Problem with steps counter
Closed this issue · 9 comments
If test fails with timeout, first then
section of next test will be skipped.
describe('Google searching', function() {
before(function() {
casper.start('http://www.google.com/')
})
it('Expect #qwerty element', function() {
casper.waitForSelector('#qwerty')
})
it('Expect body element', function() {
casper.then(function() {
console.log('THEN 1')
});
casper.then(function() {
console.log('THEN 2')
})
casper.then(function() {
console.log('THEN 3')
})
})
})
Result in console:
Google searching
1) Expect #qwerty element
THEN 2
THEN 3
✓ Expect body element (61ms)
1 passing (6s)
1 failing
1) Google searching Expect #qwerty element:
"#qwerty" still did not exist 5000ms
Is it a bug? Or I'm doing something wrong? I think, it's problem with steps counter, because if I remove line 51 in node_modules/mocha-casperjs/mocha-casperjs.js
, all then
sections are running.
https://github.com/nathanboktae/mocha-casperjs/blob/master/mocha-casperjs.js#L51
Google searching
1) Expect #qwerty element
THEN 1
THEN 2
THEN 3
✓ Expect body element (81ms)
1 passing (16s)
1 failing
1) Google searching Expect #qwerty element:
"#qwerty" still did not exist 5000ms
You always need to wrap Casper logic in a step. waitForSelector
needs to be in a casper.then
. otherwise mocha sees that as synchronous and succeeds.
The step counter is a critical piece to how mocha-casperjs
works. If you had real logic in there you would see race conditions everywhere removing it.
Sorry, but on the main page of mocha-casperjs I see such example:
describe('Google searching', function() {
before(function() {
casper.start('http://www.google.fr/')
})
it('should retrieve 10 or more results', function() {
casper.then(function() {
'Google'.should.matchTitle
'form[action="/search"]'.should.be.inDOM.and.be.visible
this.fill('form[action="/search"]', {
q: 'casperjs'
}, true)
})
casper.waitForUrl(/q=casperjs/, function() {
(/casperjs/).should.matchTitle
})
})
})
I see waitForUrl
outside of casper.then
section. Is it a bug in documentation?
waitForSelector
calls waitFor internally and waitFor creates separate step, so I think it is not necessary to put waitForSelector
into casper.then
Ah ok, yeah that incrementing of the step counter came in with #56. Did casper functionality change since 1.1.0-beta3? what version of casperjs are you on? It could be if casper moves on to the next step after timeouts now automatically.
I wrap waitForSelector
in a step:
casper.then(function() {
casper.waitForSelector('#qwerty')
})
The result is the same. Version of casperjs is 1.1.3
, mocha - 3.2.0
, mocha-casperjs - 0.5.8
.
I agree with you I think it's a bug and removing those lines make sense. Would you mind to submit a PR with this test case too?
Yes. I'll do it this weekend.