ReferenceError: window is not defined at e2e test
ReferenceError: window is not defined at e2e test
我正在使用 TS + Puppeteer 编写一个新的 e2e 测试,我需要向下滚动页面以单击按钮。
it('user create request at homepage', async () => {
await page.goto(`${global.HOST}`, { waitUntil: 'networkidle0' });
const postRequestBtn = 'qa-id="dummybtn"';
await window.scrollBy(0, document.body.scrollHeight);
//also tried await window.scrollTo(0,100);
await page.waitForSelector(postRequestBtn);
});
我希望向下滚动页面,但出现错误:
ReferenceError: window is not defined
- 你能说说我做错了什么吗?
使用page.evaluate
函数在页面上下文中执行javascript。
滚动到元素:
await page.$eval('qa-id="dummybtn"', el => el.scrollIntoView());
滚动到底部:
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
我正在使用 TS + Puppeteer 编写一个新的 e2e 测试,我需要向下滚动页面以单击按钮。
it('user create request at homepage', async () => {
await page.goto(`${global.HOST}`, { waitUntil: 'networkidle0' });
const postRequestBtn = 'qa-id="dummybtn"';
await window.scrollBy(0, document.body.scrollHeight);
//also tried await window.scrollTo(0,100);
await page.waitForSelector(postRequestBtn);
});
我希望向下滚动页面,但出现错误:
ReferenceError: window is not defined
- 你能说说我做错了什么吗?
使用page.evaluate
函数在页面上下文中执行javascript。
滚动到元素:
await page.$eval('qa-id="dummybtn"', el => el.scrollIntoView());
滚动到底部:
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));