-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialSetup.js
More file actions
81 lines (67 loc) · 3.07 KB
/
initialSetup.js
File metadata and controls
81 lines (67 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {chromium, expect, webkit} from "@playwright/test";
import {testData} from "./config/mainConfig";
import {setTimeout} from "node:timers/promises";
import {SignUpPage} from "./pages/signUpPage";
import {randomInt} from "crypto";
import {waitForElementVisible} from "./helpers/waitFor";
import path from "node:path";
import {LoginPage} from "./pages/loginPage";
import {HomePage} from "./pages/homePage";
import * as fs from "node:fs/promises";
import {getLinkFromMailinatorRecentEmail} from "./mailinator/mailinator";
import {randomStringLettersOnly} from "./helpers/random";
async function initialSetup() {
if (process.env.SKIP_SETUP) {
console.log('Skipping global setup');
return;
}
const projectName = process.argv.find(arg => arg.startsWith('--project='))?.split('=')[1];
if (!projectName) {
throw new Error('Project name is required. Please run with --project=chrome or --project=safari');
}
let browser;
switch (projectName) {
case 'safari':
browser = await webkit.launch({headless: true});
break;
case 'chrome':
browser = await chromium.launch({headless: true});
break;
case 'chromium':
default:
throw new Error(`Unknown project: ${projectName}. Supported projects are: chrome and safari`);
}
const context = await browser.newContext({viewport: {width: 1900, height: 1000}});
const page = await context.newPage();
await page.goto(testData.url);
await expect(page).toHaveTitle('Harper Fabric');
await setTimeout(2000);
console.log('Signing up with new user...');
const signUpPage = new SignUpPage(page);
const emailName = randomStringLettersOnly(12) + randomInt(1000);
const email = `${emailName}@${testData.mailinator_team_name}`;
await signUpPage.signUp(testData.firstName, testData.lastName, email, testData.password);
console.log(`Signed up`);
console.log('Waiting for 15 seconds before checking the email inbox');
await setTimeout(15000);
const link = await getLinkFromMailinatorRecentEmail(testData.mailinator_api_token, testData.mailinator_team_name, emailName);
await page.goto(link);
await waitForElementVisible(page.locator('//div[text() = "Email verified successfully"]'), 12000);
await setTimeout(3000);
console.log('Email verified successfully');
await page.goto(testData.url);
const loginPage = new LoginPage(page);
await waitForElementVisible(loginPage.signInButton, 5000);
await loginPage.signIn(email, testData.password);
const homePage = new HomePage(page);
await expect(await homePage.signOut).toBeVisible({timeout: 15000});
await setTimeout(2000);
await page.context().storageState({path: path.join(__dirname, 'StageLoginSavedState.json')});
await setTimeout(2000);
console.log('Saved initial login state for stage env in StageLoginSavedState.json');
await browser.close();
await fs.writeFile(path.join(__dirname, 'User.txt'), email);
console.log('Stored in User.txt');
await setTimeout(1000);
}
export default initialSetup;