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

时间:2014-06-10 09:37:36

标签: javascript selenium-webdriver phantomjs webdriver-io

我正在使用webdriverjs在Windows 8上运行自动化测试。当我将浏览器设置为Chrome时,测试工作正常,但是当我使用PhantomJS时,测试工作正常。当我在OS X Mavericks上运行它们时,相同的测试也能正常工作。

测试不会失败,他们只是无限期地等待。

以下是定义客户端的文件:

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

这是包含我的测试的文件:

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);
  });
});

我在全球安装了mocha,selenium-standalone和phantomjs NPM软件包,并在项目目录中安装了webdriverjs和chai。

我使用start-selenium命令启动selenium,然后使用mocha test.js执行我的测试。

如上所述,测试不会失败,只是等待闪烁的光标,直到我强行退出。

以下是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: {}

1 个答案:

答案 0 :(得分:2)

Ghostdriver需要注册Selenium服务器:

(1)启动Selenium服务器作为集线器:

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

(2)启动phantomjs / ghostdriver并将其注册到selenium服务器

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

如果没有Selenium服务器,有open webdriverjs issue阻止直接使用phantomj。