简体   繁体   English

在Windows上使用PhantomJS时,We​​bdriverJS测试会挂起

[英]WebdriverJS tests hang when using PhantomJS on Windows

I'm using webdriverjs to run automated tests on Windows 8. The tests work correctly when I set the browser to Chrome but not when I use PhantomJS. 我正在使用webdriverjs在Windows 8上运行自动化测试。当我将浏览器设置为Chrome时,测试工作正常,但是当我使用PhantomJS时,测试工作正常。 The same tests also work correctly when I run them on OS X Mavericks. 当我在OS X Mavericks上运行它们时,相同的测试也能正常工作。

The tests don't fail, they just wait indefinitely. 测试不会失败,他们只是无限期地等待。

Here is the file where the client is defined: 这是定义客户端的文件:

exports.client = require('webdriverjs').remote({
  desiredCapabilities: {
    browserName: 'phantomjs'
  }
});

Here is the file containing my test: 这是包含我的测试的文件:

var chai        = require('chai'),
    assert      = chai.assert,
    expect      = chai.expect,
    webdriverjs = require('webdriverjs'),
    client      = require('./client').client;

describe('my webdriverjs tests', function(){

  this.timeout(10000);

  before(function(done){
    client.init(done);
  });

  it('Github test',function(done) {
    client
      .url('https://github.com/')
      .getElementSize('.header-logo-wordmark', function(err, result) {
        assert.equal(null, err);
        assert.strictEqual(result.height , 32);
        assert.strictEqual(result.width, 89);
      })
      .getTitle(function(err, title) {
        assert.equal(null, err);
        assert.strictEqual(title,'GitHub · Build software better, together.');
      })
      .getCssProperty('a[href="/plans"]', 'color', function(err, result){
        assert.equal(null, err);
        assert.strictEqual(result, 'rgba(65,131,196,1)');
      })
      .call(done);
  });

  after(function(done) {
    client.end(done);
  });
});

I have the mocha, selenium-standalone and phantomjs NPM packages installed globally, with webdriverjs and chai installed in the project directory. 我在全球安装了mocha,selenium-standalone和phantomjs NPM软件包,并在项目目录中安装了webdriverjs和chai。

I start selenium using the start-selenium command and then execute my test using mocha test.js . 我使用start-selenium命令start-selenium ,然后使用mocha test.js执行我的测试。

As mentioned, the test doesn't fail, it just waits with a blinking cursor until I force it to exit. 如上所述,测试不会失败,只是等待闪烁的光标,直到我强行退出。

Here is the output from selenium: 这是硒的输出:

c:\Code\cie-teacher-support-portal-web\src\CIE.TeacherSupportPortal.Web>start-selenium
Jun 10, 2014 10:33:18 AM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
Setting system property webdriver.chrome.driver to C:\Users\Alex Cason\AppData\Roaming\npm\node_modules\selenium-standalone\.selenium\2.42.0\chromedriver
10:33:18.788 INFO - Java: Oracle Corporation 21.0-b17
10:33:18.789 INFO - OS: Windows NT (unknown) 6.2 amd64
10:33:18.820 INFO - v2.42.0, with Core v2.42.0. Built from revision 5e82430
10:33:18.935 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
10:33:18.937 INFO - Version Jetty/5.1.x
10:33:18.937 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
10:33:18.938 INFO - Started HttpContext[/selenium-server,/selenium-server]
10:33:18.938 INFO - Started HttpContext[/,/]
10:33:18.983 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@4672b784
10:33:18.983 INFO - Started HttpContext[/wd,/wd]
10:33:18.986 INFO - Started SocketListener on 0.0.0.0:4444
10:33:18.986 INFO - Started org.openqa.jetty.jetty.Server@3bba1558
10:33:25.692 INFO - Executing: [new session: Capabilities [{platform=ANY, javascriptEnabled=true, browserName=phantomjs, version=}]])
10:33:25.707 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=true, browserName=phantomjs, version=}]
10:33:25.721 INFO - executable: C:\Users\Alex Cason\AppData\Roaming\npm\phantomjs
10:33:25.722 INFO - port: 32714
10:33:25.722 INFO - arguments: [--webdriver=32714, --webdriver-logfile=c:\Code\cie-teacher-support-portal-web\src\CIE.TeacherSupportPortal.Web\phantomjsdriver.log]
10:33:25.723 INFO - environment: {}

Ghostdriver needs to register with the Selenium server: Ghostdriver需要注册Selenium服务器:

(1) start the Selenium server as a hub: (1)启动Selenium服务器作为集线器:

java -jar selenium-server-standalone-2.42.2.jar -role hub

(2) start phantomjs/ghostdriver and register it with the selenium server (2)启动phantomjs / ghostdriver并将其注册到selenium服务器

phantomjs --webdriver=4445 --webdriver-selenium-grid-hub=http://127.0.0.1:4444

There is an open webdriverjs issue preventing direct use of phantomjs without the Selenium server. 有一个开放的webdriverjs问题阻止在没有Selenium服务器的情况下直接使用phantomjs。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM