Skip to content

Commit

Permalink
Merge pull request #45 from CactusPuppy/pipeline-update
Browse files Browse the repository at this point in the history
test(Playwright): fix Playwright test
  • Loading branch information
CactusPuppy authored Apr 16, 2024
2 parents 0fe234b + d5d0b50 commit 4fbf86d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
- uses: actions/setup-node@v2
with:
node-version: '14.x'
node-version: '18.x'
cache: 'yarn'
- name: Install dependencies
run: yarn
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ yarn-error.log*
.vercel
test-results/
playwright-report/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
],
"devDependencies": {
"@next/eslint-plugin-next": "^12.0.4",
"@playwright/test": "^1.28.0",
"@playwright/test": "^1.43.1",
"@types/node": "^20.12.7",
"eslint": "^7.0",
"eslint-config-next": "^12.0.4",
"typescript": "^4.5.4",
Expand Down
91 changes: 26 additions & 65 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,116 +1,77 @@
import { PlaywrightTestConfig } from "@playwright/test";
const { devices } = require("@playwright/test");
import { defineConfig, devices } from "@playwright/test";

/**
* @see https://playwright.dev/docs/test-configuration
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
const config: PlaywrightTestConfig = {
/* Run a setup script before Playwright */
globalSetup: "./tests/support/global-setup.ts",
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./tests",

/* Maximum time one test can run for. */
timeout: 30 * 1000,

expect: {

/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
},

/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,

/* Retry on CI only */
retries: process.env.CI ? 2 : 0,

/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : 5,

workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? "dot" : [["html", { open: "never" }]],

reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {

/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,

/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:3000',
baseURL: "http://127.0.0.1:3000",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",

/* Take a screenshot on every failure */
screenshot: "only-on-failure",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",

/* Project-specific settings. */
use: {
...devices["Desktop Chrome"],
},
use: { ...devices["Desktop Chrome"] },
},

{
name: "firefox",
use: {
...devices["Desktop Firefox"],
},
use: { ...devices["Desktop Firefox"] },
},

{
name: "webkit",
use: {
...devices["Desktop Safari"],
},
use: { ...devices["Desktop Safari"] },
},

/* Test against mobile viewports. */
{
name: "Mobile Chrome",
use: {
...devices["Pixel 5"],
},
use: { ...devices["Pixel 5"] },
},
{
name: "Mobile Safari",
use: {
...devices["iPhone 12"],
},
use: { ...devices["iPhone 12"] },
},

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: {
// channel: 'msedge',
// },
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
outputDir: "test-results/",

/* Run your local dev server before starting the tests */
// webServer: {
// command: "npm run start",
// port: 3000,
// },
};
module.exports = config;
webServer: {
command: process.env.CI ? "yarn dev -p 3000" : "vercel dev --listen 3000",
url: "http://127.0.0.1:3000",
reuseExistingServer: !process.env.CI,
},
});
11 changes: 5 additions & 6 deletions tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import test from "./support/next-fixture";
import { expect } from "@playwright/test";
import { test, expect } from "@playwright/test";

