-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
navigation.go
61 lines (53 loc) · 1.56 KB
/
navigation.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
package biloba
import (
"net/http"
"github.com/chromedp/chromedp"
)
/*
Navigate() causes this tab to navigate to the provided URL. The spec fails if the response does not have status code 200
Read https://onsi.github.io/biloba/#navigation to learn more about navigation
*/
func (b *Biloba) Navigate(url string) *Biloba {
return b.NavigateWithStatus(url, http.StatusOK)
}
/*
NavigateWithStatus() causes this tab to navigate to the provided URL and asserts that the response has the provided status code.
Read https://onsi.github.io/biloba/#navigation to learn more about navigation
*/
func (b *Biloba) NavigateWithStatus(url string, status int) *Biloba {
b.gt.Helper()
resp, err := chromedp.RunResponse(b.Context, chromedp.Navigate(url))
if err != nil {
b.gt.Fatalf("failed to navigate to %s: %s", url, err.Error())
return b
}
if resp != nil && status != int(resp.Status) {
b.gt.Fatalf("failed to navigate to %s: expected status code %d, got %d", url, status, resp.Status)
return b
}
return b
}
/*
Location() returns the location (i.e. url) of the current tab.
*/
func (b *Biloba) Location() string {
var location string
err := chromedp.Run(b.Context, chromedp.Location(&location))
if err != nil {
b.gt.Fatalf("Failed to fetch location:\n%s", err.Error())
return ""
}
return location
}
/*
Title() returns the window title of the current tab.
*/
func (b *Biloba) Title() string {
var title string
err := chromedp.Run(b.Context, chromedp.Title(&title))
if err != nil {
b.gt.Fatalf("Failed to fetch title:\n%s", err.Error())
return ""
}
return title
}