问题
I would like to make pause each test. I've create this function:
afterEach:function(browser){
browser.pause(2000);
},
But when I run tests, I will get error:
TypeError: browser.pause is not a function
Why ? In tests browser.pause is function.
回答1:
The answer, provided by beatfactor, on the linked GitHub issue, is
When using afterEach you need to use the done callback argument always if you want to use the browser object. That is for backwards compatibility. So you need to do either:
afterEach(browser, done) {
// ...
done();
}
回答2:
I've written on GitHub as issue and I've got a solution: https://github.com/nightwatchjs/nightwatch/issues/921
RESOLVE:
use
afterEach(done) {
// ...
done();
}
instead of
afterEach(browser, done) {
// ...
done();
}
回答3:
When using afterEach
, if you want access to the browser
object then you need to add the done
callback argument after browser
to your function.
So your function should look like this:
afterEach(browser, done) {
// ...
done();
}
Note that you have to call done()
to signify the completion of the test.
If you only have one argument in afterEach
then it's the done
argument.
afterEach(done) {
// ...
done();
}
In other words, if you write
afterEach(browser) {
// ...
}
browser
is actually the done
callback. You've named it browser but that's not what it is.
回答4:
My dear friend you have to do "something" and then pause! (i.e. assert the url and then pause!)
Does it works?
afterEach:function(browser){ browser .assert.urlEquals('http://www.google.com') .pause(2000) },
来源:https://stackoverflow.com/questions/36309656/nightwatch-aftereach-browser-pause-is-not-a-function