forked from serge1peshcoff/selenium-go-conditions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathurl.go
55 lines (45 loc) · 1.32 KB
/
url.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
package conditions
import (
"strings"
"github.com/tebeka/selenium"
)
// URLIs returns a condition that checks if the page's URL matches the expectedURL.
func URLIs(expectedURL string) selenium.Condition {
return func(wd selenium.WebDriver) (bool, error) {
url, err := wd.CurrentURL()
if err != nil {
return false, err
}
return url == expectedURL, nil
}
}
// URLIsNot returns a condition that checks if the page's URL doesn't match the expectedURL.
func URLIsNot(expectedURL string) selenium.Condition {
return func(wd selenium.WebDriver) (bool, error) {
url, err := wd.CurrentURL()
if err != nil {
return false, err
}
return url != expectedURL, nil
}
}
// URLContains returns a condition that checks if the page's URL includes the substring.
func URLContains(substring string) selenium.Condition {
return func(wd selenium.WebDriver) (bool, error) {
url, err := wd.CurrentURL()
if err != nil {
return false, err
}
return strings.Contains(url, substring), nil
}
}
// URLNotContains returns a condition that checks if the page's URL doesn't include the substring.
func URLNotContains(substring string) selenium.Condition {
return func(wd selenium.WebDriver) (bool, error) {
url, err := wd.CurrentURL()
if err != nil {
return false, err
}
return !strings.Contains(url, substring), nil
}
}