mirror of
https://github.com/playwright-community/playwright-go.git
synced 2026-06-12 21:01:15 +08:00
Some checks failed
Go / Lint (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, windows-latest) (push) Has been cancelled
Go / test-examples (push) Has been cancelled
Docs / Deploy docs (push) Has been cancelled
Verify Types / verify (push) Has been cancelled
Go / finish (push) Has been cancelled
91 lines
3.4 KiB
Go
91 lines
3.4 KiB
Go
package playwright_test
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/playwright-community/playwright-go"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPageAssertionsToHaveTitle(t *testing.T) {
|
|
BeforeEach(t)
|
|
|
|
_, err := page.Goto(server.EMPTY_PAGE)
|
|
require.NoError(t, err)
|
|
require.NoError(t, page.SetContent(`<title>new title</title>`))
|
|
|
|
require.NoError(t, expect.Page(page).ToHaveTitle("new title"))
|
|
require.NoError(t, expect.Page(page).ToHaveTitle(regexp.MustCompile("(?i)new title")))
|
|
require.NoError(t, expect.Page(page).Not().ToHaveTitle("not the current title", playwright.PageAssertionsToHaveTitleOptions{
|
|
Timeout: playwright.Float(750),
|
|
}))
|
|
|
|
_, err = page.Evaluate(`setTimeout(() => {
|
|
document.title = 'great title';
|
|
}, 300);
|
|
`)
|
|
require.NoError(t, err)
|
|
require.NoError(t, expect.Page(page).ToHaveTitle("great title"))
|
|
require.NoError(t, expect.Page(page).Not().ToHaveTitle("not the current title"))
|
|
}
|
|
|
|
func TestPageAssertionsToHaveURL(t *testing.T) {
|
|
BeforeEach(t)
|
|
|
|
_, err := page.Goto(server.EMPTY_PAGE)
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, expect.Page(page).ToHaveURL(server.EMPTY_PAGE))
|
|
require.NoError(t, expect.Page(page).ToHaveURL(regexp.MustCompile(`.*/empty\.html`), playwright.PageAssertionsToHaveURLOptions{
|
|
Timeout: playwright.Float(750),
|
|
}))
|
|
require.NoError(t, expect.Page(page).Not().ToHaveURL("https://playwright.dev"))
|
|
|
|
_, err = page.Goto("data:text/html,<div>A</div>")
|
|
require.NoError(t, err)
|
|
require.NoError(t, expect.Page(page).ToHaveURL("DATA:teXT/HTml,<div>a</div>", playwright.PageAssertionsToHaveURLOptions{
|
|
IgnoreCase: playwright.Bool(true),
|
|
}))
|
|
}
|
|
|
|
func TestPageAssertionsToHaveURLWithBaseURL(t *testing.T) {
|
|
BeforeEach(t)
|
|
|
|
page, err := browser.NewPage(playwright.BrowserNewPageOptions{
|
|
BaseURL: &server.PREFIX,
|
|
})
|
|
require.NoError(t, err)
|
|
_, err = page.Goto("/empty.html")
|
|
require.NoError(t, err)
|
|
require.NoError(t, expect.Page(page).ToHaveURL("/empty.html"))
|
|
require.NoError(t, expect.Page(page).ToHaveURL(regexp.MustCompile(`.*/empty\.html`)))
|
|
require.NoError(t, expect.Page(page).Not().ToHaveURL("https://playwright.dev"))
|
|
require.NoError(t, page.Close())
|
|
}
|
|
|
|
func TestPageAssertionsToHaveAccessibleErrorMessage(t *testing.T) {
|
|
BeforeEach(t)
|
|
|
|
require.NoError(t, page.SetContent(`
|
|
<form>
|
|
<input role="textbox" aria-invalid="true" aria-errormessage="error-message" />
|
|
<div id="error-message">Hello</div>
|
|
<div id="irrelevant-error">This should not be considered.</div>
|
|
</form>
|
|
`))
|
|
|
|
locator := page.Locator("input[role=\"textbox\"]")
|
|
require.NoError(t, expect.Locator(locator).ToHaveAccessibleErrorMessage("Hello"))
|
|
require.NoError(t, expect.Locator(locator).Not().ToHaveAccessibleErrorMessage("hello"))
|
|
require.NoError(t, expect.Locator(locator).ToHaveAccessibleErrorMessage("hello", playwright.LocatorAssertionsToHaveAccessibleErrorMessageOptions{
|
|
IgnoreCase: playwright.Bool(true),
|
|
}))
|
|
require.NoError(t, expect.Locator(locator).ToHaveAccessibleErrorMessage(regexp.MustCompile(`ell\w`)))
|
|
require.NoError(t, expect.Locator(locator).Not().ToHaveAccessibleErrorMessage(regexp.MustCompile(`hello`)))
|
|
require.NoError(t, expect.Locator(locator).ToHaveAccessibleErrorMessage(regexp.MustCompile(`hello`), playwright.LocatorAssertionsToHaveAccessibleErrorMessageOptions{
|
|
IgnoreCase: playwright.Bool(true),
|
|
}))
|
|
require.NoError(t, expect.Locator(locator).Not().ToHaveAccessibleErrorMessage("This should not be considered."))
|
|
}
|