我目前正致力于使用WebDriverJs和Mocha为Web应用程序编写一些自动化测试。当我删除与摩卡相关的任何内容时,它运行正常并完全符合我的预期。但是,只要我将mocha元素引入我的代码,Chrome就会打开,但不会加载网址和测试时间。
我正在使用的代码(使用mocha实现)如下:
"use strict";
var assert = require('assert');
var test = require('selenium-webdriver/testing');
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build();
before(function() {
driver.get('http://127.0.0.1:3000/');
});
test.describe('Login', function() {
test.it('should work', function()
{
var passLoginTest = require('./PassLoginTest');
passLoginTest(webdriver, driver).then(function(loggedIn){
assert.isTrue(loggedIn, 'successfully logged in');
});
driver.quit();
});
});
我也尝试在前块之外使用driver.get('http://127.0.0.1:3000/);
,但结果相同。我正在使用Mocha v.2.2.1和Webdriver 2.45.1。
答案 0 :(得分:2)
我也遇到过这种情况,当使用茉莉花代替摩卡时。 我用mocha和selenium-webdriver的版本进行了一些实验。
事实证明selenium webdriver的版本2.43并且有这个问题,下面对我来说效果很好。所以我决定使用最后一个正常的版本。我的package.json现在有
...
"selenium-webdriver": "~2.42.1",
"mocha": "~2.2.4",
...
答案 1 :(得分:0)
You should not be calling $H2
"naked" like you do. You should do like you do with before
and describe
and use the version that is provided by it
so:
selenium-webdriver/testing
The version of these calls provided by test.before(function() {
driver.get('http://127.0.0.1:3000/');
});
are modified to wait for the driver to do its work before moving on. The "stock" (which I called "naked" above) version of these calls would require at a minimum that you return a promise or that you use a callback.