I keep getting this error at:
search.waitForElementVisible('@headerTitle', client.globals.waitForTiming);
search.expect.element('@headerTitle').text.to.contain('Miami');
Error:
TypeError: this.resultValue.indexOf is not a function
at TextAssertion.<anonymous> (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/api/expect/_baseAssertion.js:218:48)
at TextAssertion.BaseAssertion.getResult (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/api/expect/_baseAssertion.js:182:19)
at TextAssertion.BaseAssertion.conditionFlag (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/api/expect/_baseAssertion.js:258:22)
at TextAssertion.BaseAssertion.@containsFlag (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/api/expect/_baseAssertion.js:217:8)
at TextAssertion.<anonymous> (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/api/expect/_baseAssertion.js:144:33)
at Array.forEach (native)
at TextAssertion.BaseAssertion.processFlags (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/api/expect/_baseAssertion.js:140:30)
at TextAssertion.<anonymous> (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/api/expect/_baseAssertion.js:112:10)
at HttpRequest.<anonymous> (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/index.js:339:20)
at emitTwo (events.js:100:13)
at HttpRequest.emit (events.js:185:7)
at HttpRequest.<anonymous> (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/index.js:378:15)
at emitThree (events.js:110:13)
at HttpRequest.emit (events.js:188:7)
at IncomingMessage.<anonymous> (/home/travis/build/gadabout/sparrow/node_modules/nightwatch/lib/http/request.js:157:16)
at emitNone (events.js:85:20)
at IncomingMessage.emit (events.js:179:7)
at endReadableNT (_stream_readable.js:906:12)
at nextTickCallbackWith2Args (node.js:475:9)
at process._tickDomainCallback (node.js:430:17)
What is happening is that I have an ajax request which updates the dom right when the test is running and throws an error. Adding pause solved it
Can you give us some more details on how to reproduce this? A verbose log snippet would also help.
@beatfactor I think that is happening is that selenium is looking for an element that changed slightly (for example, an ajax request that updated the DOM, perhaps the elements around the element I want to do something to it that throws this error).
Is there any problem with incorporating my fix from #862? It's a simple change that prevents the crash for me.
As I stated above, I need more info on how to reproduce the issue. Your verbose log output might also help.
Is the HTML and JS that fastman posted in #862 not sufficient for you to reproduce the problem?
I'm facing a similar problem. I'm using nightwatch to test locally and some online environments.
When I run my tests on local I got everything working fine. Once I run the task in jenkins it gets stuck and throws me the error:
✔ Expected element <h3.title-orange> text to not equal: "$0.00 COP" - condition was met in 99ms
✖ TypeError: this.resultValue.indexOf is not a function
at Array.forEach (native)
Departure date set to: 2016-09-20
Returning date set to: 2016-09-25
FAILED: 1 errors and 3 passed (6.312s)
✖ TypeError: this.resultValue.indexOf is not a function
at Array.forEach (native)
✖ TypeError: this.resultValue.indexOf is not a function
at Array.forEach (native)
✖ Expected element <h1> to have css property "ng-binding" contain: "My Dashboard" - expected "contain 'My Dashboard'" but got: "null"
My specific case is happening somewhere in this code:
browser
.waitForElementPresent('select[id=currencySelector]', 10000)
.click('select[id=currencySelector] option[value=COP]');
browser.pause(3000);
switch (browser.currentTest.name){
case 'Enough balance':
browser.expect.element('h3.title-orange')
.text.to.not.equal('$0.00 COP').before(10000);
break;
case 'Enough balance':
browser.expect.element('h3.title-orange')
.text.to.contain('$0.00 COP').before(10000);
break;
default:
console.error('You shouldnt be here');
}
browser
.url(browser.globals.host)
.pause(1000)
.refresh()
.maximizeWindow();
// Expect body to be present within 1000 ms
browser.expect.element('body').to.be.present.before(5000);
// Giving starting values
var now = new Date();
var departure = new Date();
var returning = new Date();
departure.setDate(now.getDate() + 15);
returning.setDate(now.getDate() + 20);
// Check departure and returning dates in ISO format
console.info("Departure date set to: " + departure.toCustomISO());
console.info("Returning date set to: " + returning.toCustomISO());
// Set values for fields
browser.setValue('input[name=inputOrigin]', 'Bogota'); // HERE IS WHERE I THINK IT FAILS
browser.pause(1000);
The phantomjs log throws me this:
[INFO - 2016-09-05T20:03:39.872Z] Session [d69a2ab0-73a3-11e6-bbe2-fd01809cf57f] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"},"phantomjs.page.settings.userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1"}
[INFO - 2016-09-05T20:03:39.872Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: d69a2ab0-73a3-11e6-bbe2-fd01809cf57f
[ERROR - 2016-09-05T20:03:40.049Z] Session [d69a2ab0-73a3-11e6-bbe2-fd01809cf57f] - page.onError - msg: Error: Script error for "reCaptcha", needed by: mainModule
http://requirejs.org/docs/errors.html#scripterror
[ERROR - 2016-09-05T20:03:40.049Z] Session [d69a2ab0-73a3-11e6-bbe2-fd01809cf57f] - page.onError - stack:
defaultOnError (http://dev.mysite.com/components/requirejs/require.js:143)
onError (http://dev.mysite.com/components/requirejs/require.js:547)
onScriptError (http://dev.mysite.com/components/requirejs/require.js:1735)
[ERROR - 2016-09-05T20:03:40.049Z] Session [d69a2ab0-73a3-11e6-bbe2-fd01809cf57f] - page.onError - msg: Error: Script error for "ngResource", needed by: undertrailApis, mainModule
And it keeps going with angular dependencies errors
I'm facing a similar issue here…
Error:
TypeError: this.resultValue.indexOf is not a function
at Array.forEach (native)
It is a little bit weird, because it only happens when I'm doing two assertions instead of one. Here some pseudo-code:
function filterApply() {
pageObject
.clickFilterButton()
.verifyFilterButtonDisabled()
.selectCategoryFilter(filterValue);
filterForm = pageObject.section.filterForm;
// #1
filterForm.expect.element(`@appliedFilters`).text.to.contain(filterName);
}
function filterChange() {
pageObject
.selectCategoryFilter(filterValue);
// #2
filterForm.expect.element(`@appliedFilters`).text.to.contain(filterName).after(timeoutDefault);
}
When I remove #1 OR #2, I don't have any issue… both assertions are working as expected. When I try using both of them in my test suite, I receive the error above. That's why I started looking into the verbose logs, where I saw this beauty at the second assertion:
ERROR Response 500 GET
/wd/hub/session/8fd28034-ae9c-4403-adb1-5cd99fafecc3/element/4/text (1021ms)
{ state: 'stale element reference',
My assumption right now is that the error happens, because the page-object I'm using is storing a reference to the element on my first assertion. But the DOM element in my test get's destroyed and replaced by another one, therefore the _cached reference is invalid_ and the error is thrown.
Any thoughts on that one?
Edit:
I found a possible workaround in my case:
function filterApply() {
pageObject
.clickFilterButton()
.verifyFilterButtonDisabled()
.selectCategoryFilter(filterValue);
filterForm = pageObject.section.filterForm;
// #1
filterForm.expect.element(`@appliedFilters`).text.to.contain(filterName);
}
function filterChange() {
pageObject
.selectCategoryFilter(filterValue)
.api.pause(5000)
// #2
.expect.element(`css selector`).text.to.contain(filterName);
}
Making a hard pause before is the only way to get it working :/
I was able to "fix" it. The fix was on my code. After several attempts to see where the problem was I managed to locate the problem and fix it.
Before I had this:
browser.expect.element('h1')
.to.have.css('text-center')
.to.have.css('title-orange')
.to.have.css('ng-binding')
.text.to.contain('My Dashboard').before(10000);
So I replaced that with this:
browser.expect.element('h1').before(10000);
browser.expect.element('h1').to.have.css('text-center');
browser.expect.element('h1').to.have.css('title-orange');
browser.expect.element('h1').to.have.css('ng-binding');
browser.expect.element('h1').text.to.contain('My Dashboard').before(10000);
That worked in my case.
use text.to.equal instead of contain
Issue still not fixed, but even stated in the API docs 👎
http://nightwatchjs.org/api#expect-before
Minimum working example to reproduce:
module.exports = {
'Configuration process': (client: any): void => {
// Carline page
client.url('https://www.volkswagen.es/app/configurador/vw-es/es');
client.expect.element('body').to.be.present.before(1000);
client.expect.element('.car-list').to.be.present;
client.expect.element('.headline--3').text.to.equal('Configura tu Volkswagen.');
client.assert.title('VW Configurador - Volkswagen España');
client.click('.car-list .car-tile:nth-of-type(3) a');
// Trim page
client.expect.element('.car-list').to.be.present;
client.expect.element('.headline--3').text.to.contain('Selecciona una versión de equipamiento para tu Polo').after(1000); // error here
client.assert.title('Configurador VW Polo');
client.end();
}
};
Try using .before() instead of .after()
Same result with .before()
I've added an explicit wait, but dislike this kind of approach since wasting a fixed amount of time versus the retry behavior of the .before() / .after() makes tests slower.
I'm getting the same behavior.
Me too. Never on the local machine, but in exactly the same circumstances when running on a CI server. (The error appears when repeatedly using an element(...).text.to.contain(...) test.)
Getting the same error (and others) running tests with WebdriverIO on Selenium Docker. No errors locally. Error seems to come from Chai
Has there been any headway on this? I've been running into this issue while running selenium/standalone-firefox on selenium version 3.8.1
Ditto. Flaky CI is a real pain
FYIs, after adding a bit more debugging stuff, it seems that this is what nightwatch is getting instead of a string in the contains assertion:
Expected a string, but got: {"message":"java.net.SocketException: Connection reset by peer (connect failed)","error":"unknown error"}
This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contributions.
Most helpful comment
Me too. Never on the local machine, but in exactly the same circumstances when running on a CI server. (The error appears when repeatedly using an
element(...).text.to.contain(...)test.)