使用phantomjs浏览器运行量角器时,只能运行一次测试

时间:2022-10-07 01:23:40

test code:

测试代码:

describe('mysite', function(){

describe('mysite',function(){

var init_url = 'http://localhost/mySite/#/home';
beforeEach(function(){
    // driver = new webdriver.Builder().
    // withCapabilities(webdriver.Capabilities.phantomjs()).build();
})


it('should click on toolbox and do stuff', function(){
    browser.get(init_url);
    browser.waitForAngular();
    browser.getCurrentUrl().then(function(url){
        console.log('current_url', url);
        expect(init_url).toEqual(init_url);
    })
    expect(true).toBe(true);
    browser.sleep(2000);
})

result 1st time run,

结果第一次运行,

Using the selenium server at http://localhost:9515
data Zoom Pad
class active

mysite
    should click on toolbox and do stuff

Finished in 3.94 seconds
1 test, 4 assertions, 0 failures

2nd time run, without any interruption, just up arrow and enter:

第二次运行,没有任何中断,只需向上箭头并输入:

   Stacktrace:
     Error: Error while running testForAngular: Error Message => 'Detected a pag
e unload event; asynchronous script execution does not work across page loads.'
 caused by Request => {"headers":{"Accept":"application/json; charset=utf-8","Co
nnection":"keep-alive","Content-Length":"689","Content-Type":"application/json;c
harset=UTF-8","Host":"localhost:9515"},"httpVersion":"1.1","method":"POST","post
":"{\"script\":\"return (function () {\\n  var attempts = arguments[0];\\n  var
callback = arguments[arguments.length - 1];\\n  var check = function(n) {\\n
try {\\n      if (window.angular && window.angular.resumeBootstrap) {\\n
callback([true, null]);\\n      } else if (n < 1) {\\n        if (window.angular
) {\\n          callback([false, 'angular never provided resumeBootstrap']);\\n
       } else {\\n          callback([false, 'retries looking for angular exceed

third time

第三次

  1) mysite should click on toolbox and do stuff
   Message:
     Error: ECONNREFUSED connect ECONNREFUSED
   Stacktrace:
     Error: ECONNREFUSED connect ECONNREFUSED
    at ClientRequest.<anonymous> (K:\Users\Congwen\AppData\Roaming\npm\node_modu
les\protractor\node_modules\selenium-webdriver\http\index.js:127:16)
    at ClientRequest.EventEmitter.emit (events.js:95:17)
    at Socket.socketErrorListener (http.js:1547:9)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:441:14

and on third time the phantomjs webserver is down, and needs to be reconnected, and afterwards it goes back to result 1:

第三次,phantomjs webserver关闭,需要重新连接,然后返回结果1:

any clues?

任何线索?

config file used:

使用的配置文件:

 exports.config = {
     seleniumAddress: 'http://localhost:9515',
     specs: [
         './ptor-tests/mysite-test.js'
     ],
     capabilities: {
         browserName: 'phantomjs',
         version: '',
         platform: 'ANY'
     },
     //baseUrl: 'http://testapp.example.com/index.html',
     rootElement: 'body',
     allScriptsTimeout: 11000,
     onPrepare: function () {},
     jasmineNodeOpts: {
         onComplete: function () {},
         isVerbose: true,
         showColors: true,
         includeStackTrace: true,
         defaultTimeoutInterval: 30000
     }
 };

also I noticed that sometimes there's no step 2 needed and it will go directly to ECONNECT error, and sometimes it gets stuck in step 2 for a number of tests and eventually will terminate phantomjs server.

另外我注意到有时候不需要第2步,它会直接转到ECONNECT错误,有时它会在第2步中遇到大量测试,并最终终止phantomjs服务器。

1 个解决方案

#1


7  

This is an issue with Protractor that was resolved in version 0.17 and made better in 0.18.

这是Protractor的一个问题,它在0.17版本中得到了解决,在0.18中更好。

It's a bug with a long tail, but the TL;DR is that Protractor's .get(url) function actually uses client-side JavaScript to make the location change; this is to ensure it properly bootstraps. An unfortunate side effect of that design is that for some reason, PhantomJS takes a few seconds to navigate over properly.

这是一个长尾的错误,但TL; DR是Protractor的.get(url)函数实际上使用客户端JavaScript来改变位置;这是为了确保它正确引导。该设计的一个不幸的副作用是,由于某种原因,PhantomJS需要几秒钟才能正确导航。

The bug was resolved by adding a longer timeout to the .get function.

通过向.get函数添加更长的超时来解决该错误。

Github Issue: https://github.com/angular/protractor/issues/85

Github问题:https://github.com/angular/protractor/issues/85

Relevant changelog entries:

相关的更改日志条目:

v0.18

(10aec0f) fix(pageload): increase wait timeout

(10aec0f)fix(pageload):增加等待超时

The 300 ms wait caused problems when testing IE on Sauce Labs. It seems way too short. "browser.get()" invariably timed out. Increasing it solved our problem.

在Sauce Labs上测试IE时,300毫秒等待会导致问题。这似乎太短了。 “browser.get()”总是超时。增加它解决了我们的问题。

v0.17

(a0bd84b) fix(pageload): add a wait during protractor.get() to solve unload issues

(a0bd84b)fix(pageload):在protractor.get()期间添加一个等待来解决卸载问题

Some systems would not wait for the browser unload event to finish before beginning the asynchronous script execution.

在开始异步脚本执行之前,某些系统不会等待浏览器卸载事件完成。

Closes #406. Closes #85.

关闭#406。关闭#85。

I've run your test locally (with a different page, but otherwise the same code):

我在本地运行您的测试(使用不同的页面,但其他代码相同):

使用phantomjs浏览器运行量角器时,只能运行一次测试

Happy testing!

快乐的测试!

#1


7  

This is an issue with Protractor that was resolved in version 0.17 and made better in 0.18.

这是Protractor的一个问题,它在0.17版本中得到了解决,在0.18中更好。

It's a bug with a long tail, but the TL;DR is that Protractor's .get(url) function actually uses client-side JavaScript to make the location change; this is to ensure it properly bootstraps. An unfortunate side effect of that design is that for some reason, PhantomJS takes a few seconds to navigate over properly.

这是一个长尾的错误,但TL; DR是Protractor的.get(url)函数实际上使用客户端JavaScript来改变位置;这是为了确保它正确引导。该设计的一个不幸的副作用是,由于某种原因,PhantomJS需要几秒钟才能正确导航。

The bug was resolved by adding a longer timeout to the .get function.

通过向.get函数添加更长的超时来解决该错误。

Github Issue: https://github.com/angular/protractor/issues/85

Github问题:https://github.com/angular/protractor/issues/85

Relevant changelog entries:

相关的更改日志条目:

v0.18

(10aec0f) fix(pageload): increase wait timeout

(10aec0f)fix(pageload):增加等待超时

The 300 ms wait caused problems when testing IE on Sauce Labs. It seems way too short. "browser.get()" invariably timed out. Increasing it solved our problem.

在Sauce Labs上测试IE时,300毫秒等待会导致问题。这似乎太短了。 “browser.get()”总是超时。增加它解决了我们的问题。

v0.17

(a0bd84b) fix(pageload): add a wait during protractor.get() to solve unload issues

(a0bd84b)fix(pageload):在protractor.get()期间添加一个等待来解决卸载问题

Some systems would not wait for the browser unload event to finish before beginning the asynchronous script execution.

在开始异步脚本执行之前,某些系统不会等待浏览器卸载事件完成。

Closes #406. Closes #85.

关闭#406。关闭#85。

I've run your test locally (with a different page, but otherwise the same code):

我在本地运行您的测试(使用不同的页面,但其他代码相同):

使用phantomjs浏览器运行量角器时,只能运行一次测试

Happy testing!

快乐的测试!