Skip to content

Instantly share code, notes, and snippets.

@NickCis
Created October 14, 2018 17:15
Show Gist options
  • Save NickCis/1ca33e22641c9d6dda1fc88c4de49c3a to your computer and use it in GitHub Desktop.
Save NickCis/1ca33e22641c9d6dda1fc88c4de49c3a to your computer and use it in GitHub Desktop.
Testcafe bug: ignores setNativeHandler on useRole first redirection
<html>
<head>
<title>My Nice Page</title>
</head>
<body>
<h1>My nice body :)</h1>
<p>This is a nice webpage</p>
<script>
window.addEventListener('beforeunload', function() {
console.log('beforeunload');
return 'something';
});
</script>
</body>
</html>
<html>
<head>
<title>My Nice Login</title>
</head>
<body>
<h1>Login :)</h1>
<p>This is a nice Login</p>
<form action="index.html">
<input name="user" type="text" id="user" />
<input name="password" type="password" id="password" />
<button type="submit" id="submit">Send</button>
</form>
</body>
</html>
{
"name": "testcafe-setNativeHandler-userRole-bug",
"version": "0.0.1",
"main": "index.js",
"license": "MIT",
"dependencies": {
"http-server": "^0.11.1",
"testcafe": "^0.22.0"
},
"scripts": {
"start": "http-server",
"test": "testcafe chromium test.js --app 'npm start'"
}
}
import { Role, Selector } from 'testcafe';
const url = 'http://localhost:8080';
const user = new Role(`${url}/login.html`, async t => {
await t
.typeText('#user', 'user')
.typeText('#password', 'password')
.click('#submit');
});
fixture('Home')
.page(url);
test('My first test', async t => {
await t
.setNativeDialogHandler((...args) => {
console.log('handler', args);
return true;
})
.useRole(user);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment