我正在尝试通过运行无头Chrome浏览器进行测试来使用Intern 4进行功能测试。我相信一切都已正确设置,并且最近为Mac终端安装了selenium-server-standalone
。尝试运行测试时,我得到以下结果:
Running "exec:test_functional" (exec) task
Listening on localhost:9000 (ws 9001)
Tunnel started
BUG: suiteEnd was received for invalid session
(ノಠ益ಠ)ノ彡┻━┻
UnknownError: [POST http://localhost:4444/wd/hub/session / {"desiredCapabilities":{"name":"intern","idle-timeout":60,"browserName":"chrome","goog:chromeOptions":{"args":["headless","disable-gpu"]}}}] Cannot define class using reflection
at Server.post <tests/node_modules/src/Server.ts:367:14>
at Server.createSession <tests/node_modules/src/Server.ts:412:14>
at Suite.before <tests/src/lib/executors/Node.ts:469:8>
at <tests/src/lib/Suite.ts:388:19>
at new Task <tests/node_modules/@dojo/core/async/Task.ts:239:3>
at runLifecycleMethod <tests/src/lib/Suite.ts:355:10>
at before <tests/src/lib/Suite.ts:458:10>
at Suite.run <tests/src/lib/Suite.ts:477:6>
at <tests/src/lib/executors/Node.ts:821:20>
at FunctionQueue.next <tests/src/lib/executors/Node.ts:945:16>
TOTAL: tested 0 platforms, 0 passed, 0 failed; fatal error occurred
>> Exited with code: 1.
>> Error executing child process: Error: Process exited with code 1.
Warning: Task "exec:test_functional" failed. Use --force to continue.
Aborted due to warnings.
我正在运行最新版本的Node,npm和Intern
解决此问题的任何帮助
编辑:
app.ts
// tests/functional/app.ts
const { suite, before, test } = intern.getPlugin("interface.tdd");
const { expect, assert } = intern.getPlugin("chai");
suite("app", () => {
before(({ remote }) => {
return remote
.get("src/app.html")
.setFindTimeout(5000)
.findDisplayedByCssSelector("body");
});
let windowHandles: any;
test("testing", ({ remote }) => {
return remote
// Click login button
.findByClassName('hero-cta')
.click()
.end()
// Switch to login window
.getAllWindowHandles()
.then(function(handles: string[]){
windowHandles = handles;
assert.isArray(windowHandles);
return remote.switchToWindow(windowHandles[1]);
})
// Input user credentials and submit
.findById('user_username')
.type('username')
.end()
.findById('user_password')
.type('password')
.findAllByCssSelector('button')
.click()
.end()
//Switch to app
.getAllWindowHandles()
.then(function(handles: string[]){
assert.isArray(handles);
return remote.switchToWindow(windowHandles[0]);
})
.find('css selector','span')
.getVisibleText()
.then(function(text: string) {
console.log(text);
})
});
});
intern.json
{
...
"environments": [
{
"browserName": "chrome",
"goog:chromeOptions": {
"args": ["headless", "disable-gpu"]
}
}
]
}
答案 0 :(得分:3)
当系统上Java版本对于Selenium(为Intern管理WebDriver连接)太新时,就会发生Cannot define class using reflection
错误。 Selenium需要Java 1.8;如果Java 10或11是默认设置,则会出现该错误。
还要注意,实习生测试不需要selenium-server-standalone
;默认情况下,实习生会自行下载Selenium和所需的WebDriver隧道,并启动和关闭其自己的Selenium实例。