假设脚本已导航到某个页面。如何在该脚本中执行js函数?
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);
答案 0 :(得分:7)
使用.evaluate()函数。
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);