我正在使用 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
.
如前所述,测试不会失败,它只是等待闪烁的光标,直到我强制它退出。
这是硒的输出:
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: {}