-
Notifications
You must be signed in to change notification settings - Fork 15
/
wait_test.go
64 lines (51 loc) · 1.54 KB
/
wait_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
package marionette_client
import (
"errors"
"testing"
"time"
)
func TestWait(t *testing.T) {
t.Run("UntilConditionNeverOccuredTest", UntilConditionNeverOccuredTest)
// FIXME: t.Run("UntilErrorTest", UntilErrorTest)
}
func UntilErrorTest(t *testing.T) {
var errorMsg string = "the Error message."
timeout := time.Duration(5) * time.Second
condition := func(c Finder) (bool, *WebElement, error) {
return false, nil, errors.New(errorMsg)
}
_, _, err := Wait(client).For(timeout).Until(condition)
if err.Error() != errorMsg {
t.Fatalf("Expected error msg %v, got %v", errorMsg, err.Error())
}
}
func UntilConditionNeverOccuredTest(t *testing.T) {
timeout := time.Duration(11) * time.Minute
condition := func(c Finder) (bool, *WebElement, error) {
return false, nil, nil
}
_, _, err := Wait(client).For(timeout).Until(condition)
if err == nil {
t.Fatal("Element Was Found in ElementIsNotPresent test.")
}
}
func WaitForUntilIntegrationTest(t *testing.T) {
client.SetContext(Context(CONTENT))
client.Navigate("http://www.w3schools.com/xml/tryit.asp?filename=tryajax_get")
timeout := time.Duration(10) * time.Second
condition := ElementIsPresent(By(CssSelector), "a.w3-button.w3-bar-item.topnav-icons.fa.fa-rotate")
ok, v, err := Wait(client).For(timeout).Until(condition)
if err != nil || !ok {
t.Fatalf("%#v", err)
}
v.Click()
err = client.SwitchToFrame(By(Id), "iframeResult")
if err != nil {
t.Fatalf("%#v", err)
}
e, err := client.FindElement(By(TagName), "button")
if err != nil {
t.Fatalf("%#v", err)
}
e.Click()
}