Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Visual testing #13

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ yarn.lock
allure-results
allure-report
myAllureReport

# For Chapter 11
*storybook.log
apps/
**/__snapshots__/**/*.png
**/.tmp/
324 changes: 315 additions & 9 deletions chapter_11.md

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions solutions/chapter_11/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
{
"name": "chapter11",
"version": "1.0.0",
"description": "Chapter 11 of the WebdriverIO workshop: Visual Regression Testing",
"main": "index.js",
"keywords": [],
"author": "Christian Bromann <[email protected]>",
"license": "MIT",
"name": "visual-demo",
"type": "module",
"scripts": {
"test": "wdio wdio.local.conf.js",
"test:applitools": "wdio wdio.applitools.conf.js"
},
"devDependencies": {
"@applitools/eyes-webdriverio": "^5.51.2",
"@wdio/allure-reporter": "^8.34.0",
"@wdio/applitools-service": "^7.3.0",
"@wdio/cli": "^8.35.1",
"@wdio/local-runner": "^8.35.1",
"@wdio/mocha-framework": "^8.35.0",
"@wdio/spec-reporter": "^8.32.4",
"allure-commandline": "^2.27.0",
"webdriverio": "^8.35.1"
"@wdio/visual-service": "^4.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.3"
},
"scripts": {
"test:desktop": "wdio run ./wdio.conf.ts --spec='test/specs/desktop.spec.ts'",
"test:desktop:layout": "ENABLE_LAYOUT_TESTING=true wdio run ./wdio.conf.ts --spec='test/specs/desktop.spec.ts'",
"test:storybook:local": "wdio ./wdio.conf.ts --storybook",
"test:storybook:external": "wdio ./wdio.conf.ts --storybook --url=https://govuk-react.github.io/govuk-react/ --numShards=10",
"test:storybook:external:skipped": "wdio ./wdio.conf.ts --storybook --url=https://govuk-react.github.io/govuk-react/ --numShards=10 --skipStories=\"/.*(loading-box|spinner).*/\"",
"test:mobile:android:app": "wdio run ./wdio.android.emulator.conf.ts --spec='test/specs/mobile.app.spec.ts'"
}
}
}
47 changes: 0 additions & 47 deletions solutions/chapter_11/test/pageobjects/main.page.js

This file was deleted.

17 changes: 0 additions & 17 deletions solutions/chapter_11/test/pageobjects/todo.entry.js

This file was deleted.

21 changes: 21 additions & 0 deletions solutions/chapter_11/test/specs/desktop.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {$, browser, expect} from '@wdio/globals'

describe('Guinea Pig Application', () => {
beforeEach(async () => {
await browser.setWindowSize(1200, 800)
await browser.url('http://guinea-pig.webdriver.io/image-compare.html')
await $('.hero__title-logo').waitForDisplayed()
});

it('should be able to create an element snapshot', async () => {
await expect($('.hero__title-logo')).toMatchElementSnapshot('logo', {hideElements: [await $('nav.navbar')]})
})

it('should be able to create a viewport snapshot', async () => {
await expect(browser).toMatchScreenSnapshot('viewport')
})

it('should be able to create fullpage snapshot', async () => {
await expect(browser).toMatchFullPageSnapshot('fullpage', {hideAfterFirstScroll: [await $('nav.navbar')]})
})
})
32 changes: 32 additions & 0 deletions solutions/chapter_11/test/specs/mobile.app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {$, browser, expect} from '@wdio/globals'

describe('Mobile Application', () => {
beforeEach(async () => {
await relaunchApp()
await $('~Home-screen').waitForDisplayed()
await $('~Login').click()
await $('~button-LOGIN').waitForDisplayed()
})

it('should be able to create an element snapshot', async () => {
await expect($('~button-LOGIN')).toMatchElementSnapshot('login-button', {hideElements: [await $('nav.navbar')]})
})

it('should be able to create a device snapshot', async () => {
await expect(browser).toMatchScreenSnapshot('app-forms', {blockOutToolBar: true, blockOutStatusBar: true})
})
})

/**
* Simple function to relaunch the app
*/
async function relaunchApp() {
wswebcreation marked this conversation as resolved.
Show resolved Hide resolved
const PACKAGE_NAME = 'com.wdiodemoapp'
const BUNDLE_ID = 'org.reactjs.native.example.wdiodemoapp'
const appIdentifier = browser.isAndroid ? { 'appId': PACKAGE_NAME } : { 'bundleId': BUNDLE_ID }
const terminateCommand = 'mobile: terminateApp'
const launchCommand = `mobile: ${driver.isAndroid ? 'activateApp' : 'launchApp'}`

await browser.execute(terminateCommand, appIdentifier)
await browser.execute(launchCommand, appIdentifier)
}
57 changes: 0 additions & 57 deletions solutions/chapter_11/test/specs/test.js

This file was deleted.

31 changes: 31 additions & 0 deletions solutions/chapter_11/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "ESNext",
"target": "es2022",
"lib": [
"es2022",
"dom"
],
"types": [
"node",
"@wdio/globals/types",
"expect-webdriverio",
"@wdio/mocha-framework",
"@wdio/visual-service"
],
"skipLibCheck": true,
"noEmit": true,
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": [
"test/**/*.ts",
"*.conf.ts"
]
}
21 changes: 21 additions & 0 deletions solutions/chapter_11/wdio.android.emulator.conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Options } from '@wdio/types'
import {join} from 'node:path';
import {config as sharedConfig} from './wdio.conf.js';

export const config: Options.Testrunner = {
...sharedConfig,
capabilities: [
{
platformName: 'Android',
'appium:automationName': 'UIAutomator2',
// Change this to the name of your emulator
'appium:deviceName': 'Pixel_7_Pro_Android_14_API_34',
// Change this to the version of your emulator
'appium:platformVersion': '14.0',
// Change this to the path/name of your app
'appium:app': join(process.cwd(), './apps/android.wdio.native.app.v1.0.8.apk'),
wswebcreation marked this conversation as resolved.
Show resolved Hide resolved
'appium:newCommandTimeout': 240,
}
],
port: 4723,
};
40 changes: 0 additions & 40 deletions solutions/chapter_11/wdio.applitools.conf.js

This file was deleted.

Loading
Loading