我正在使用Puppeteer来测试我的应用程序的登录页面。 下面的代码在我的本地系统上运行正常但是当在Jenkins上运行9次时,我得到错误(如下所述)。
我尝试过不同的方法来解决这个问题但是还没有成功。还添加了setTimeOut,但即使这样也无法解决这个问题。
以下是示例代码:
const puppeteer = require('puppeteer');
const CREDS = require('../creds');
describe('Login & Title', () => {
var browser, page;
var url = 'https://www.example.com/login'
beforeEach (async () => {
browser = await puppeteer.launch({
args: ['--no-sandbox'], headless: true
});
page = await browser.newPage();
await page.goto(url);
})
afterEach (() => {
browser.close()
})
test('Test for Page Title', async () => {
var millisecondsToWait = 500;
setTimeout(function() {
}, millisecondsToWait);
const USERNAME_SELECTOR = '#inputUserName';
const PASSWORD_SELECTOR = '#inputPassword';
const BUTTON_SELECTOR = 'body > div > ng-view > form > div:nth-child(3) > button';
await page.click(USERNAME_SELECTOR);
await page.keyboard.type(CREDS.username);
await page.click(PASSWORD_SELECTOR);
await page.keyboard.type(CREDS.password);
await page.click(BUTTON_SELECTOR);
await page.waitForNavigation();
const title = await page.title();
expect(title).toBe("Example Website");
});
})
我收到错误:
console.assert node_modules/puppeteer/lib/FrameManager.js:597
AssertionError [ERR_ASSERTION]: No node found for selector: #inputUserName
FAIL __tests__/login.test.js
Login & Title
✕ Test for Page Title (513ms)
● Login & Title functionality.. › Test for Page Title
TypeError: Cannot read property 'click' of null
at Frame.click (node_modules/puppeteer/lib/FrameManager.js:598:18)
任何指针或帮助都会很棒!在此先感谢。