Say the script has navigated to a certain page. How to execute a js function inside that script?
describe("TestSuite", () => {
test("Login", async() => {
await page.goto(APP);
await page.waitForSelector("[name=loginForm]");
await page.click("input[name=username]");
await page.type("input[name=username]", user.username);
await page.click("input[name=pwd]");
await page.type("input[name=pwd]", user.pwd);
await page.click("input[name=login]");
await page.waitForSelector(".PageBodyVertical");
// execute a js function x() here which is loaded with the page.
}, 60000);
Use the .evaluate() function.
describe("TestSuite", () => {
test("Login", async() => {
await page.goto(APP);
await page.waitForSelector("[name=loginForm]");
await page.click("input[name=username]");
await page.type("input[name=username]", user.username);
await page.click("input[name=pwd]");
await page.type("input[name=pwd]", user.pwd);
await page.click("input[name=login]");
await page.waitForSelector(".PageBodyVertical");
await page.evaluate( function(){
x();
} );
}, 60000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With