Skip to content

Commit 21b02eb

Browse files
Bump webdriverio to v9 (#4594)
* Bump webdriverio to v9 * Adjust config * Adjust config * Remove options * Update chrome driver * Fix deprecations * Fix deprecations * Fix markup * Added condition * Fix more tests * Fix iFrame stuff * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * try to fix some wdio tests * Try to fix popup test * Try to fix window size #resizeWindow * Another fix * Fix popup tests * Enable should be authenticated * Trigger Build --------- Co-authored-by: kobenguyent <[email protected]> Co-authored-by: kobenguyent <[email protected]>
1 parent 3c1bca5 commit 21b02eb

File tree

10 files changed

+111
-96
lines changed

10 files changed

+111
-96
lines changed

.github/workflows/webdriver.yml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,30 @@ env:
1515

1616
jobs:
1717
build:
18-
1918
runs-on: ubuntu-latest
2019
strategy:
2120
matrix:
2221
node-version: [20.x]
2322

2423
steps:
25-
- run: docker run -d --net=host --shm-size=2g selenium/standalone-chrome:3.141.0
26-
- uses: actions/checkout@v4
27-
- name: Use Node.js ${{ matrix.node-version }}
28-
uses: actions/setup-node@v4
29-
with:
30-
node-version: ${{ matrix.node-version }}
31-
- uses: shivammathur/setup-php@v2
32-
with:
33-
php-version: 8.0
34-
- name: npm install
35-
run: |
36-
npm i --force
37-
env:
38-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
39-
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
40-
- name: start a server
41-
run: "php -S 127.0.0.1:8000 -t test/data/app &"
42-
- name: run unit tests
43-
run: ./node_modules/.bin/mocha test/helper/WebDriver_test.js --exit
44-
- name: run unit tests - no selenium server
45-
run: ./node_modules/.bin/mocha test/helper/WebDriver.noSeleniumServer_test.js --exit
46-
- name: run tests
47-
run: "./bin/codecept.js run -c test/acceptance/codecept.WebDriver.js --grep @WebDriver --debug"
48-
24+
- run: docker run -d --net=host --shm-size=2g selenium/standalone-chrome:4.27
25+
- uses: actions/checkout@v4
26+
- name: Use Node.js ${{ matrix.node-version }}
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
- uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: 8.0
33+
- name: npm install
34+
run: |
35+
npm i
36+
env:
37+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
38+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
39+
- name: start a server
40+
run: 'php -S 127.0.0.1:8000 -t test/data/app &'
41+
- name: run unit tests
42+
run: ./node_modules/.bin/mocha test/helper/WebDriver_test.js --exit
43+
- name: run tests
44+
run: './bin/codecept.js run -c test/acceptance/codecept.WebDriver.js --grep @WebDriver --debug'

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export default [
8080
'prefer-const': 0,
8181
'no-extra-semi': 0,
8282
'max-classes-per-file': 0,
83+
'no-return-await': 0,
8384
},
8485
},
8586
]

lib/helper/WebDriver.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ class WebDriver extends Helper {
644644
this.isRunning = false
645645
return this.browser.deleteSession()
646646
}
647-
if (this.browser.isInsideFrame) await this.browser.switchToFrame(null)
647+
if (this.browser.isInsideFrame) await this.browser.switchFrame(null)
648648

649649
if (this.options.keepBrowserState) return
650650

