I am writing nightmare script to test a website. The problem is for page events. There is a script
<button id="btn" onclick="myFunction()">Try it</button>
<script>
function myFunction() {
confirm("Press a button!");
}
</script>
and the nightmare script is
var Nightmare = require('nightmare');
const path = require('path');
var nightmare = Nightmare({
show: true,
webPreferences: {
preload: path.resolve("pre.js")
//alternative: preload: "absolute/path/to/custom-script.js"
}
})
var confirm = 'confirm';
nightmare.on('page', function(confirm, message, response){
return true;
});
nightmare
.goto('http://localhost:3000/index.html')
.click('#btn')
.wait(1000)
.evaluate(function () {
return "just value";//document.querySelector('#main .searchCenterMiddle li a').href
})
.end()
.then(function (result) {
console.log(result)
})
.catch(function (error) {
console.error('Search failed:', error);
});
function testing(arg){
console.log(arg);
}
When run like node test.js
It opens the browser window and click the button. But don't know how to press 'OK' button in the confirm pop up so that I can go to next test. The response not required from the 'OK' button just need to click the 'OK' button in the confirm window.
any help is very much appreciated.
Thanks