0

I have a component using Popover from shadcn/ui. When I try to testing it with Playwright the locator can´t found the id into the Input. I am using React ts. This is a fragment from my component:

 <div className="grid grid-cols-3 items-center gap-4">
              <Label htmlFor="name">Name</Label>
              <Input
                id="name"
                className="col-span-2 h-8"
                value={section}
                onChange={(e) => {
                  const newName = e.target.value
                  setSection(newName)
                }}
              />

and this is my spec:

test.describe('CaptureIdPopover Component', () =\> {
    let page: any;
    
    test.beforeEach(async ({ mount, page: p }) => {
        page = p;
        const mockValues = {
        section: 'Test Section',
        setSection: (value: string) => {},
        frameLength: 10,
        setFrameLength: (value: number) => {},
        additionalInfo: 'Test Comments',
        setAdditionalInfo: (value: string) => {},
       };
    
       await mount(
        <MockCameraControlProvider mockValues={mockValues}>
            <CaptureIdPopover/>
        </MockCameraControlProvider>
       );
    })
    
    test('Should render initial values', async () => {
       const nameInput = page.locator('#name');
       await expect(nameInput).toHaveText('Test Section')
    
       const lengthInput = page.locator('#length');
       await expect(lengthInput).toHaveText('15');
    
       const commentsInput = page.locator('#comments');
       await expect(commentsInput).toHaveText('Test Comments')
    })
})

I receive this:

Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected)

Locator: locator('#name') Expected string: "Test Section" Received: <element(s) not found> Call log:

  • expect.toHaveText with timeout 5000ms
  • waiting for locator('#name')
31 |  
32 |        const nameInput = page.locator('#name');

33 |        await expect(nameInput).toHaveText('Test Section');
   |                                ^
34 |
35 |        const lengthInput = page.locator('#length');
36 |        await expect(lengthInput).toHaveText('15');
1
  • Can you add your rendered html after mounting? console.log(await page.locator("body").innerHTML()); Commented Dec 20, 2024 at 11:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.