Skip to content

Commit dff8319

Browse files
fix(webdriverio): fix failing e2e tests due to language and timezone differences (webdriverio#14215)
* fix(webdriverio): fix flaky e2e tests due to language and timezone differences * fix: fix more flaky e2e tests * fix: revert some changes * fix: update CONTRIBUTING.md
1 parent e3e8ded commit dff8319

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ You can immediately start working on the code using [a pre-setup Gitpod environm
117117

118118
* Switch to the most recent Node LTS (you should be able to use older/newer versions of Node but we recommend to use v20 LTS so all developers are on the same side) or to the one denoted in `.nvmrc`. We recommend to use [`nvm`](https://github.com/nvm-sh/nvm) to switch between Node.js versions.
119119

120+
* Install Chrome, Firefox and Edge (required for running the e2e tests)
121+
120122
* Set up the project:
121123
First make sure you have the right Node.js version installed.
122124
You can find the current defined development version in `.nvmrc` within the root directory of the project. The easiest way to handle multiple Node.js versions is by using [NVM](https://github.com/nvm-sh/nvm).

e2e/wdio/headless/test.e2e.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -430,25 +430,26 @@ describe('main suite 1', () => {
430430
})
431431

432432
describe('emulate clock', () => {
433-
const now = new Date(2021, 3, 14)
434-
const getDateString = () => (new Date()).toString()
433+
const now = new Date(Date.UTC(2021, 3, 14))
434+
const getDateString = () => new Date()
435+
const mockedDateString = now.toLocaleString('en-GB', { timeZone: 'UTC' })
435436

436437
it('should allow to mock the clock', async () => {
437438
await browser.emulate('clock', { now })
438-
expect(await browser.execute(getDateString))
439-
.toBe(now.toString())
439+
expect((await browser.execute(getDateString)).toLocaleString('en-GB', { timeZone: 'UTC' }))
440+
.toBe(mockedDateString)
440441
await browser.url('https://guinea-pig.webdriver.io')
441-
expect(await browser.execute(getDateString))
442-
.toBe(now.toString())
442+
expect((await browser.execute(getDateString)).toLocaleString('en-GB', { timeZone: 'UTC' }))
443+
.toBe(mockedDateString)
443444
})
444445

445446
it('should allow to restore the clock', async () => {
446447
await browser.restore('clock')
447-
expect(await browser.execute(getDateString))
448-
.not.toBe(now.toString())
448+
expect((await browser.execute(getDateString)).toLocaleString('en-GB', { timeZone: 'UTC' }))
449+
.not.toBe(mockedDateString)
449450
await browser.url('https://guinea-pig.webdriver.io/pointer.html')
450-
expect(await browser.execute(getDateString))
451-
.not.toBe(now.toString())
451+
expect((await browser.execute(getDateString)).toLocaleString('en-GB', { timeZone: 'UTC' }))
452+
.not.toBe(mockedDateString)
452453
})
453454
})
454455

@@ -514,7 +515,7 @@ describe('main suite 1', () => {
514515
await browser.switchToWindow(handles[1])
515516

516517
// Verify element text to ensure the browsing context has changed and can interact with elements
517-
await expect(await $('.page').getText()).toBe('Second page!')
518+
await expect($('.page')).toHaveText('Second page!')
518519
})
519520

520521
it('should see that content is no longer displayed when window is closed', async () => {
@@ -675,8 +676,8 @@ describe('main suite 1', () => {
675676
})
676677

677678
it('chrome', async () => {
678-
await browser.url('chrome://version/')
679-
await expect(browser).toHaveTitle('About Version')
679+
await browser.url('chrome://about/')
680+
await expect($('li=chrome://accessibility')).toExist()
680681
})
681682
})
682683

0 commit comments

Comments
 (0)