Skip to content

Commit 3f685e0

Browse files
committed
Switch to async Webdriver.io mode.
1 parent d8ad149 commit 3f685e0

File tree

4 files changed

+47
-34
lines changed

4 files changed

+47
-34
lines changed

docker-compose.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ services:
44
build: server/php
55
ports:
66
- 127.0.0.1:80:80
7-
- ${SERVER_HOST:-127.0.0.1}:${SERVER_PORT-}:80
87
volumes:
98
- .:/var/www/html
109
mocha:
@@ -16,7 +15,6 @@ services:
1615
- example
1716
chromedriver:
1817
image: blueimp/chromedriver
19-
init: true
2018
tmpfs: /tmp
2119
environment:
2220
- DISABLE_X11=false
@@ -28,7 +26,6 @@ services:
2826
- 127.0.0.1:5900:5900
2927
geckodriver:
3028
image: blueimp/geckodriver
31-
init: true
3229
tmpfs: /tmp
3330
shm_size: 2g
3431
environment:
@@ -41,18 +38,17 @@ services:
4138
- 127.0.0.1:5901:5900
4239
wdio:
4340
image: blueimp/wdio
44-
init: true
4541
read_only: true
4642
tmpfs:
4743
- /tmp
4844
environment:
49-
- WAIT_FOR_HOSTS= chromedriver:4444 geckodriver:4444 example:80
45+
- WAIT_FOR_HOSTS=chromedriver:4444 geckodriver:4444 example:80
5046
- WINDOWS_HOST
5147
- MACOS_ASSETS_DIR=$PWD/wdio/assets/
5248
- WINDOWS_ASSETS_DIR
5349
volumes:
54-
- ./wdio:/opt:ro
55-
- ./wdio/reports:/opt/reports
50+
- ./wdio:/app:ro
51+
- ./wdio/reports:/app/reports
5652
depends_on:
5753
- chromedriver
5854
- geckodriver

wdio/hooks/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55
const cmds = require('wdio-screen-commands')
66

77
/* eslint-disable jsdoc/valid-types */
8-
/** @type WebdriverIO.HookFunctions */
8+
/** @type WebdriverIO.HookFunctionExtension */
99
const config = {
1010
before: async () => {
11+
// Add browser commands:
1112
browser.addCommand('saveScreenshotByName', cmds.saveScreenshotByName)
1213
browser.addCommand('saveAndDiffScreenshot', cmds.saveAndDiffScreenshot)
14+
// Add element commands:
15+
browser.addCommand('saveScreenshotByName', cmds.saveScreenshotByName, true)
16+
browser.addCommand(
17+
'saveAndDiffScreenshot',
18+
cmds.saveAndDiffScreenshot,
19+
true
20+
)
21+
if (browser.config.appium)
22+
await browser.updateSettings(browser.config.appium)
1323
if (browser.config.maximizeWindow) await browser.maximizeWindow()
1424
},
1525
beforeTest: async test => {

wdio/test/pages/file-upload.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,47 @@ class FileUpload {
3232
* Opens the file upload form.
3333
*
3434
* @param {number} [timeout] Wait timeout
35-
* @returns {FileUpload} FileUpload object
3635
*/
37-
open(timeout) {
38-
browser.url('/')
39-
this.fileinput.waitForExist({ timeout })
40-
return this
36+
async open(timeout) {
37+
await browser.url('/')
38+
await this.fileinput.waitForExist({ timeout })
4139
}
4240
/**
4341
* Uploads files.
4442
*
4543
* @param {Array<string>} files Files to upload
4644
* @param {number} [timeout] Wait timeout
47-
* @returns {FileUpload} FileUpload object
4845
*/
49-
upload(files, timeout) {
50-
this.fileinput.addValue(files.join('\n'))
51-
browser.waitUntil(() => !this.processing.length, { timeout })
52-
this.start.click()
53-
browser.waitUntil(() => !!this.downloads.length, { timeout })
54-
browser.waitUntil(() => !this.uploads.length, { timeout })
55-
return this
46+
async upload(files, timeout) {
47+
await this.fileinput.addValue(files.join('\n'))
48+
await browser.waitUntil(async () => !(await this.processing.length), {
49+
timeout
50+
})
51+
await this.start.click()
52+
await browser.waitUntil(async () => !!(await this.downloads.length), {
53+
timeout
54+
})
55+
await browser.waitUntil(async () => !(await this.uploads.length), {
56+
timeout
57+
})
5658
}
5759
/**
5860
* Deletes uploaded files.
5961
*
6062
* @param {number} [timeout] Wait timeout
61-
* @returns {FileUpload} FileUpload object
6263
*/
63-
delete(timeout) {
64-
this.toggle.click()
65-
browser.waitUntil(() => this.downloads.length === this.checked.length, {
64+
async delete(timeout) {
65+
await this.toggle.click()
66+
await browser.waitUntil(
67+
async () => (await this.downloads.length) === (await this.checked.length),
68+
{
69+
timeout
70+
}
71+
)
72+
await this.remove.click()
73+
await browser.waitUntil(async () => !(await this.downloads.length), {
6674
timeout
6775
})
68-
this.remove.click()
69-
browser.waitUntil(() => !this.downloads.length, { timeout })
70-
return this
7176
}
7277
}
7378

wdio/test/specs/01-file-upload.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ const assetsDir = browser.config.assetsDir
88
describe('File Upload', () => {
99
if (!assetsDir) return
1010

11-
it('uploads files', () => {
12-
FileUpload.open().upload([
11+
it('uploads files', async () => {
12+
await FileUpload.open()
13+
await FileUpload.upload([
1314
assetsDir + 'black+white-60x40.gif',
1415
assetsDir + 'black+white-3x2.jpg'
1516
])
16-
browser.saveAndDiffScreenshot('Files uploaded')
17+
await browser.saveAndDiffScreenshot('Files uploaded')
1718
})
1819

19-
it('deletes files', () => {
20-
FileUpload.open().delete()
21-
browser.saveAndDiffScreenshot('Files deleted')
20+
it('deletes files', async () => {
21+
await FileUpload.open()
22+
await FileUpload.delete()
23+
await browser.saveAndDiffScreenshot('Files deleted')
2224
})
2325
})

0 commit comments

Comments
 (0)