Skip to content

Commit d3243ca

Browse files
committed
Added fixtures and projects and fixed logic
1 parent c25fc63 commit d3243ca

File tree

7 files changed

+81
-48
lines changed

7 files changed

+81
-48
lines changed

packages/twenty-e2e-testing/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ run_results/
66
playwright-report/.last-run.json
77
results/
88
run_results/.playwright-artifacts-0/
9-
run_results/.playwright-artifacts-1/
9+
run_results/.playwright-artifacts-1/
10+
.auth/

packages/twenty-e2e-testing/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ yarn run test:e2e <filename>
3535
```
3636
yarn run test:e2e:debug
3737
```
38+
39+
## Q&A
40+
41+
#### Why there's `path.resolve()` everywhere?
42+
That's thanks to differences in root directory when running tests using commands and using IDE. When running tests with commands,
43+
the root directory is `twenty/packages/twenty-e2e-testing`, for IDE it depends on how someone sets the configuration. This way, it
44+
ensures that no matter which IDE or OS Shell is used, the result will be the same.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { test as base } from '@playwright/test';
2+
import path from 'path';
3+
4+
const date = new Date();
5+
6+
export const test = base.extend<{ screenshotHook: void }>({
7+
screenshotHook: [
8+
async ({ page, browserName }, use, workerInfo) => {
9+
// here everything is the same as beforeEach()
10+
// goto is to go to website as login setup saves the cookies of logged-in user, not the state of browser
11+
await page.goto('/');
12+
await use(); // here is the code of test
13+
// here everything is the same as afterEach()
14+
// automatic fixture of making screenshot after each test
15+
await page.screenshot({
16+
path: path.resolve(
17+
__dirname,
18+
'..',
19+
'..',
20+
'results',
21+
'screenshots',
22+
`${workerInfo.project.name}`,
23+
browserName,
24+
`${date.toISOString()}.png`,
25+
),
26+
});
27+
},
28+
{ auto: true }, // automatic fixture runs with every test
29+
],
30+
});
31+
32+
export { expect } from '@playwright/test';

packages/twenty-e2e-testing/playwright.config.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfig, devices } from '@playwright/test';
22
import { config } from 'dotenv';
3+
import path from 'path';
34

45
config();
56

@@ -15,7 +16,7 @@ export default defineConfig({
1516
fullyParallel: true, // false only for specific tests, overwritten in specific projects or global setups of projects
1617
forbidOnly: !!process.env.CI,
1718
retries: process.env.CI ? 2 : 0,
18-
workers: process.env.CI ? 1 : undefined, // undefined = amount of projects
19+
workers: process.env.CI ? 1 : undefined, // undefined = amount of projects * amount of tests
1920
timeout: 30 * 1000, // timeout can be changed
2021
use: {
2122
baseURL: process.env.CI
@@ -35,13 +36,25 @@ export default defineConfig({
3536
},
3637
reporter: [['html', { open: 'never' }]],
3738
projects: [
39+
{
40+
name: 'Login setup',
41+
testMatch: /login\.setup\.ts/, // finds all tests matching this regex, in this case only 1 test should be found
42+
},
3843
{
3944
name: 'chromium',
40-
use: { ...devices['Desktop Chrome'] },
45+
use: {
46+
...devices['Desktop Chrome'],
47+
storageState: path.resolve(__dirname, '.auth', 'user.json'), // takes saved cookies from directory
48+
},
49+
dependencies: ['Login setup'], // forces to run login setup before running tests from this project - CASE SENSITIVE
4150
},
4251
{
4352
name: 'firefox',
44-
use: { ...devices['Desktop Firefox'] },
53+
use: {
54+
...devices['Desktop Firefox'],
55+
storageState: path.resolve(__dirname, '.auth', 'user.json'),
56+
},
57+
dependencies: ['Login setup'],
4558
},
4659

4760
//{
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
1-
import { test, expect } from '@playwright/test';
1+
import { test, expect } from '../lib/fixtures/screenshot';
22
import { config } from 'dotenv';
33
import path = require('path');
44
config({ path: path.resolve(__dirname, '..', '.env') });
55

6-
const date = new Date();
7-
8-
test.beforeEach(async ({ page }) => {
9-
await page.goto('/');
10-
await page.getByRole('button', { name: 'Continue With Email' }).click();
11-
await page.getByPlaceholder('Email').fill(process.env.DEFAULT_LOGIN);
12-
await page.getByRole('button', { name: 'Continue', exact: true }).click();
13-
await page.getByPlaceholder('Password').fill(process.env.DEFAULT_PASSWORD);
14-
await page.getByRole('button', { name: 'Sign in' }).click();
15-
await expect(page.getByText('Welcome to Twenty')).not.toBeVisible();
16-
});
17-
18-
test.afterEach(async ({ page, browserName }, workerInfo) => {
19-
await page.screenshot({
20-
path: path.resolve(
21-
__dirname,
22-
'..',
23-
'results',
24-
'screenshots',
25-
browserName,
26-
`${workerInfo.project.name}`,
27-
`${date.toISOString()}.png`,
28-
),
29-
});
30-
});
31-
326
test.describe('Basic check', () => {
337
test('Checking if table in Companies is visible', async ({ page }) => {
348
await expect(page.getByTestId('tooltip').nth(0)).toHaveText('Companies');
@@ -37,4 +11,9 @@ test.describe('Basic check', () => {
3711
await expect(page.locator('table')).toBeVisible();
3812
await expect(page.locator('tbody > tr')).toHaveCount(13); // shouldn't be hardcoded in case of tests on demo
3913
});
14+
15+
test('', async ({ page }) => {
16+
await page.getByRole('link', { name: 'Opportunities' }).click();
17+
await expect(page.locator('table')).toBeVisible();
18+
});
4019
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test as setup, expect } from '@playwright/test';
2+
import path from 'path';
3+
4+
setup('Login test', async ({ page }) => {
5+
await page.goto('/');
6+
await page.getByRole('button', { name: 'Continue With Email' }).click();
7+
await page.getByPlaceholder('Email').fill(process.env.DEFAULT_LOGIN);
8+
await page.getByRole('button', { name: 'Continue', exact: true }).click();
9+
await page.getByPlaceholder('Password').fill(process.env.DEFAULT_PASSWORD);
10+
await page.getByRole('button', { name: 'Sign in' }).click();
11+
await expect(page.getByText('Welcome to Twenty')).not.toBeVisible();
12+
13+
// End of authentication steps.
14+
15+
await page.context().storageState({
16+
path: path.resolve(__dirname, '..', '.auth', 'user.json'),
17+
});
18+
});

packages/twenty-e2e-testing/tests/workspaces.spec.ts

-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
import { test, expect } from '@playwright/test';
22
import { sh } from '../drivers/shell_driver';
3-
import path from 'path';
4-
5-
const date = new Date();
6-
7-
test.afterEach(async ({ page, browserName }, workerInfo) => {
8-
await page.screenshot({
9-
path: path.resolve(
10-
__dirname,
11-
'..',
12-
'results',
13-
'screenshots',
14-
browserName,
15-
`${workerInfo.project.name}`,
16-
`${date.toISOString()}.png`,
17-
),
18-
});
19-
});
203

214
test.describe('', () => {
225
test('Testing logging', async ({ page }) => {

0 commit comments

Comments
 (0)