Nightwatch, afterEach, browser.pause is not a function

早过忘川 提交于 2020-01-03 17:09:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!