Skip to content

Commit 5a66c7d

Browse files
committed
update readme
1 parent 921387c commit 5a66c7d

File tree

4 files changed

+63
-37
lines changed

4 files changed

+63
-37
lines changed

.env.sample

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MAILSLURP_API_KEY=
2+
TEST_EMAIL=
3+
TEST_PASSWORD=

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# UI Integration Testing
2+
3+
## Repository Structure
4+
5+
- **/tests**: Contains all test cases and scenarios.
6+
- **/perf-results**: Stores performance test results.
7+
8+
## Getting Started
9+
10+
To set up and run the tests locally:
11+
12+
1. **Clone the Repository**:
13+
```bash
14+
git clone https://github.com/adsabs/ui-integration-testing.git
15+
cd ui-integration-testing
16+
17+
# Install dependencies
18+
pnpm install
19+
```
20+
21+
2. **Run the Tests**:
22+
```bash
23+
# Run all tests
24+
pnpm test
25+
26+
# Run tests in watch mode
27+
pnpm test:watch
28+
```
29+
30+
In order to do the account creation tests, you'll need to create a mailslurp API key and set it in the `MAILSLURP_API_KEY` environment variable.
31+
https://docs.mailslurp.com/api/
32+
33+
For the other account login tests make sure you have a good test account created in the environment and add the `TEST_EMAIL` and `TEST_PASSWORD` environment variables.
34+
35+
The tests watch for these variables and will be skipped if they are not set.
36+

tests/ui.adsabs.harvard.edu/smoke/account.spec.ts

+6-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '@playwright/test';
2-
import {getInbox, getTestEmailAccount, waitForLatestEmail} from '../../../util/email';
2+
import {ms, getInbox, getTestEmailAccount, waitForLatestEmail, getRandomPassword} from '../../../util/email';
33
import {configDotenv} from 'dotenv';
44
import { Email } from 'mailslurp-client';
55

@@ -9,7 +9,6 @@ test.use({
99
baseURL: 'https://qa.adsabs.harvard.edu'
1010
});
1111

12-
1312
function extractRegisterToken(email: Email): string | null {
1413
const html = email.body;
1514
if (typeof html === 'string') {
@@ -21,10 +20,10 @@ function extractRegisterToken(email: Email): string | null {
2120
throw new Error(`${html} is not a string`)
2221
}
2322

24-
const password = 'XZHFjvCpDWrF8sAb1d0Npg50nH1xg'
25-
2623
test('Can register an account', async ({ page }) => {
24+
test.skip(!ms, 'MailSlurp API key not set');
2725
const {id, emailAddress} = await getInbox();
26+
const password = await getRandomPassword(page);
2827
await page.goto("/user/account/register");
2928

3029
// fill out form
@@ -65,6 +64,9 @@ test('Can register an account', async ({ page }) => {
6564

6665
test('Can login and get to all settings pages', async ({ page }) => {
6766
const { emailAddress, password } = getTestEmailAccount();
67+
test.skip(!emailAddress, 'TEST_EMAIL not set');
68+
test.skip(!password, 'TEST_PASSWORD not set');
69+
6870
await page.goto("/user/account/login");
6971

7072
// fill out form
@@ -115,25 +117,3 @@ test('Can login and get to all settings pages', async ({ page }) => {
115117
await page.goto('/user/libraries');
116118
await expect(page.locator('span.h2')).toHaveText('My Libraries');
117119
});
118-
119-
120-
121-
122-
123-
124-
// test("register and delete account", async ({ page }) =>{
125-
//
126-
//
127-
// // go to account page
128-
// await page.goto('/user/settings/delete');
129-
// page.on('dialog', async dialog => {
130-
// await dialog.accept();
131-
// });
132-
// await page.locator('#delete-account').click();
133-
// await page.waitForURL('/user/account/login');
134-
// await expect(page).toHaveURL('/user/account/login');
135-
// });
136-
137-
138-
139-

util/email.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { InboxDto, MailSlurp } from 'mailslurp-client';
2-
import { configDotenv } from 'dotenv';
1+
import {InboxDto, MailSlurp} from 'mailslurp-client';
2+
import {configDotenv} from 'dotenv';
3+
import {Page} from '@playwright/test';
34

45
configDotenv();
5-
const ms = new MailSlurp({
6-
apiKey: process.env.MAILSLURP_API_KEY,
7-
});
86

97
export const getMailSlurp = () => {
108
if (!process.env.MAILSLURP_API_KEY) {
11-
throw new Error('Environment variable MAILSLURP_API_KEY must be defined');
9+
return;
1210
}
13-
return ms;
11+
return new MailSlurp({
12+
apiKey: process.env.MAILSLURP_API_KEY,
13+
});
1414
}
1515

16+
export const ms = getMailSlurp();
17+
1618
export const getInbox = async () => {
1719
try {
1820
let inbox: InboxDto;
@@ -40,12 +42,17 @@ export const getTestEmailAccount = () => {
4042
const emailAddress = process.env.TEST_EMAIL;
4143
const password = process.env.TEST_PASSWORD;
4244

43-
if (!emailAddress || !password) {
44-
throw new Error('Environment variables TEST_EMAIL and TEST_PASSWORD must be defined');
45-
}
46-
4745
return {
4846
emailAddress,
4947
password
5048
}
5149
}
50+
51+
export const getRandomPassword = async (page: Page, len=16) => {
52+
return await page.evaluate(() => {
53+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
54+
const ranVals = new Uint8Array(len);
55+
crypto.getRandomValues(ranVals);
56+
return Array.from(ranVals, byte => chars[byte % chars.length]).join('');
57+
});
58+
}

0 commit comments

Comments
 (0)