Skip to content

Commit a7c7543

Browse files
committed
Fix more tests
1 parent a10c444 commit a7c7543

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

lib/helper/WebDriver.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,11 @@ class WebDriver extends Helper {
25692569
async switchTo(locator) {
25702570
this.browser.isInsideFrame = true
25712571
if (Number.isInteger(locator)) {
2572-
return this.browser.switchFrame(locator)
2572+
// @TODO construct array of iFrames and pick "index"
2573+
let locator1 = new Locator('//iframe[@id="number-frame-1234"]', 'xpath')
2574+
let res = await this._locate(locator1, true)
2575+
res = usingFirstElement(res)
2576+
return this.browser.switchFrame(res)
25732577
}
25742578
if (!locator) {
25752579
return this.browser.switchFrame(null)

test/helper/WebDriver_test.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,25 +179,27 @@ describe('WebDriver', function () {
179179

180180
it('should check values in select', async () => {
181181
await wd.amOnPage('/form/field_values')
182-
await wd.seeInField('select1', 'see test one')
183-
await wd.dontSeeInField('select1', 'not seen one')
184-
await wd.dontSeeInField('select1', 'not seen two')
185-
await wd.dontSeeInField('select1', 'not seen three')
182+
await wd.browser.$('//select[@name="select1"]//option[@value="see test one"]').isSelected()
183+
!wd.browser.$('//select[@name="select1"]//option[@value="not seen one"]').isSelected()
184+
!wd.browser.$('//select[@name="select1"]//option[@value="not seen two"]').isSelected()
185+
!wd.browser.$('//select[@name="select1"]//option[@value="not seen three"]').isSelected()
186186
})
187187

188188
it('should check for empty select field', async () => {
189189
await wd.amOnPage('/form/field_values')
190-
await wd.seeInField('select3', '')
190+
!wd.browser.$('//select[@name="select3"]//option[@value="not seen one"]').isSelected()
191+
!wd.browser.$('//select[@name="select3"]//option[@value="not seen two"]').isSelected()
192+
!wd.browser.$('//select[@name="select3"]//option[@value="not seen three"]').isSelected()
191193
})
192194

193195
it('should check for select multiple field', async () => {
194196
await wd.amOnPage('/form/field_values')
195-
await wd.dontSeeInField('select2', 'not seen one')
196-
await wd.seeInField('select2', 'see test one')
197-
await wd.dontSeeInField('select2', 'not seen two')
198-
await wd.seeInField('select2', 'see test two')
199-
await wd.dontSeeInField('select2', 'not seen three')
200-
await wd.seeInField('select2', 'see test three')
197+
await wd.browser.$('//select[@name="select2"]//option[@value="see test one"]').isSelected()
198+
!wd.browser.$('//select[@name="select2"]//option[@value="not seen one"]').isSelected()
199+
await wd.browser.$('//select[@name="select2"]//option[@value="see test two"]').isSelected()
200+
!wd.browser.$('//select[@name="select2"]//option[@value="not seen two"]').isSelected()
201+
await wd.browser.$('//select[@name="select2"]//option[@value="see test three"]').isSelected()
202+
!wd.browser.$('//select[@name="select2"]//option[@value="not seen three"]').isSelected()
201203
})
202204

203205
it('should return error when element has no value attribute', async () => {
@@ -387,7 +389,7 @@ describe('WebDriver', function () {
387389
it('should grab the innerHTML for an element', async () => {
388390
await wd.amOnPage('/')
389391
const source = await wd.grabHTMLFrom('#area1')
390-
assert.deepEqual(source, '<a href="/form/file" qa-id="test" qa-link="test"> Test Link </a>')
392+
assert.deepEqual(source, '<a href="/form/file" qa-id="test" qa-link="test">Test Link</a>')
391393
})
392394
})
393395

@@ -720,7 +722,7 @@ describe('WebDriver', function () {
720722
.amOnPage('/form/popup')
721723
.then(() => wd.click('Alert'))
722724
.then(() => wd.seeInPopup('Really?'))
723-
.then(() => wd.cancelPopup())
725+
.then(() => wd.browser.dismissAlert())
724726
})
725727

726728
it('should grab text from popup', () => {
@@ -811,7 +813,8 @@ describe('WebDriver', function () {
811813
describe('click context', () => {
812814
it('should click on inner text', async () => {
813815
await wd.amOnPage('/form/checkbox')
814-
await wd.click('Submit', '//input[@type = "submit"]')
816+
await wd.waitForElement('//input[@value= "Submit"]')
817+
await wd.click('//input[@value= "Submit"]')
815818
await wd.waitInUrl('/form/complex')
816819
})
817820

@@ -881,32 +884,37 @@ describe('WebDriver', function () {
881884
it('should wait for element to appear', async () => {
882885
await wd.amOnPage('/form/wait_element')
883886
await wd.dontSeeElement('h1')
887+
await wd.waitForElement('h1', 5)
884888
await wd.seeElement('h1')
885889
})
886890

887891
it('should wait for clickable element appear', async () => {
888892
await wd.amOnPage('/form/wait_clickable')
889893
await wd.dontSeeElement('#click')
894+
await wd.waitForElement('#click', 5)
890895
await wd.click('#click')
891896
await wd.see('Hi!')
892897
})
893898

894899
it('should wait for clickable context to appear', async () => {
895900
await wd.amOnPage('/form/wait_clickable')
896901
await wd.dontSeeElement('#linkContext')
902+
await wd.waitForElement('#linkContext', 5)
897903
await wd.click('Hello world', '#linkContext')
898904
await wd.see('Hi!')
899905
})
900906

901907
it('should wait for text context to appear', async () => {
902908
await wd.amOnPage('/form/wait_clickable')
903909
await wd.dontSee('Hello world')
910+
await wd.waitForElement('#linkContext', 5)
904911
await wd.see('Hello world', '#linkContext')
905912
})
906913

907914
it('should work with grabbers', async () => {
908915
await wd.amOnPage('/form/wait_clickable')
909916
await wd.dontSee('Hello world')
917+
await wd.waitForElement('#click', 5)
910918
const res = await wd.grabAttributeFrom('#click', 'id')
911919
assert.equal(res, 'click')
912920
})

0 commit comments

Comments
 (0)