我已经成功地与Jest和Puppeteer进行了一些测试,我遇到了一个重大挑战,现在我遇到了另一个挑战。
我有一个应该由await page.click('button.green');
单击的“发送调查”按钮,该按钮应该起作用,因为我在控制台中运行了该选择器:$('button.green')
<button class="green btn-flat right white-text">…</button>
,并确定我已经获得了正确的元素。>
waitFor()
方法也应与该选择器一起使用,我对其进行了测试:$('.card')
<div class="card darken-1"><div class="card-content">…</div><div class="card-action">…</div></div>
任何人都有任何想法可能会导致此特定测试失败的原因吗?
describe("And using valid inputs", async () => {
beforeEach(async () => {
await page.type("input[name=title]", "My Title");
await page.type("input[name=subject]", "My Subject");
await page.type("input[name=body]", "This is the body of the email");
await page.type("input[name=recipients]", "example@gmail.com");
await page.click("form button.teal");
});
test("Submitting takes user to review screen", async () => {
const text = await page.getContentsOf("h5");
expect(text).toEqual("Please confirm your entries");
});
test("Submitting then saving adds survey to index page", async () => {
await page.click("button.green");
await page.waitFor(".card");
const title = await page.getContentsOf(".card-title");
const content = await page.getContentsOf("p");
expect(title).toEqual("My Title");
expect(content).toEqual("This is the body of the email");
});
});
这是我得到的错误:
FAIL tests/surveys.test.js (46.311s)
When logged in
✓ can see survey create form (4726ms)
And using valid inputs
✓ Submitting takes user to review screen (4360ms)
✕ Submitting then saving adds survey to index page (33430ms)
And using invalid inputs
✓ the form shows an error message (2966ms)
● When logged in › And using valid inputs › Submitting then saving adds survey to index page
Timeout - Async callback was not invoked within the 30000ms timeout specified by jest.setTimeout.
at node_modules/jest-jasmine2/build/queue_runner.js:68:21
at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:678:19)
● When logged in › And using valid inputs › Submitting then saving adds survey to index page
TimeoutError: waiting for selector ".card" failed: timeout 30000ms exceeded
40 | test("Submitting then saving adds survey to index page", async () => {
41 | await page.click("button.green");
> 42 | await page.waitFor(".card");
43 |
44 | const title = await page.getContentsOf(".card-title");
45 | const content = await page.getContentsOf("p");
at new WaitTask (node_modules/puppeteer/lib/DOMWorld.js:554:28)
at DOMWorld._waitForSelectorOrXPath (node_modules/puppeteer/lib/DOMWorld.js:483:22)
at DOMWorld.waitForSelector (node_modules/puppeteer/lib/DOMWorld.js:437:17)
at Frame.waitForSelector (node_modules/puppeteer/lib/FrameManager.js:608:47)
at Frame.<anonymous> (node_modules/puppeteer/lib/helper.js:111:23)
at Frame.waitFor (node_modules/puppeteer/lib/FrameManager.js:593:19)
at Proxy.waitFor (node_modules/puppeteer/lib/Page.js:1064:29)
at Object.waitFor (tests/surveys.test.js:42:18)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 failed, 6 passed, 7 total
Snapshots: 0 total
Time: 47.365s
Ran all test suites.