Sunday, 18 September 2022

puppeteer check value input after type

I'm using puppeteer, pptr-testing-library and I'm trying to open google website and type in search input "tutorials" and after that I want to check that the value in the input is the same as I type "tutorials" but I get an error

 Unable to find an element with the text: tutorials".

enter image description here the code:

import { PuppeteerScreenRecorder } from "puppeteer-screen-recorder";
import puppeteer, { Browser, ElementHandle, Page } from "puppeteer";
import { getDocument, queries } from "pptr-testing-library";
const { findByRole } = queries;
let page, recorder, browser;
beforeAll(async () => {
  browser = await puppeteer.launch({
    headless: true,
  });

  page = await browser.newPage();
  recorder = new PuppeteerScreenRecorder(page);
  await recorder.start(`./screenshots/e2e-test-${Date.now()}.mp4`);
  await page.goto("https://www.google.com");
  console.log({ page });
});

describe("type in search input", () => {
  it("should check search input value", async () => {
    console.log("enter test");
    const $document = await getDocument(page);
    console.log("doc is", $document);
    const $searchInput = await findByRole($document, "combobox");
    await $searchInput.type("tutorials");
    console.log({ $searchInput });
    expect(await queries.findAllByText($document, 'tutorials"')).toBeTruthy();
    await recorder.stop();
    await browser.close();
  });
});

in addition when I print the logs of doc and searchInput I get empty object enter image description here how to get the value of the input after typing?



from puppeteer check value input after type

No comments:

Post a Comment