Skip to content

Commit a531971

Browse files
committed
try to fix some wdio tests
1 parent 261a22c commit a531971

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

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: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -2521,7 +2519,7 @@ class WebDriver extends Helper {
25212519
let res = await this._locate(locator, true)
25222520
assertElementExists(res, locator)
25232521
res = usingFirstElement(res)
2524-
return this.browser.switchFrame(res)
2522+
return this.browser.switchFrame(res.elementId)
25252523
}
25262524

25272525
/**
@@ -2821,7 +2819,7 @@ async function proceedSeeField(assertType, field, value) {
28212819
const fieldResults = toArray(
28222820
await forEachAsync(fields, async el => {
28232821
const elementId = getElementId(el)
2824-
return this.browser.isW3C ? el.getValue() : this.browser.getElementAttribute(elementId, 'value')
2822+
return this.browser.getElementAttribute(elementId, 'value')
28252823
}),
28262824
)
28272825

@@ -2847,15 +2845,21 @@ async function proceedSeeField(assertType, field, value) {
28472845
const filterSelectedByValue = async (elements, value) => {
28482846
return filterAsync(elements, async el => {
28492847
const elementId = getElementId(el)
2850-
const currentValue = this.browser.isW3C ? await el.getValue() : await this.browser.getElementAttribute(elementId, 'value')
2848+
const currentValue = await this.browser.getElementAttribute(elementId, 'value')
28512849
const isSelected = await this.browser.isElementSelected(elementId)
28522850
return currentValue === value && isSelected
28532851
})
28542852
}
28552853

28562854
const tag = await elem.getTagName()
28572855
if (tag === 'select') {
2858-
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+
}
28592863

28602864
if (value === '') {
28612865
// Don't filter by value

test/helper/WebDriver_test.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ describe('WebDriver', function () {
198198
await wd.seeInField('select2', 'see test three')
199199
})
200200

201-
202201
it('should return error when element has no value attribute', async () => {
203202
await wd.amOnPage('https://codecept.io/quickstart')
204203

@@ -386,16 +385,10 @@ describe('WebDriver', function () {
386385
it('should grab the innerHTML for an element', async () => {
387386
await wd.amOnPage('/')
388387
const source = await wd.grabHTMLFrom('#area1')
389-
assert.deepEqual(
390-
source,
391-
`
392-
<a href="/form/file" qa-id="test" qa-link="test"> Test Link </a>
393-
`,
394-
)
388+
assert.deepEqual(source, '<a href="/form/file" qa-id="test" qa-link="test">Test Link</a>')
395389
})
396390
})
397391

398-
399392
describe('#seeTitleEquals', () => {
400393
it('should check that title is equal to provided one', async () => {
401394
await wd.amOnPage('/')
@@ -794,7 +787,7 @@ describe('WebDriver', function () {
794787
await wd.switchTo('h1')
795788
} catch (e) {
796789
e.should.be.instanceOf(Error)
797-
e.message.should.contain('no such frame')
790+
e.message.should.contain('No frame')
798791
}
799792
})
800793

0 commit comments

Comments
 (0)