-
Notifications
You must be signed in to change notification settings - Fork 4
/
url_test.go
103 lines (86 loc) · 3.37 KB
/
url_test.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package conditions_test
import (
"testing"
"time"
conditions "github.com/serge1peshcoff/selenium-go-conditions"
)
func TestURLIs(t *testing.T) {
// Testing successful selenium.Wait() call.
err := wd.Get("http://localhost:3000/redirect")
if err != nil {
t.Fatalf("Cannot get http://localhost:3000/redirect: %v\n", err)
}
// This should not raise an error.
if err = wd.Wait(conditions.URLIs("http://localhost:3000/static")); err != nil {
t.Fatalf("Error while executing wd.Wait(): %v\n", err)
}
// Testing unsuccessful selenium.Wait() call (this should raise error cause of timeout).
err = wd.Get("http://localhost:3000/static")
if err != nil {
t.Fatalf("Cannot get http://localhost:3000/static: %v\n", err)
}
// This should raise an timeout error.
if err = wd.WaitWithTimeout(conditions.URLIs("http://localhost:3000/redirect"), 500*time.Millisecond); err == nil {
t.Fatalf("wd.Wait() should raise an error, but it didn't.\n")
}
}
func TestURLIsNot(t *testing.T) {
// Testing successful selenium.Wait() call.
err := wd.Get("http://localhost:3000/redirect")
if err != nil {
t.Fatalf("Cannot get http://localhost:3000/redirect: %v\n", err)
}
// This should not raise an error.
if err = wd.Wait(conditions.URLIsNot("http://localhost:3000/redirect")); err != nil {
t.Fatalf("Error while executing wd.Wait(): %v\n", err)
}
// Testing unsuccessful selenium.Wait() call (this should raise error cause of timeout).
err = wd.Get("http://localhost:3000/static")
if err != nil {
t.Fatalf("Cannot get http://localhost:3000/static: %v\n", err)
}
// This should raise an timeout error.
if err = wd.WaitWithTimeout(conditions.URLIsNot("http://localhost:3000/static"), 500*time.Millisecond); err == nil {
t.Fatalf("wd.Wait() should raise an error, but it didn't.\n")
}
}
func TestURLContains(t *testing.T) {
// Testing successful selenium.Wait() call.
err := wd.Get("http://localhost:3000/redirect")
if err != nil {
t.Fatalf("Cannot get http://localhost:3000/redirect: %v\n", err)
}
// This should not raise an error.
if err = wd.Wait(conditions.URLContains("static")); err != nil {
t.Fatalf("Error while executing wd.Wait(): %v\n", err)
}
// Testing unsuccessful selenium.Wait() call (this should raise error cause of timeout).
err = wd.Get("http://localhost:3000/static")
if err != nil {
t.Fatalf("Cannot get http://localhost:3000/static: %v\n", err)
}
// This should raise an timeout error.
if err = wd.WaitWithTimeout(conditions.URLContains("redirect"), 500*time.Millisecond); err == nil {
t.Fatalf("wd.Wait() should raise an error, but it didn't.\n")
}
}
func TestURLNotContains(t *testing.T) {
// Testing successful selenium.Wait() call.
err := wd.Get("http://localhost:3000/redirect")
if err != nil {
t.Fatalf("Cannot get http://localhost:3000/redirect: %v\n", err)
}
// This should not raise an error.
if err = wd.Wait(conditions.URLNotContains("redirect")); err != nil {
t.Fatalf("Error while executing wd.Wait(): %v\n", err)
}
// Testing unsuccessful selenium.Wait() call (this should raise error cause of timeout).
err = wd.Get("http://localhost:3000/static")
if err != nil {
t.Fatalf("Cannot get http://localhost:3000/static: %v\n", err)
}
// This should raise an timeout error.
if err = wd.WaitWithTimeout(conditions.URLNotContains("static"), 500*time.Millisecond); err == nil {
t.Fatalf("wd.Wait() should raise an error, but it didn't.\n")
}
}