Я успешно разрабатывал некоторые тесты с 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.