test("main page title", async ({ page, port }) => {
await page.goto(`http://localhost:${port}/`);
test("main page title", async ({ page }) => {
await page.goto("/");

const name = await page.locator("h1").allInnerTexts();
expect(name).toContain("Anwita Biosciences");
});

test("can find the current mission statement", async ({ page, port }) => {
await page.goto(`http://localhost:${port}`);
test("can find the current mission statement", async ({ page }) => {
await page.goto("/");

const aboutSection = await page.innerText("div:has(span#about)");
expect(aboutSection.includes("Our mission is to deliver transformative treatment")).toBeTruthy();
Expand Down
22 changes: 7 additions & 15 deletions tests/pipeline.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import test from "./support/next-fixture";
import { expect } from "@playwright/test";
import { test, expect } from "@playwright/test";

test("can see all available pipelines", async ({ page, port }) => {
await page.goto(`http://localhost:${port}/`);
test("can see all available pipelines", async ({ page }) => {
await page.goto("/");

const pipelineText = (await page.locator("div[data-role~='pipeline-display']").innerText())
.replace(/[^\P{C}\n]/gu, "")
.split("\n")
.filter((s) => s.trim().length > 0)
.map((s) => s.trim());
const programs = [
"Exenokine-21 (JS014)",
"Exenokine-2 (RT003)",
Expand All @@ -17,19 +11,17 @@ test("can see all available pipelines", async ({ page, port }) => {
"Antibody Drug Conjugates",
"Discovery Programs",
];
programs.forEach((program) => {
expect(pipelineText).toContain(program);
});
await expect(page.locator("div[data-role~='pipeline-display'] summary")).toContainText([new RegExp(`/${programs.join("|")}/`)]);
});

test("can click a pipeline to reveal its description", async ({ page, port }) => {
await page.goto(`http://localhost:${port}/`);
test("can click a pipeline to reveal its description", async ({ page }) => {
await page.goto("/");

const pipeline = page.locator("div[data-role~='pipeline-display']");
const button = pipeline.locator("text='Discovery Programs'");
// Stupid hack needed to make the test work on both touch and non-touch browsers
await button.click();
const pipelineText = (await page.locator("div[data-role~='pipeline-display'] details[open] div:not([aria-hidden])").innerText())
.replace(/[^\P{C}\n]/gu, "");
expect(pipelineText.includes("Anwita applies our AccuKine cytokine")).toBeTruthy();
expect(pipelineText).toContain("Anwita applies our AccuKine cytokine");
});
11 changes: 0 additions & 11 deletions tests/support/global-setup.ts

This file was deleted.

48 changes: 0 additions & 48 deletions tests/support/next-fixture.ts

This file was deleted.

42 changes: 31 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,12 @@
"@nodelib/fs.scandir" "2.1.4"
fastq "^1.6.0"

"@playwright/test@^1.28.0":
version "1.28.0"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.28.0.tgz#8de83f9d2291bba3f37883e33431b325661720d9"
integrity sha512-vrHs5DFTPwYox5SGKq/7TDn/S4q6RA1zArd7uhO6EyP9hj3XgZBBM12ktMbnDQNxh/fL1IUKsTNLxihmsU38lQ==
"@playwright/test@^1.43.1":
version "1.43.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.43.1.tgz#16728a59eb8ce0f60472f98d8886d6cab0fa3e42"
integrity sha512-HgtQzFgNEEo4TE22K/X7sYTYNqEMMTZmFS8kTq6m8hXj+m1D8TgwgIbumHddJa9h4yl4GkKb8/bgAl2+g7eDgA==
dependencies:
"@types/node" "*"
playwright-core "1.28.0"
playwright "1.43.1"

"@rushstack/eslint-patch@^1.0.6":
version "1.1.0"
Expand Down Expand Up @@ -235,6 +234,13 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.36.tgz#c414052cb9d43fab67d679d5f3c641be911f5835"
integrity sha512-FXKWbsJ6a1hIrRxv+FoukuHnGTgEzKYGi7kilfMae96AL9UNkPFNWJEEYWzdRI9ooIkbr4AKldyuSTLql06vLQ==

"@types/node@^20.12.7":
version "20.12.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.12.7.tgz#04080362fa3dd6c5822061aa3124f5c152cff384"
integrity sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==
dependencies:
undici-types "~5.26.4"

"@types/parse-json@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
Expand Down Expand Up @@ -1357,7 +1363,7 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=

fsevents@~2.3.2:
fsevents@2.3.2, fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
Expand Down Expand Up @@ -2552,10 +2558,19 @@ pkg-dir@^2.0.0:
dependencies:
find-up "^2.1.0"

playwright-core@1.28.0:
version "1.28.0"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.28.0.tgz#61df5c714f45139cca07095eccb4891e520e06f2"
integrity sha512-nJLknd28kPBiCNTbqpu6Wmkrh63OEqJSFw9xOfL9qxfNwody7h6/L3O2dZoWQ6Oxcm0VOHjWmGiCUGkc0X3VZA==
playwright-core@1.43.1:
version "1.43.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.43.1.tgz#0eafef9994c69c02a1a3825a4343e56c99c03b02"
integrity sha512-EI36Mto2Vrx6VF7rm708qSnesVQKbxEWvPrfA1IPY6HgczBplDx7ENtx+K2n4kJ41sLLkuGfmb0ZLSSXlDhqPg==

playwright@1.43.1:
version "1.43.1"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.43.1.tgz#8ad08984ac66c9ef3d0db035be54dd7ec9f1c7d9"
integrity sha512-V7SoH0ai2kNt1Md9E3Gwas5B9m8KR2GVvwZnAI6Pg0m3sh7UvgiYhRrhsziCmqMJNouPckiOhk8T+9bSAK0VIA==
dependencies:
playwright-core "1.43.1"
optionalDependencies:
fsevents "2.3.2"

postcss-js@^3.0.3:
version "3.0.3"
Expand Down Expand Up @@ -3250,6 +3265,11 @@ unbox-primitive@^1.0.1:
has-symbols "^1.0.2"
which-boxed-primitive "^1.0.2"

undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

unified@^10.0.0:
version "10.1.1"
resolved "https://registry.yarnpkg.com/unified/-/unified-10.1.1.tgz#345e349e3ab353ab612878338eb9d57b4dea1d46"
Expand Down

0 comments on commit 4fbf86d

Please sign in to comment.