我正在尝试使用测试运行器(CucumberJS)来利用selenium来运行测试套件。 Selenium设置为每个新方案启动一个新的浏览器会话。世界代码如下所示:
'use strict'
const webdriver = require('selenium-webdriver')
class World {
constructor(browser) {
this.browser = browser
}
cleanUp(callback) {
this.browser.quit().then(callback)
}
}
exports.World = function(callback) {
const browser = new webdriver.Builder()
.usingServer('http://localhost:4444/wd/hub')
.withCapabilities(webdriver.Capabilities.chrome())
.build()
const timeouts = browser.manage().timeouts()
timeouts.pageLoadTimeout(10000)
timeouts.setScriptTimeout(5000)
timeouts.implicitlyWait(1000)
const world = new World(browser)
callback(world)
}
这是步骤定义
function stepDefinitions() {
this.World = require('../support/world').World
this.Given(/^I am on the dashboard page for game (\d+)$/, function (id, callback) {
this.dashboard = new Dashboard(this.browser)
this.dashboard.viewGame(id).then(callback)
})
this.After(function(callback) {
this.cleanUp(callback)
})
}
我正在使用场景大纲,因此上面的步骤定义会执行两次。我目前只编写了这一步定义,以便编写最少的必要代码。
正在发生的事情是:在第一个场景大纲中,这非常有效。加载页面,selenium终止它自己,辉煌。但是在第二个大纲中,selenium只会启动Chrome,不会尝试加载任何网页 - 只需在网址中挂起data:;
即可。它将永远执行此操作,直到我手动关闭测试运行器和Chrome进程。这是硒日志:
Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 30263 Only local connections are allowed.
12:27:07.486 INFO - Done: [new session: Capabilities [{browserName=chrome}]]
12:27:07.502 INFO - Executing: [page load wait: 10000])
12:27:07.502 INFO - Done: [page load wait: 10000]
12:27:07.518 INFO - Executing: [set script timeoutt: 5000])
12:27:07.518 INFO - Done: [set script timeoutt: 5000]
12:27:07.533 INFO - Executing: [implicitly wait: 1000])
12:27:07.533 INFO - Done: [implicitly wait: 1000]
12:27:07.534 INFO - Executing: [get: http://localhost:3000/dashboard/game/1])
12:27:11.269 INFO - Done: [get: http://localhost:3000/dashboard/game/1]
12:27:11.308 INFO - Executing: [delete session: 77e320e2-e116-46a2-bce7-364a2fd1ad8d])
12:27:12.599 INFO - Done: [delete session: 77e320e2-e116-46a2-bce7-364a2fd1ad8d]
// At this point, the first scenario is finished and the second begins
12:27:12.630 INFO - Executing: [new session: Capabilities [{browserName=chrome}]])
12:27:12.630 INFO - Creating a new session for Capabilities [{browserName=chrome}] Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 25037 Only local connections are allowed.
12:27:14.423 INFO - Done: [new session: Capabilities [{browserName=chrome}]]
正如您所看到的,它只会创建一个新会话而不会执行任何其他操作。我该如何处理?