Skip to content

Commit

Permalink
setup playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
thal0x committed Sep 21, 2023
1 parent baf8027 commit 1b302a6
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
/test-results/
/playwright-report/
/playwright/.cache/
71 changes: 71 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "jest"
"test": "jest",
"test:e2e": "playwright test --project=chromium"
},
"dependencies": {
"@cosmjs/amino": "^0.31.0",
Expand Down Expand Up @@ -64,6 +65,7 @@
"usehooks-ts": "^2.9.1"
},
"devDependencies": {
"@playwright/test": "^1.38.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
Expand Down
20 changes: 20 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig, devices } from "@playwright/test";

export default defineConfig({
testDir: "./tests",
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: "html",
use: {
trace: "on-first-retry",
headless: false,
},
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
],
});
20 changes: 20 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, test } from "./lib/fixtures";

test("has title", async ({ page }) => {
await page.goto("https://playwright.dev/");

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
});

test("get started link", async ({ page }) => {
await page.goto("https://playwright.dev/");

// Click the get started link.
await page.getByRole("link", { name: "Get started" }).click();

// Expects page to have a heading with the name of Installation.
await expect(
page.getByRole("heading", { name: "Installation" }),
).toBeVisible();
});
38 changes: 38 additions & 0 deletions tests/lib/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { type BrowserContext, chromium, test as base } from "@playwright/test";

import { prepareKeplr } from "./keplr";

export const test = base.extend<{ context: BrowserContext }>({
// eslint-disable-next-line no-empty-pattern
context: async ({}, use) => {
// download keplr
await prepareKeplr();

// prepare browser args
const browserArgs = [
// `--disable-extensions-except=${metamaskPath}`,
// `--load-extension=${metamaskPath}`,
"--remote-debugging-port=9222",
];

if (process.env.CI) {
browserArgs.push("--disable-gpu");
}

if (process.env.HEADLESS_MODE) {
browserArgs.push("--headless=new");
}

// launch browser
const context = await chromium.launchPersistentContext("", {
headless: false,
args: browserArgs,
});

await use(context);

await context.close();
},
});

export const expect = test.expect;
14 changes: 14 additions & 0 deletions tests/lib/keplr/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from "axios";

export async function prepareKeplr() {
const response = await axios.get(
"https://api.github.com/repos/chainapsis/keplr-wallet/releases",
);

const filename = response.data[0].assets[0].name;
const downloadUrl = response.data[0].assets[0].browser_download_url;
const tagName = response.data[0].tag_name;
console.log(
`Keplr version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`,
);
}

0 comments on commit 1b302a6

Please sign in to comment.