Skip to content

Commit 9862ef9

Browse files
committed
test: update tests
1 parent ea122aa commit 9862ef9

2 files changed

Lines changed: 142 additions & 26 deletions

File tree

tests/configs/wdio.local.android.emus.web.conf.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export const config: WebdriverIO.Config = {
1212
// Capabilities
1313
// ============
1414
capabilities: [
15-
// androidCaps('Pixel_8_Pro_Android_15_API_35', 'PORTRAIT', '15.0', true),
16-
androidCaps('Pixel_8_Pro_Android_15_API_35', 'LANDSCAPE', '15.0', true),
15+
androidCaps('Pixel_8_Pro_Android_15_API_35', 'PORTRAIT', '15.0', true),
16+
// androidCaps('Pixel_8_Pro_Android_15_API_35', 'LANDSCAPE', '15.0', true),
1717
],
1818
}
1919

@@ -36,6 +36,7 @@ function androidCaps(
3636
'appium:orientation': orientation,
3737
'appium:newCommandTimeout': 240,
3838
...(nativeWebScreenshot ? { 'appium:nativeWebScreenshot': true } : {}),
39+
'wdio:enforceWebDriverClassic': true,
3940
'wdio-ics:options': {
4041
logName: `${deviceName
4142
.split(' ')

tests/specs/mobile.web.spec.ts

Lines changed: 139 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,15 @@ import { browser, expect } from '@wdio/globals'
66
describe('@wdio/visual-service mobile web', () => {
77
// Get the commands that need to be executed
88
// 0 means all, otherwise it will only execute the commands that are specified
9-
const wdioIcsCommands = driver.requestedCapabilities['wdio-ics:options'].commands
10-
const deviceName = driver.requestedCapabilities['lt:options']?.deviceName ||
11-
driver.requestedCapabilities['bstack:options']?.deviceName ||
12-
driver.requestedCapabilities['appium:options']?.deviceName ||
13-
driver.requestedCapabilities.deviceName
14-
const platformName = (
15-
driver.requestedCapabilities['lt:options']?.platformName ||
16-
driver.requestedCapabilities['appium:options']?.platformName ||
17-
driver.requestedCapabilities.platformName
18-
).toLowerCase() === 'android' ? 'Android' : 'iOS'
19-
const platformVersion =
20-
driver.requestedCapabilities['lt:options']?.platformVersion ||
21-
driver.requestedCapabilities['bstack:options']?.osVersion ||
22-
driver.requestedCapabilities['appium:options']?.platformVersion ||
23-
driver.requestedCapabilities.platformVersion
24-
const orientation = (
25-
driver.requestedCapabilities['lt:options']?.deviceOrientation ||
26-
driver.requestedCapabilities['bstack:options']?.deviceOrientation ||
27-
driver.requestedCapabilities['appium:options']?.orientation ||
28-
driver.requestedCapabilities.orientation || 'PORTRAIT'
29-
).toLowerCase()
9+
const caps = driver.requestedCapabilities
10+
const lt = caps['lt:options']
11+
const bs = caps['bstack:options']
12+
const appium = caps['appium:options']
13+
const wdioIcsCommands = caps['wdio-ics:options'].commands
14+
const deviceName = lt?.deviceName || bs?.deviceName || appium?.deviceName || caps.deviceName
15+
const platformName = (lt?.platformName || appium?.platformName || caps.platformName).toLowerCase() === 'android' ? 'Android' : 'iOS'
16+
const platformVersion = lt?.platformVersion || bs?.osVersion || appium?.platformVersion || caps.platformVersion
17+
const orientation = (lt?.deviceOrientation || bs?.deviceOrientation || appium?.orientation || caps.orientation || 'PORTRAIT').toLowerCase()
3018

3119
beforeEach(async () => {
3220
await browser.url('')
@@ -44,7 +32,7 @@ describe('@wdio/visual-service mobile web', () => {
4432
wdioIcsCommands.includes('checkScreen')
4533
) {
4634
it(`should compare a screen successful for '${deviceName}' with ${platformName}:${platformVersion} in ${orientation}-mode`, async function () {
47-
// @ts-ignore
35+
skipTest({ test: this, deviceName, platformName, platformVersion, orientation })
4836
this.retries(2)
4937

5038
// This is normally a bad practice, but a mobile screenshot is normally around 1M pixels
@@ -68,15 +56,39 @@ describe('@wdio/visual-service mobile web', () => {
6856
await browser.setOrientation(orientation)
6957
await expect(newResult < 0.05 ? 0 : newResult).toEqual(0)
7058
})
59+
60+
it(`should compare a screen with ignore elements successful for '${deviceName}' with ${platformName}:${platformVersion} in ${orientation}-mode`, async function () {
61+
skipTest({ test: this, deviceName, platformName, platformVersion, orientation })
62+
63+
await browser.execute(() => {
64+
document.querySelectorAll('.getStarted_Sjon').forEach(link => {
65+
(link as HTMLElement).style.backgroundColor = 'var(--ifm-font-color-base)'
66+
})
67+
})
68+
69+
// This is normally a bad practice, but a mobile screenshot is normally around 1M pixels
70+
// We're accepting 0.05%, which is 500 pixels, to be a max difference
71+
const result = await browser.checkScreen(
72+
'ignoredElementsScreenshot', {
73+
ignore: [
74+
await $$('.getStarted_Sjon'),
75+
],
76+
}) as number
77+
if (result > 0 && result < 0.05) {
78+
console.log(`\n\n\n'Screenshot for ${deviceName}' with ${platformName}:${platformVersion} in ${orientation}-mode has a difference of ${result}%\n\n\n`)
79+
}
80+
await expect(result < 0.05 ? 0 : result).toEqual(0)
81+
})
7182
}
7283

7384
if (
7485
wdioIcsCommands.length === 0 ||
7586
wdioIcsCommands.includes('checkElement')
7687
) {
7788
it(`should compare an element successful for '${deviceName}' with ${platformName}:${platformVersion} in ${orientation}-mode`, async function() {
78-
// @ts-ignore
89+
skipTest({ test: this, deviceName, platformName, platformVersion, orientation })
7990
this.retries(2)
91+
8092
await expect(
8193
await browser.checkElement(
8294
await $('.hero__title-logo'),
@@ -94,8 +106,9 @@ describe('@wdio/visual-service mobile web', () => {
94106
wdioIcsCommands.includes('checkFullPageScreen')
95107
) {
96108
it(`should compare a full page screenshot successful for '${deviceName}' with ${platformName}:${platformVersion} in ${orientation}-mode`, async function() {
97-
// @ts-ignore
109+
skipTest({ test: this, deviceName, platformName, platformVersion, orientation })
98110
this.retries(2)
111+
99112
// This is normally a bad practice, but a mobile full page screenshot is normally around 4M pixels
100113
// We're accepting 0.05%, which is 2000 pixels, to be a max difference
101114
const result = await browser.checkFullPageScreen('fullPage', {
@@ -111,3 +124,105 @@ describe('@wdio/visual-service mobile web', () => {
111124
})
112125
}
113126
})
127+
128+
interface SkipRule {
129+
titleIncludes: string
130+
deviceName: string
131+
platformName: 'Android' | 'iOS'
132+
platformVersions: string[]
133+
orientations: ('landscape' | 'portrait')[]
134+
reason: string
135+
}
136+
137+
/**
138+
* Rules for skipping tests,
139+
* these are most likely TODO's that we have to fix but are not a blocker for the release
140+
*/
141+
const skipRules: SkipRule[] = [
142+
{
143+
// @TODO: remove when fixed
144+
titleIncludes: 'ignore elements',
145+
deviceName: 'Pixel 9 Pro',
146+
platformName: 'Android',
147+
platformVersions: ['15'],
148+
orientations: ['portrait'],
149+
reason: '1px difference in the ignore elements screenshot',
150+
},
151+
{
152+
// @TODO: remove when fixed
153+
titleIncludes: 'ignore elements',
154+
deviceName: 'Galaxy Tab S8',
155+
platformName: 'Android',
156+
platformVersions: ['13'],
157+
orientations: ['landscape', 'portrait'],
158+
reason: '1px difference in the ignore elements screenshot',
159+
},
160+
{
161+
// @TODO: remove when fixed
162+
titleIncludes: 'ignore elements',
163+
deviceName: 'Galaxy Tab S8',
164+
platformName: 'Android',
165+
platformVersions: ['14'],
166+
orientations: ['portrait'],
167+
reason: '1px difference in the ignore elements screenshot',
168+
},
169+
{
170+
// @TODO: remove when fixed
171+
titleIncludes: 'ignore elements',
172+
deviceName: 'Galaxy Tab S8',
173+
platformName: 'Android',
174+
platformVersions: ['14'],
175+
orientations: ['landscape'],
176+
reason: 'Fully ignored in the screenshot so it will never find a difference',
177+
},
178+
{
179+
// @TODO: remove when fixed
180+
titleIncludes: 'ignore elements',
181+
deviceName: 'Pixel 4',
182+
platformName: 'Android',
183+
platformVersions: ['13'],
184+
orientations: ['landscape', 'portrait'],
185+
reason: 'Fully ignored in the screenshot so it will never find a difference',
186+
},
187+
{
188+
titleIncludes: 'ignore elements',
189+
deviceName: 'Pixel 9 Pro',
190+
platformName: 'Android',
191+
platformVersions: ['14', '15'],
192+
orientations: ['landscape'],
193+
reason: 'Elements not visible in the screenshot, no value in testing',
194+
},
195+
{
196+
titleIncludes: 'ignore elements',
197+
deviceName: 'Pixel 4',
198+
platformName: 'Android',
199+
platformVersions: ['11', '12'],
200+
orientations: ['landscape', 'portrait'],
201+
reason: 'Elements not visible in the screenshot, no value in testing',
202+
},
203+
]
204+
205+
/**
206+
* Skips a test if it matches any of the skip rules
207+
*/
208+
function skipTest({ test, deviceName, platformName, platformVersion, orientation }: {
209+
test: Mocha.Context
210+
deviceName: string
211+
platformName: string
212+
platformVersion: string
213+
orientation: string
214+
}) {
215+
const { title } = test.test!
216+
217+
const matchedRule = skipRules.find(rule =>
218+
title.includes(rule.titleIncludes)
219+
&& rule.deviceName === deviceName
220+
&& rule.platformName === platformName
221+
&& rule.platformVersions.includes(platformVersion)
222+
&& rule.orientations.includes(orientation as 'landscape' | 'portrait')
223+
)
224+
225+
if (matchedRule) {
226+
test.skip()
227+
}
228+
}

0 commit comments

Comments
 (0)