Skip to content

Commit

Permalink
Don't crash when webdriverio.getAttribute returns an array of null
Browse files Browse the repository at this point in the history
  • Loading branch information
NiGhTTraX committed Jan 13, 2017
1 parent 2676a8d commit 7e4abef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ let isElementsResult = function (result) {
}

let is$$Result = function (result) {
return Array.isArray(result) && result.length && result[0].ELEMENT !== undefined
// Commands like getAttribute can return an array of null when the attribute
// is not set.
return Array.isArray(result) && result.length && result[0] && result[0].ELEMENT !== undefined
}

/**
Expand Down
9 changes: 9 additions & 0 deletions test/wrapCommand.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ WebdriverIO.prototype = {
getNull: (ms = 50) => new Promise((r) => {
setTimeout(() => r(null), ms)
}),
getNulls: (ms = 50) => new Promise((r) => {
setTimeout(() => r([null, null]), ms)
}),
waitUntilSync: (fn) => new Promise((r) => {
return wdioSync(fn, r)()
})
Expand Down Expand Up @@ -84,6 +87,12 @@ describe('wrapCommand', () => {
})
})

it('should not treat an array of null as a $$ result', () => {
return run(() => {
instance.getNulls().should.be.deepEqual([null, null])
})
})

after(() => {
delete global.browser
})
Expand Down

0 comments on commit 7e4abef

Please sign in to comment.