I am trying to get functional testing working using Intern 4 by running a headless Chrome browser for testing. I believe everything is set up correctly and have recently installed selenium-server-standalone
for Mac terminal. I am getting the following result when attempting to run the test:
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.
I am running the latest version of Node, npm, and Intern
Any help with resolving this appreciated
EDIT:
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"]
}
}
]
}
The Cannot define class using reflection
error happens when the version of Java on your system is too new for Selenium (which manages WebDriver connections for Intern). Selenium needs Java 1.8; when Java 10 or 11 are the default, you'll get that error.
Also note that you don't need selenium-server-standalone
for Intern tests; by default Intern downloads Selenium and the required WebDriver tunnels on its own, and also starts and shuts down its own instance of Selenium.