Skip to content

Commit

Permalink
Bump webdriverio to v9 (#4594)
Browse files Browse the repository at this point in the history
* 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 <7845001+kobenguyent@users.noreply.github.com>
Co-authored-by: kobenguyent <kobenguyent@gmail.com>
  • Loading branch information
3 people authored Jan 6, 2025
1 parent 3c1bca5 commit 21b02eb
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 96 deletions.
46 changes: 21 additions & 25 deletions .github/workflows/webdriver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,30 @@ env:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]

steps:
- run: docker run -d --net=host --shm-size=2g selenium/standalone-chrome:3.141.0
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
- name: npm install
run: |
npm i --force
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- name: start a server
run: "php -S 127.0.0.1:8000 -t test/data/app &"
- name: run unit tests
run: ./node_modules/.bin/mocha test/helper/WebDriver_test.js --exit
- name: run unit tests - no selenium server
run: ./node_modules/.bin/mocha test/helper/WebDriver.noSeleniumServer_test.js --exit
- name: run tests
run: "./bin/codecept.js run -c test/acceptance/codecept.WebDriver.js --grep @WebDriver --debug"

- run: docker run -d --net=host --shm-size=2g selenium/standalone-chrome:4.27
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
- name: npm install
run: |
npm i
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- name: start a server
run: 'php -S 127.0.0.1:8000 -t test/data/app &'
- name: run unit tests
run: ./node_modules/.bin/mocha test/helper/WebDriver_test.js --exit
- name: run tests
run: './bin/codecept.js run -c test/acceptance/codecept.WebDriver.js --grep @WebDriver --debug'
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default [
'prefer-const': 0,
'no-extra-semi': 0,
'max-classes-per-file': 0,
'no-return-await': 0,
},
},
]
41 changes: 21 additions & 20 deletions lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ class WebDriver extends Helper {
this.isRunning = false
return this.browser.deleteSession()
}
if (this.browser.isInsideFrame) await this.browser.switchToFrame(null)
if (this.browser.isInsideFrame) await this.browser.switchFrame(null)

if (this.options.keepBrowserState) return

