forked from playwright-community/playwright-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage_assertions.go
62 lines (54 loc) · 1.62 KB
/
page_assertions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package playwright
import (
"net/url"
"path"
)
type pageAssertionsImpl struct {
assertionsBase
actualPage Page
}
func newPageAssertions(page Page, isNot bool, defaultTimeout *float64) *pageAssertionsImpl {
return &pageAssertionsImpl{
assertionsBase: assertionsBase{
actualLocator: page.Locator(":root"),
isNot: isNot,
defaultTimeout: defaultTimeout,
},
actualPage: page,
}
}
func (pa *pageAssertionsImpl) ToHaveTitle(titleOrRegExp interface{}, options ...PageAssertionsToHaveTitleOptions) error {
var timeout *float64
if len(options) == 1 {
timeout = options[0].Timeout
}
expectedValues := toExpectedTextValues([]interface{}{titleOrRegExp}, false, true, nil)
return pa.expect(
"to.have.title",
frameExpectOptions{ExpectedText: expectedValues, Timeout: timeout},
titleOrRegExp,
"Page title expected to be",
)
}
func (pa *pageAssertionsImpl) ToHaveURL(urlOrRegExp interface{}, options ...PageAssertionsToHaveURLOptions) error {
var timeout *float64
if len(options) == 1 {
timeout = options[0].Timeout
}
baseURL := pa.actualPage.Context().(*browserContextImpl).options.BaseURL
if urlPath, ok := urlOrRegExp.(string); ok && baseURL != nil {
u, _ := url.Parse(*baseURL)
u.Path = path.Join(u.Path, urlPath)
urlOrRegExp = u.String()
}
expectedValues := toExpectedTextValues([]interface{}{urlOrRegExp}, false, false, nil)
return pa.expect(
"to.have.url",
frameExpectOptions{ExpectedText: expectedValues, Timeout: timeout},
urlOrRegExp,
"Page URL expected to be",
)
}
func (pa *pageAssertionsImpl) Not() PageAssertions {
return newPageAssertions(pa.actualPage, true, pa.defaultTimeout)
}