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

Commit 201b59c

Browse files
committed
feat(jasminewd): better error messaging when expect is called with a 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.
1 parent a199bb4 commit 201b59c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

jasminewd/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ originalExpect = global.expect;
104104

105105
global.expect = function(actual) {
106106
if (actual instanceof webdriver.promise.Promise) {
107+
if (actual instanceof webdriver.WebElement) {
108+
throw 'expect called with WebElement argment, expected a Promise. ' +
109+
'Did you mean to use .getText()?';
110+
}
107111
return promiseMatchers(actual);
108112
} else {
109113
return originalExpect(actual);

jasminewd/spec/adapterSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ var webdriver = require('selenium-webdriver');
1010
var getFakeDriver = function() {
1111
var flow = webdriver.promise.controlFlow();
1212
return {
13+
controlFlow: function() {
14+
return flow;
15+
},
1316
sleep: function(ms) {
1417
return flow.timeout(ms);
1518
},
@@ -108,6 +111,14 @@ describe('webdriverJS Jasmine adapter', function() {
108111
expect(fakeDriver.getBigNumber()).toBeLotsMoreThan(33);
109112
});
110113

114+
it('should throw an error with a WebElement actual value', function() {
115+
var webElement = new webdriver.WebElement(fakeDriver, 'idstring');
116+
117+
expect(function() {
118+
expect(webElement).toEqual(4);
119+
}).toThrow('expect called with WebElement argment, expected a Promise. ' +
120+
'Did you mean to use .getText()?');
121+
});
111122

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

0 commit comments

Comments
 (0)