Expand Down Expand Up @@ -1898,23 +1898,21 @@ class WebDriver extends Helper {
* libraries](http://jster.net/category/windows-modals-popups).
*/
async acceptPopup() {
return this.browser.getAlertText().then(res => {
if (res !== null) {
return this.browser.acceptAlert()
}
})
const text = await this.browser.getAlertText()
if (text) {
return await this.browser.acceptAlert()
}
}

/**
* Dismisses the active JavaScript popup, as created by `window.alert|window.confirm|window.prompt`.
*
*/
async cancelPopup() {
return this.browser.getAlertText().then(res => {
if (res !== null) {
return this.browser.dismissAlert()
}
})
const text = await this.browser.getAlertText()
if (text) {
return await this.browser.dismissAlert()
}
}

/**
Expand All @@ -1924,7 +1922,7 @@ class WebDriver extends Helper {
* @param {string} text value to check.
*/
async seeInPopup(text) {
return this.browser.getAlertText().then(res => {
return await this.browser.getAlertText().then(res => {
if (res === null) {
throw new Error('Popup is not opened')
}
Expand Down Expand Up @@ -2514,17 +2512,14 @@ class WebDriver extends Helper {
*/
async switchTo(locator) {
this.browser.isInsideFrame = true
if (Number.isInteger(locator)) {
return this.browser.switchToFrame(locator)
}
if (!locator) {
return this.browser.switchToFrame(null)
return this.browser.switchFrame(null)
}

let res = await this._locate(locator, true)
assertElementExists(res, locator)
res = usingFirstElement(res)
return this.browser.switchToFrame(res)
return this.browser.switchFrame(res)
}

/**
Expand Down Expand Up @@ -2824,7 +2819,7 @@ async function proceedSeeField(assertType, field, value) {
const fieldResults = toArray(
await forEachAsync(fields, async el => {
const elementId = getElementId(el)
return this.browser.isW3C ? el.getValue() : this.browser.getElementAttribute(elementId, 'value')
return this.browser.getElementAttribute(elementId, 'value')
}),
)

Expand All @@ -2850,15 +2845,21 @@ async function proceedSeeField(assertType, field, value) {
const filterSelectedByValue = async (elements, value) => {
return filterAsync(elements, async el => {
const elementId = getElementId(el)
const currentValue = this.browser.isW3C ? await el.getValue() : await this.browser.getElementAttribute(elementId, 'value')
const currentValue = await this.browser.getElementAttribute(elementId, 'value')
const isSelected = await this.browser.isElementSelected(elementId)
return currentValue === value && isSelected
})
}

const tag = await elem.getTagName()
if (tag === 'select') {
const subOptions = await this.browser.findElementsFromElement(elemId, 'css', 'option')
let subOptions

try {
subOptions = await this.browser.findElementsFromElement(elemId, 'css', 'option')
} catch (e) {
subOptions = await this.browser.findElementsFromElement(elemId, 'xpath', 'option')
}

if (value === '') {
// Don't filter by value
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"test-app:stop": "kill -9 $(lsof -t -i:8000)",
"test:unit:webbapi:playwright": "mocha test/helper/Playwright_test.js",
"test:unit:webbapi:puppeteer": "mocha test/helper/Puppeteer_test.js",
"test:unit:webbapi:webDriver": "mocha test/helper/WebDriver_test.js",
"test:unit:webbapi:webDriver:noSeleniumServer": "mocha test/helper/WebDriver.noSeleniumServer_test.js",
"test:unit:webbapi:webDriver": "mocha test/helper/WebDriver_test.js --timeout 10000",
"test:unit:webbapi:webDriver:noSeleniumServer": "mocha test/helper/WebDriver.noSeleniumServer_test.js --timeout 10000",
"test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js",
"test:unit:expect": "mocha test/helper/Expect_test.js",
"test:plugin": "mocha test/plugin/plugin_test.js",
Expand Down Expand Up @@ -168,7 +168,7 @@
"typedoc-plugin-markdown": "4.4.1",
"typescript": "5.7.2",
"wdio-docker-service": "1.5.0",
"webdriverio": "8.40.6",
"webdriverio": "^9.5.1",
"xml2js": "0.6.2",
"xpath": "0.0.34"
},
Expand Down
12 changes: 6 additions & 6 deletions test/acceptance/codecept.WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const TestHelper = require('../support/TestHelper')

module.exports.config = {
tests: './*_test.js',
timeout: 10000,
timeout: 20,
output: './output',
helpers: {
WebDriver: {
Expand All @@ -11,11 +11,11 @@ module.exports.config = {
host: TestHelper.seleniumHost(),
port: TestHelper.seleniumPort(),
// disableScreenshots: true,
// desiredCapabilities: {
// chromeOptions: {
// args: ['--headless', '--disable-gpu', '--window-size=1280,1024'],
// },
// },
desiredCapabilities: {
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=500,700'],
},
},
},
ScreenshotSessionHelper: {
require: '../support/ScreenshotSessionHelper.js',
Expand Down
24 changes: 12 additions & 12 deletions test/acceptance/session_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const { event } = codeceptjs

Feature('Session')

Scenario('simple session @WebDriverIO @Puppeteer @Playwright', ({ I }) => {
Scenario('simple session @Puppeteer @Playwright', ({ I }) => {
I.amOnPage('/info')
session('john', () => {
I.amOnPage('https://codecept.io/')
I.amOnPage('/login')
I.dontSeeInCurrentUrl('/info')
I.see('CodeceptJS')
I.see('Email')
})
I.dontSee('GitHub')
I.dontSee('Email')
I.seeInCurrentUrl('/info')
})

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

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

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

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

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

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

Scenario('should work with within @WebDriverIO @Puppeteer @Playwright', ({ I }) => {
Scenario('should work with within @Puppeteer @Playwright', ({ I }) => {
I.amOnPage('/form/bug1467')
session('john', () => {
I.amOnPage('/form/bug1467')
Expand Down Expand Up @@ -209,7 +209,7 @@ xScenario('should start firefox', async ({ I }) => {
assert(isChrome)
})

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

Scenario('should return a value @WebDriverIO @Puppeteer @Playwright in async', async ({ I }) => {
Scenario('should return a value @Puppeteer @Playwright in async', async ({ I }) => {
I.amOnPage('/form/textarea')
const val = await session('john', async () => {
I.amOnPage('/info')
Expand Down
2 changes: 1 addition & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ services:
- node_modules:/node_modules

selenium.chrome:
image: selenium/standalone-chrome:3.141.59-oxygen
image: selenium/standalone-chrome:4.26
shm_size: 2g
ports:
- 4444:4444
Expand Down
1 change: 1 addition & 0 deletions test/helper/WebDriver.noSeleniumServer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ describe('WebDriver - No Selenium server started', function () {
})
})


describe('#seeTitleEquals', () => {
it('should check that title is equal to provided one', async () => {
await wd.amOnPage('/')
Expand Down
Loading

0 comments on commit 21b02eb

Please sign in to comment.