Skip to content

Commit bb890d6

Browse files
author
Guru
committed
feat: playwright test cases
1 parent f30330a commit bb890d6

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import { test, expect } from '@playwright/test';
2+
import axios from 'axios';
3+
import { delay, generateEmailWithTag } from '../testUtils';
4+
5+
import dotenv from 'dotenv';
6+
// Load environment variables from .env file
7+
dotenv.config();
8+
const testEmailAppApiKey = process.env.TEST_EMAIL_APP_API_KEY;
9+
10+
test('login with email password less and enable MFA using password', async ({ page }) => {
11+
const testEmail = generateEmailWithTag() || "";
12+
const fixedEmail = "[email protected]";
13+
const tag = fixedEmail.split("@")[0].split(".")[1];
14+
const timestamp= Math.floor(Date.now() / 1000);
15+
console.log({testEmailAppApiKey});
16+
await page.goto('http://localhost:5173/');
17+
await page.getByRole('textbox', { name: 'E.g. [email protected]' }).click();
18+
await page.getByRole('textbox', { name: 'E.g. [email protected]' }).fill(fixedEmail);
19+
await page.getByRole('button', { name: 'Continue with Email' }).click();
20+
21+
const page1Promise = page.waitForEvent('popup');
22+
const page1 = await page1Promise;
23+
24+
await delay(4000);
25+
const ENDPOINT = `https://api.testmail.app/api/json?apikey=${testEmailAppApiKey}&namespace=kelg8&tag=${tag}&livequery=true&timestamp_from=${timestamp}`;
26+
console.log({ENDPOINT});
27+
const res = await axios.get(`${ENDPOINT}`);
28+
const inbox = await res.data;
29+
// const verificationCodeMatch = inbox.emails[0].html.match(/<span[^>]*font-weight: 600[^>]*>(\d+)<\/span>/);
30+
const verificationCode = inbox.emails[0].html.match(/<span[^>]*style\s*=\s*["'][^"']*font-size\s*:\s*40px[^"']*["'][^>]*>\s*(\d+)\s*<\/span>/i)[1];
31+
console.log({verificationCode});
32+
33+
await page1.locator('.w-12').first().click();
34+
for (let i = 0; i < verificationCode.length; i++) {
35+
await page1.locator(`input:nth-child(${i + 1})`).fill(verificationCode[i]);
36+
}
37+
38+
await page.getByRole('button', { name: 'Sign Message' }).click();
39+
await expect(page.getByText('Message has been signed')).toBeVisible();
40+
41+
await page.getByRole('button', { name: 'Close', exact: true }).click();
42+
await page.getByRole('button', { name: 'Send Transaction' }).click();
43+
44+
});
45+
46+
test('MFA login with password and email-passwordless and sign message', async ({ page }) => {
47+
const fixedEmail = "[email protected]";
48+
const tag = fixedEmail.split("@")[0].split(".")[1];
49+
const timestamp= Math.floor(Date.now() / 1000);
50+
51+
await page.goto('http://localhost:5173/');
52+
await page.getByRole('textbox', { name: 'E.g. [email protected]' }).click();
53+
await page.getByRole('textbox', { name: 'E.g. [email protected]' }).fill(fixedEmail);
54+
await page.getByRole('button', { name: 'Continue with Email' }).click();
55+
56+
const page1Promise = page.waitForEvent('popup');
57+
const page1 = await page1Promise;
58+
59+
// wait for mailbox to receive email
60+
await delay(4000);
61+
const ENDPOINT = `https://api.testmail.app/api/json?apikey=${testEmailAppApiKey}&namespace=kelg8&tag=${tag}&livequery=true&timestamp_from=${timestamp}`;
62+
console.log({ENDPOINT});
63+
const res = await axios.get(`${ENDPOINT}`);
64+
const inbox = await res.data;
65+
const verificationCode = inbox.emails[0].html.match(/<span[^>]*style\s*=\s*["'][^"']*font-size\s*:\s*40px[^"']*["'][^>]*>\s*(\d+)\s*<\/span>/i)[1];
66+
67+
// fill the code received in the email
68+
await page1.locator('.w-12').first().click();
69+
for (let i = 0; i < verificationCode.length; i++) {
70+
await page1.locator(`input:nth-child(${i + 1})`).fill(verificationCode[i]);
71+
}
72+
73+
await page.waitForTimeout(2000);
74+
await page.getByRole('button', { name: 'Password' }).click();
75+
await page.getByRole('textbox', { name: 'Confirm password' }).click();
76+
await page.getByRole('textbox', { name: 'Confirm password' }).fill('Test@1234');
77+
await page.getByRole('button', { name: 'Confirm' }).click();
78+
79+
await page.getByRole('button', { name: 'Sign Message' }).click();
80+
await expect(page.getByText('Message has been signed')).toBeVisible();
81+
await page.getByRole('button', { name: 'Close', exact: true }).click();
82+
await page.waitForTimeout(4000);
83+
84+
await page.getByRole('button', { name: 'Criticial Reset' }).click();
85+
});
86+
87+
test('login with email password-less,enable recovery phrase logout and recover using phrase and sign message', async ({ browser }) => {
88+
test.setTimeout(120000);
89+
const context = await browser.newContext({
90+
permissions: ['clipboard-read', 'clipboard-write']
91+
});
92+
const page = await context.newPage();
93+
94+
const testEmail = generateEmailWithTag() || "";
95+
const fixedEmail = "[email protected]";
96+
const tag = fixedEmail.split("@")[0].split(".")[1];
97+
const timestamp= Math.floor(Date.now() / 1000);
98+
99+
await page.goto('http://localhost:5173/');
100+
await page.getByRole('textbox', { name: 'E.g. [email protected]' }).click();
101+
await page.getByRole('textbox', { name: 'E.g. [email protected]' }).fill(fixedEmail);
102+
await page.getByRole('button', { name: 'Continue with Email' }).click();
103+
104+
const page1Promise = page.waitForEvent('popup');
105+
const page1 = await page1Promise;
106+
107+
await delay(4000);
108+
const ENDPOINT = `https://api.testmail.app/api/json?apikey=${testEmailAppApiKey}&namespace=kelg8&tag=${tag}&livequery=true&timestamp_from=${timestamp}`;
109+
console.log({ENDPOINT});
110+
const res = await axios.get(`${ENDPOINT}`);
111+
const inbox = await res.data;
112+
// const verificationCodeMatch = inbox.emails[0].html.match(/<span[^>]*font-weight: 600[^>]*>(\d+)<\/span>/);
113+
const verificationCode = inbox.emails[0].html.match(/<span[^>]*style\s*=\s*["'][^"']*font-size\s*:\s*40px[^"']*["'][^>]*>\s*(\d+)\s*<\/span>/i)[1];
114+
console.log({verificationCode});
115+
116+
await page1.locator('.w-12').first().click();
117+
for (let i = 0; i < verificationCode.length; i++) {
118+
await page1.locator(`input:nth-child(${i + 1})`).fill(verificationCode[i]);
119+
}
120+
121+
await page.getByRole('button', { name: 'Sign Message' }).click();
122+
await expect(page.getByText('Message has been signed')).toBeVisible();
123+
await page.getByRole('button', { name: 'Close', exact: true }).click();
124+
await page.getByRole('button', { name: 'Add Recovery Phrase' }).click();
125+
await page.getByRole('textbox', { name: 'Enter seed phrase' }).click();
126+
await page.getByRole('textbox', { name: 'Enter seed phrase' }).press('ControlOrMeta+a');
127+
await page.getByRole('textbox', { name: 'Enter seed phrase' }).press('ControlOrMeta+c');
128+
await page.getByRole('textbox', { name: 'Enter seed phrase' }).press('ControlOrMeta+c');
129+
const copiedResult = await page.evaluate(() => navigator.clipboard.readText());
130+
await page.getByRole('button', { name: 'Proceed' }).click();
131+
await page.waitForTimeout(6000);
132+
await page.getByRole('button', { name: 'Close', exact: true }).click();
133+
await page.getByRole('button', { name: 'Logout' }).click();
134+
await page.waitForTimeout(3000);
135+
136+
await page.getByRole('textbox', { name: 'E.g. [email protected]' }).click();
137+
await page.getByRole('textbox', { name: 'E.g. [email protected]' }).fill(fixedEmail);
138+
await page.getByRole('button', { name: 'Continue with Email' }).click();
139+
const page2Promise = page.waitForEvent('popup');
140+
const page2 = await page2Promise;
141+
await delay(4000);
142+
console.log({ENDPOINT});
143+
const res2 = await axios.get(`${ENDPOINT}`);
144+
const inbox2 = await res2.data;
145+
// const verificationCodeMatch = inbox.emails[0].html.match(/<span[^>]*font-weight: 600[^>]*>(\d+)<\/span>/);
146+
const verificationCode2 = inbox2.emails[0].html.match(/<span[^>]*style\s*=\s*["'][^"']*font-size\s*:\s*40px[^"']*["'][^>]*>\s*(\d+)\s*<\/span>/i)[1];
147+
console.log({ verificationCode2 });
148+
149+
await page2.locator('.w-12').first().click();
150+
for (let i = 0; i < verificationCode2.length; i++) {
151+
await page2.locator(`input:nth-child(${i + 1})`).fill(verificationCode2[i]);
152+
}
153+
154+
await page.getByRole('button', { name: 'Recovery Phrase' }).click();
155+
await page.getByRole('textbox', { name: 'Enter seed phrase' }).click();
156+
await page.getByRole('textbox', { name: 'Enter seed phrase' }).fill(copiedResult);
157+
await page.getByRole('button', { name: 'Proceed' }).click();
158+
159+
160+
await page.getByRole('button', { name: 'Sign Message' }).click();
161+
await expect(page.getByText('Message has been signed')).toBeVisible();
162+
await page.getByRole('button', { name: 'Close', exact: true }).click();
163+
await page.waitForTimeout(4000);
164+
165+
await page.getByRole('button', { name: 'Criticial Reset' }).click();
166+
});

0 commit comments

Comments
 (0)