playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
2.11k stars 156 forks source link

Assertions in Go #401

Closed ivaylo321 closed 9 months ago

ivaylo321 commented 9 months ago

Hello,

In Javascript I can use syntax like this:

expect(page.getByTestId('status')).toHaveText('Submitted');

Is there something similar I can do in Go, instead of

text, err := page.Locator("status").Evaluate("el => el.textContent", nil)
if text != "Submitted" {
    ...
}

I am basically asking if there is a way to use the expect keyword in Go?

tejaskumark commented 9 months ago

I do not think that is available by default, but you can always wrap things up as per your need like this example, func assertErrorToNilf https://github.com/playwright-community/playwright-go/blob/main/examples/download/main.go

canstand commented 9 months ago

@ivaylo321 you can do this:

expect := playwright.NewPlaywrightAssertions(5000)

err := expect.Locator(page.GetByTestId("status")).ToHaveText("Submitted")