-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathpage_assertions.go
70 lines (62 loc) · 1.76 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
63
64
65
66
67
68
69
70
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, err := toExpectedTextValues([]interface{}{titleOrRegExp}, false, true, nil)
if err != nil {
return err
}
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
var ignoreCase *bool
if len(options) == 1 {
timeout = options[0].Timeout
ignoreCase = options[0].IgnoreCase
}
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, err := toExpectedTextValues([]interface{}{urlOrRegExp}, false, false, ignoreCase)
if err != nil {
return err
}
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)
}