Skip to content

Commit 9b08413

Browse files
committed
First test
1 parent 8a02238 commit 9b08413

File tree

4 files changed

+84
-21
lines changed

4 files changed

+84
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ node_modules
2222
npm-debug.log*
2323
yarn-debug.log*
2424
yarn-error.log*
25+
refactor/screenshot.png

refactor/playwright.config.ts

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,109 @@
1-
import { defineConfig, devices } from '@playwright/test';
1+
import type { PlaywrightTestConfig } from "@playwright/test";
2+
import { devices } from "@playwright/test";
23

3-
export default defineConfig({
4-
testDir: './tests',
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
9+
/**
10+
* See https://playwright.dev/docs/test-configuration.
11+
*/
12+
const config: PlaywrightTestConfig = {
13+
testDir: "./src/tests",
514
/* Maximum time one test can run for. */
615
timeout: 30 * 1000,
716
expect: {
817
/**
918
* Maximum time expect() should wait for the condition to be met.
1019
* For example in `await expect(locator).toHaveText();`
1120
*/
12-
timeout: 5000,
21+
timeout: 5000
1322
},
1423
/* Run tests in files in parallel */
1524
fullyParallel: true,
1625
/* Fail the build on CI if you accidentally left test.only in the source code. */
17-
forbidOnly: !!process.env.CI,
26+
forbidOnly: Boolean(process.env.CI),
1827
/* Retry on CI only */
1928
retries: process.env.CI ? 2 : 0,
2029
/* Opt out of parallel tests on CI. */
21-
workers: process.env.CI && 1,
30+
workers: process.env.CI ? 1 : undefined,
2231
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23-
reporter: 'html',
32+
reporter: "html",
2433
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2534
use: {
2635
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
2736
actionTimeout: 0,
2837
/* Base URL to use in actions like `await page.goto('/')`. */
29-
baseURL: 'http://localhost:3000',
38+
baseURL: "http://localhost:3000",
3039

3140
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32-
trace: 'on-first-retry',
41+
trace: "on-first-retry",
42+
43+
viewport: { width: 1920, height: 1080 }
3344
},
3445

3546
/* Configure projects for major browsers */
3647
projects: [
3748
{
38-
name: 'chromium',
39-
use: { ...devices['Desktop Chrome'] },
49+
name: "chromium",
50+
use: {
51+
...devices["Desktop Chrome"]
52+
}
4053
},
4154

4255
{
43-
name: 'firefox',
44-
use: { ...devices['Desktop Firefox'] },
56+
name: "firefox",
57+
use: {
58+
...devices["Desktop Firefox"]
59+
}
4560
},
4661

4762
{
48-
name: 'webkit',
49-
use: { ...devices['Desktop Safari'] },
50-
},
63+
name: "webkit",
64+
use: {
65+
...devices["Desktop Safari"]
66+
}
67+
}
68+
69+
/* Test against mobile viewports. */
70+
// {
71+
// name: 'Mobile Chrome',
72+
// use: {
73+
// ...devices['Pixel 5'],
74+
// },
75+
// },
76+
// {
77+
// name: 'Mobile Safari',
78+
// use: {
79+
// ...devices['iPhone 12'],
80+
// },
81+
// },
82+
83+
/* Test against branded browsers. */
84+
// {
85+
// name: 'Microsoft Edge',
86+
// use: {
87+
// channel: 'msedge',
88+
// },
89+
// },
90+
// {
91+
// name: 'Google Chrome',
92+
// use: {
93+
// channel: 'chrome',
94+
// },
95+
// },
5196
],
5297

5398
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
54-
outputDir: 'test-results/',
99+
outputDir: "test-results/",
55100

56101
/* Run your local dev server before starting the tests */
57102
webServer: {
58-
command: 'npm run start',
59-
port: 3000,
60-
},
61-
});
103+
reuseExistingServer: true,
104+
command: "npm run dev",
105+
port: 3000
106+
}
107+
};
108+
109+
export default config;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Forside', () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('http://localhost:3000');
6+
});
7+
8+
test('Har h1 innhold på forsiden', async ({ page }) => {
9+
await page.screenshot({ path: "screenshot.png" });
10+
const h1 = await page.locator('h1');
11+
const count = await h1.count();
12+
await expect(count).toBeGreaterThan(0);
13+
});
14+
});
File renamed without changes.

0 commit comments

Comments
 (0)