0

code for frontend react js

import { chromium } from 'playwright';

export default function App() {
  const createBrowser = async () => {
    const browser = await chromium.launch({ headless: false });

    const context = await browser.newContext();

    const page = await context.newPage();

    const element = await page.waitForSelector('.products', {
      state: 'visible',
      timeout: 5,
    });
  };

  return (
    <>
      <button type="button" onClick={createBrowser}>
        CreateBrowser
      </button>
    </>
  );
}

Error

enter image description here

I'm using electron Electron-React-boilerplate template in electron options i'm using nodeIntegration option to run node js api in frontend and it works find with node js api

but when i try to get any element using page.waitForSelector or page.locator('input') or page.fill or page.click thorw this error how can i get playwright fully working with react js at fronted I don't want to use ipcMan to send request to nodejs from frontend to run test

Ahmed Mohamed
  • 29
  • 1
  • 6

1 Answers1

0

do you want to test the UI ? if so i wrote an answer here Electron desktop Application testing with[PLAYWRIGHT].

after you init the project, and write the tests you simply use npx playwright tests.

also did you try to load the page with a url, maybe the page is not loading any html file and this is why it doesn't work

2BC.Wasabi
  • 75
  • 6