Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(jasminewd): better error messaging when expect is called with a …
Browse files Browse the repository at this point in the history
…WebElement

Previously, using expect() with a web element would cause the webdriver
jasmine adapter to go into an infinite loop trying to resolve the promise,
since WebElement inherits from Promise but resolves to itself. Now
throws a more readable error.

Closes #178.
  • Loading branch information
juliemr committed Oct 30, 2013
1 parent a199bb4 commit 201b59c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jasminewd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ originalExpect = global.expect;

global.expect = function(actual) {
if (actual instanceof webdriver.promise.Promise) {
if (actual instanceof webdriver.WebElement) {
throw 'expect called with WebElement argment, expected a Promise. ' +
'Did you mean to use .getText()?';
}
return promiseMatchers(actual);
} else {
return originalExpect(actual);
Expand Down
11 changes: 11 additions & 0 deletions jasminewd/spec/adapterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ var webdriver = require('selenium-webdriver');
var getFakeDriver = function() {
var flow = webdriver.promise.controlFlow();
return {
controlFlow: function() {
return flow;
},
sleep: function(ms) {
return flow.timeout(ms);
},
Expand Down Expand Up @@ -108,6 +111,14 @@ describe('webdriverJS Jasmine adapter', function() {
expect(fakeDriver.getBigNumber()).toBeLotsMoreThan(33);
});

it('should throw an error with a WebElement actual value', function() {
var webElement = new webdriver.WebElement(fakeDriver, 'idstring');

expect(function() {
expect(webElement).toEqual(4);
}).toThrow('expect called with WebElement argment, expected a Promise. ' +
'Did you mean to use .getText()?');
});

// Uncomment to see timeout failures.
// it('should timeout after 200ms', function() {
Expand Down

0 comments on commit 201b59c

Please sign in to comment.