Skip to content

Commit

Permalink
[Playwright] Add integration tests (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Logan Graham <[email protected]>
  • Loading branch information
omacranger and Logan Graham authored Sep 13, 2024
1 parent 97f7954 commit 3a25e36
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 2 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/playwright-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: playwright (integration test)

on:
push:
branches:
- main
paths:
- 'visual-js/visual-playwright/**'
- .github/workflows/js-build.yml
- .github/workflows/playwright-integration.yml
pull_request:
paths:
- 'visual-js/visual-playwright/**'
- .github/workflows/js-build.yml
- .github/workflows/playwright-integration.yml

defaults:
run:
working-directory: visual-js/visual-playwright

jobs:
integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push to local registry
uses: docker/build-push-action@v5
with:
context: '{{defaultContext}}:visual-js'
tags: saucelabs/visual-playwright
file: visual-playwright/Dockerfile
load: true
- name: Run the integration tests
run: |
npm ci
npm run test
working-directory: tests
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
CONTAINER_IMAGE_NAME: saucelabs/visual-playwright
15 changes: 15 additions & 0 deletions visual-js/visual-playwright/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:18 AS runner

WORKDIR app

RUN corepack enable

COPY . ./

RUN yarn install && npm run build --workspaces --if-present

WORKDIR ./visual-playwright/integration-tests

RUN npm install && npx playwright install --with-deps chromium

ENTRYPOINT ["npm", "run", "sauce-visual"]
5 changes: 5 additions & 0 deletions visual-js/visual-playwright/integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
12 changes: 12 additions & 0 deletions visual-js/visual-playwright/integration-tests/custom-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test as base } from "@playwright/test";
import { sauceVisualFixtures, SauceVisualFixtures } from "@saucelabs/visual-playwright";

export const test = base.extend<SauceVisualFixtures>({
// Set up the Sauce Visual fixture, and optionally customize the global options which are sent
// with each sauce visual check to reduce duplication.
...sauceVisualFixtures({
captureDom: true,
}),
});

export { expect } from "@playwright/test";
7 changes: 7 additions & 0 deletions visual-js/visual-playwright/integration-tests/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { FullConfig } from '@playwright/test';
import { sauceVisualSetup } from "@saucelabs/visual-playwright";


export default async function globalSetup(config: FullConfig){
await sauceVisualSetup();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { FullConfig } from '@playwright/test';
import { sauceVisualTeardown } from "@saucelabs/visual-playwright";


export default async function globalTeardown(config: FullConfig) {
await sauceVisualTeardown();
}
140 changes: 140 additions & 0 deletions visual-js/visual-playwright/integration-tests/package-lock.json

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

17 changes: 17 additions & 0 deletions visual-js/visual-playwright/integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "playwright-js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"sauce-visual": "playwright test",
"sauce-visual-check": "VISUAL_CHECK=1 playwright test"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "1.47.0",
"@types/node": "22.5.4"
}
}
81 changes: 81 additions & 0 deletions visual-js/visual-playwright/integration-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* 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 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'https://www.saucedemo.com',
testIdAttribute: 'data-test',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

globalSetup: require.resolve('./global-setup'),
globalTeardown: require.resolve('./global-teardown'),

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
//
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

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

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

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test, expect } from '../custom-test';

test.beforeEach(async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/Swag Labs/);
await page.waitForLoadState('networkidle');
})

test('loads the login page', async ({ page, sauceVisual }) => {
await sauceVisual.visualCheck("Before Login");
});
4 changes: 2 additions & 2 deletions visual-js/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3577,7 +3577,7 @@ __metadata:
languageName: unknown
linkType: soft

"@saucelabs/visual-playwright@^0.1.1, @saucelabs/visual-playwright@workspace:visual-playwright":
"@saucelabs/visual-playwright@^0.1.2, @saucelabs/visual-playwright@workspace:visual-playwright":
version: 0.0.0-use.local
resolution: "@saucelabs/visual-playwright@workspace:visual-playwright"
dependencies:
Expand Down Expand Up @@ -3613,7 +3613,7 @@ __metadata:
dependencies:
"@jest/globals": ^28.0.0 || ^29.0.0
"@saucelabs/visual": ^0.8.2
"@saucelabs/visual-playwright": ^0.1.1
"@saucelabs/visual-playwright": ^0.1.2
"@storybook/test-runner": ">=0.13.0"
"@storybook/types": ^8.0.2
"@tsconfig/node18": ^2.0.0
Expand Down

0 comments on commit 3a25e36

Please sign in to comment.