@@ -1898,23 +1898,21 @@ class WebDriver extends Helper {
18981898
* libraries](http://jster.net/category/windows-modals-popups).
18991899
*/
19001900
async acceptPopup() {
1901-
return this.browser.getAlertText().then(res => {
1902-
if (res !== null) {
1903-
return this.browser.acceptAlert()
1904-
}
1905-
})
1901+
const text = await this.browser.getAlertText()
1902+
if (text) {
1903+
return await this.browser.acceptAlert()
1904+
}
19061905
}
19071906

19081907
/**
19091908
* Dismisses the active JavaScript popup, as created by `window.alert|window.confirm|window.prompt`.
19101909
*
19111910
*/
19121911
async cancelPopup() {
1913-
return this.browser.getAlertText().then(res => {
1914-
if (res !== null) {
1915-
return this.browser.dismissAlert()
1916-
}
1917-
})
1912+
const text = await this.browser.getAlertText()
1913+
if (text) {
1914+
return await this.browser.dismissAlert()
1915+
}
19181916
}
19191917

19201918
/**
@@ -1924,7 +1922,7 @@ class WebDriver extends Helper {
19241922
* @param {string} text value to check.
19251923
*/
19261924
async seeInPopup(text) {
1927-
return this.browser.getAlertText().then(res => {
1925+
return await this.browser.getAlertText().then(res => {
19281926
if (res === null) {
19291927
throw new Error('Popup is not opened')
19301928
}
@@ -2514,17 +2512,14 @@ class WebDriver extends Helper {
25142512
*/
25152513
async switchTo(locator) {
25162514
this.browser.isInsideFrame = true
2517-
if (Number.isInteger(locator)) {
2518-
return this.browser.switchToFrame(locator)
2519-
}
25202515
if (!locator) {
2521-
return this.browser.switchToFrame(null)
2516+
return this.browser.switchFrame(null)
25222517
}
25232518

25242519
let res = await this._locate(locator, true)
25252520
assertElementExists(res, locator)
25262521
res = usingFirstElement(res)
2527-
return this.browser.switchToFrame(res)
2522+
return this.browser.switchFrame(res)
25282523
}
25292524

25302525
/**
@@ -2824,7 +2819,7 @@ async function proceedSeeField(assertType, field, value) {
28242819
const fieldResults = toArray(
28252820
await forEachAsync(fields, async el => {
28262821
const elementId = getElementId(el)
2827-
return this.browser.isW3C ? el.getValue() : this.browser.getElementAttribute(elementId, 'value')
2822+
return this.browser.getElementAttribute(elementId, 'value')
28282823
}),
28292824
)
28302825

@@ -2850,15 +2845,21 @@ async function proceedSeeField(assertType, field, value) {
28502845
const filterSelectedByValue = async (elements, value) => {
28512846
return filterAsync(elements, async el => {
28522847
const elementId = getElementId(el)
2853-
const currentValue = this.browser.isW3C ? await el.getValue() : await this.browser.getElementAttribute(elementId, 'value')
2848+
const currentValue = await this.browser.getElementAttribute(elementId, 'value')
28542849
const isSelected = await this.browser.isElementSelected(elementId)
28552850
return currentValue === value && isSelected
28562851
})
28572852
}
28582853

28592854
const tag = await elem.getTagName()
28602855
if (tag === 'select') {
2861-
const subOptions = await this.browser.findElementsFromElement(elemId, 'css', 'option')
2856+
let subOptions
2857+
2858+
try {
2859+
subOptions = await this.browser.findElementsFromElement(elemId, 'css', 'option')
2860+
} catch (e) {
2861+
subOptions = await this.browser.findElementsFromElement(elemId, 'xpath', 'option')
2862+
}
28622863

28632864
if (value === '') {
28642865
// Don't filter by value

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
"test-app:stop": "kill -9 $(lsof -t -i:8000)",
5757
"test:unit:webbapi:playwright": "mocha test/helper/Playwright_test.js",
5858
"test:unit:webbapi:puppeteer": "mocha test/helper/Puppeteer_test.js",
59-
"test:unit:webbapi:webDriver": "mocha test/helper/WebDriver_test.js",
60-
"test:unit:webbapi:webDriver:noSeleniumServer": "mocha test/helper/WebDriver.noSeleniumServer_test.js",
59+
"test:unit:webbapi:webDriver": "mocha test/helper/WebDriver_test.js --timeout 10000",
60+
"test:unit:webbapi:webDriver:noSeleniumServer": "mocha test/helper/WebDriver.noSeleniumServer_test.js --timeout 10000",
6161
"test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js",
6262
"test:unit:expect": "mocha test/helper/Expect_test.js",
6363
"test:plugin": "mocha test/plugin/plugin_test.js",
@@ -168,7 +168,7 @@
168168
"typedoc-plugin-markdown": "4.4.1",
169169
"typescript": "5.7.2",
170170
"wdio-docker-service": "1.5.0",
171-
"webdriverio": "8.40.6",
171+
"webdriverio": "^9.5.1",
172172
"xml2js": "0.6.2",
173173
"xpath": "0.0.34"
174174
},

test/acceptance/codecept.WebDriver.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const TestHelper = require('../support/TestHelper')
22

33
module.exports.config = {
44
tests: './*_test.js',
5-
timeout: 10000,
5+
timeout: 20,
66
output: './output',
77
helpers: {
88
WebDriver: {
@@ -11,11 +11,11 @@ module.exports.config = {
1111
host: TestHelper.seleniumHost(),
1212
port: TestHelper.seleniumPort(),
1313
// disableScreenshots: true,
14-
// desiredCapabilities: {
15-
// chromeOptions: {
16-
// args: ['--headless', '--disable-gpu', '--window-size=1280,1024'],
17-
// },
18-
// },
14+
desiredCapabilities: {
15+
chromeOptions: {
16+
args: ['--headless', '--disable-gpu', '--window-size=500,700'],
17+
},
18+
},
1919
},
2020
ScreenshotSessionHelper: {
2121
require: '../support/ScreenshotSessionHelper.js',

test/acceptance/session_test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ const { event } = codeceptjs
44

55
Feature('Session')
66

7-
Scenario('simple session @WebDriverIO @Puppeteer @Playwright', ({ I }) => {
7+
Scenario('simple session @Puppeteer @Playwright', ({ I }) => {
88
I.amOnPage('/info')
99
session('john', () => {
10-
I.amOnPage('https://codecept.io/')
10+
I.amOnPage('/login')
1111
I.dontSeeInCurrentUrl('/info')
12-
I.see('CodeceptJS')
12+
I.see('Email')
1313
})
14-
I.dontSee('GitHub')
14+
I.dontSee('Email')
1515
I.seeInCurrentUrl('/info')
1616
})
1717

18-
Scenario('screenshots reflect the current page of current session @Puppeteer @Playwright @WebDriver', async ({ I }) => {
18+
Scenario('screenshots reflect the current page of current session @Puppeteer @Playwright', async ({ I }) => {
1919
I.amOnPage('/')
2020
I.saveScreenshot('session_default_1.png')
2121

@@ -77,7 +77,7 @@ Scenario('Different cookies for different sessions @Playwright @Puppeteer', asyn
7777
I.expectNotEqual(cookies.john, cookies.mary)
7878
})
7979

80-
Scenario('should save screenshot for sessions @WebDriverIO @Puppeteer @Playwright', async function ({ I }) {
80+
Scenario('should save screenshot for sessions @Puppeteer @Playwright', async function ({ I }) {
8181
await I.amOnPage('/form/bug1467')
8282
await I.saveScreenshot('original.png')
8383
await I.amOnPage('/')
@@ -98,7 +98,7 @@ Scenario('should save screenshot for sessions @WebDriverIO @Puppeteer @Playwrigh
9898
await I.expectNotEqual(main_original, session_failed)
9999
})
100100

101-
Scenario('should throw exception and close correctly @WebDriverIO @Puppeteer @Playwright', ({ I }) => {
101+
Scenario('should throw exception and close correctly @Puppeteer @Playwright', ({ I }) => {
102102
I.amOnPage('/form/bug1467#session1')
103103
I.checkOption('Yes')
104104
session('john', () => {
@@ -110,7 +110,7 @@ Scenario('should throw exception and close correctly @WebDriverIO @Puppeteer @Pl
110110
I.amOnPage('/info')
111111
}).fails()
112112

113-
Scenario('async/await @WebDriverIO', ({ I }) => {
113+
Scenario('async/await', ({ I }) => {
114114
I.amOnPage('/form/bug1467#session1')
115115
I.checkOption('Yes')
116116
session('john', async () => {
@@ -121,7 +121,7 @@ Scenario('async/await @WebDriverIO', ({ I }) => {
121121
I.seeCheckboxIsChecked({ css: 'input[value=Yes]' })
122122
})
123123

124-
Scenario('exception on async/await @WebDriverIO @Puppeteer @Playwright', ({ I }) => {
124+
Scenario('exception on async/await @Puppeteer @Playwright', ({ I }) => {
125125
I.amOnPage('/form/bug1467#session1')
126126
I.checkOption('Yes')
127127
session('john', async () => {
@@ -132,7 +132,7 @@ Scenario('exception on async/await @WebDriverIO @Puppeteer @Playwright', ({ I })
132132
I.seeCheckboxIsChecked({ css: 'input[value=Yes]' })
133133
}).throws(/to be checked/)
134134

135-
Scenario('should work with within @WebDriverIO @Puppeteer @Playwright', ({ I }) => {
135+
Scenario('should work with within @Puppeteer @Playwright', ({ I }) => {
136136
I.amOnPage('/form/bug1467')
137137
session('john', () => {
138138
I.amOnPage('/form/bug1467')
@@ -209,7 +209,7 @@ xScenario('should start firefox', async ({ I }) => {
209209
assert(isChrome)
210210
})
211211

212-
Scenario('should return a value in @WebDriverIO @Puppeteer @Playwright', async ({ I }) => {
212+
Scenario('should return a value in @Puppeteer @Playwright', async ({ I }) => {
213213
I.amOnPage('/form/textarea')
214214
const val = await session('john', () => {
215215
I.amOnPage('/info')
@@ -220,7 +220,7 @@ Scenario('should return a value in @WebDriverIO @Puppeteer @Playwright', async (
220220
I.see('[description] => Information')
221221
})
222222

223-
Scenario('should return a value @WebDriverIO @Puppeteer @Playwright in async', async ({ I }) => {
223+
Scenario('should return a value @Puppeteer @Playwright in async', async ({ I }) => {
224224
I.amOnPage('/form/textarea')
225225
const val = await session('john', async () => {
226226
I.amOnPage('/info')

test/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ services:
5353
- node_modules:/node_modules
5454

5555
selenium.chrome:
56-
image: selenium/standalone-chrome:3.141.59-oxygen
56+
image: selenium/standalone-chrome:4.26
5757
shm_size: 2g
5858
ports:
5959
- 4444:4444

test/helper/WebDriver.noSeleniumServer_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ describe('WebDriver - No Selenium server started', function () {
382382
})
383383
})
384384

385+
385386
describe('#seeTitleEquals', () => {
386387
it('should check that title is equal to provided one', async () => {
387388
await wd.amOnPage('/')

0 commit comments

Comments
 (0)