Skip to content

Commit

Permalink
Fixing Regression for chrome stale elements (#3486)
Browse files Browse the repository at this point in the history
## Proposed changes

[//]: # (Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.)

## Types of changes

[//]: # (What types of changes does your code introduce to WebdriverIO?)
[//]: # (_Put an `x` in the boxes that apply_)

- [X] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

## Checklist

[//]: # (_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._)

- [X] I have read the [CONTRIBUTING](https://github.com/webdriverio/webdriverio/blob/master/CONTRIBUTING.md) doc
- [X] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added necessary documentation (if appropriate)

## Further comments

[//]: # (If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...)

### Reviewers: @webdriverio/technical-committee
  • Loading branch information
abjerstedt authored and christian-bromann committed Feb 2, 2019
1 parent 8dba369 commit c40c83f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/webdriver/src/utils.js
Expand Up @@ -316,6 +316,10 @@ export function getErrorFromResponseBody (body) {
export class CustomRequestError extends Error {
constructor(body) {
super(body.value.message || body.value.class || 'unknown error')
if (body.value.error) this.name = body.value.error
if (body.value.error) {
this.name = body.value.error
} else if (body.value.message && body.value.message.includes('stale element reference')) {
this.name = 'stale element reference'
}
}
}
6 changes: 6 additions & 0 deletions packages/webdriver/tests/utils.test.js
Expand Up @@ -232,6 +232,7 @@ describe('utils', () => {
})

it('CustomRequestError', function () {
//Firefox
let error = new CustomRequestError({
value: {
error: 'foo',
Expand All @@ -241,6 +242,11 @@ describe('utils', () => {
expect(error.name).toBe('foo')
expect(error.message).toBe('bar')

//Chrome
error = new CustomRequestError({ value: { message: 'stale element reference'}})
expect(error.name).toBe('stale element reference')
expect(error.message).toBe('stale element reference')

error = new CustomRequestError({ value: { message: 'message' } } )
expect(error.name).toBe('Error')
expect(error.message).toBe('message')
Expand Down

0 comments on commit c40c83f

Please sign in to comment.