-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
72 lines (59 loc) · 1.46 KB
/
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
package main
import (
"bytes"
"fmt"
"image"
"image/png"
"os"
"time"
"github.com/tebeka/selenium"
)
var code = `
package main
import "fmt"
func main() {
fmt.Println("Hello WebDriver!\n")
}
`
func sshot(wd selenium.WebDriver, name string) {
screenshot, _ := wd.Screenshot()
img, _, _ := image.Decode(bytes.NewReader(screenshot))
out, err := os.Create(name)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = png.Encode(out, img)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
// Errors are ignored for brevity.
func main() {
// FireFox driver without specific version
// *** Add gecko driver here if necessary (see notes above.) ***
caps := selenium.Capabilities{
"browserName": "firefox",
}
wd, err := selenium.NewRemote(caps, "http://localhost:4444/wd/hub")
if err != nil {
panic(err)
}
defer wd.Quit()
// Get simple playground interface
wd.Get("http://162.222.176.0:8080/encyclopedia")
wd.SetImplicitWaitTimeout(60 * time.Second)
wd.SetAsyncScriptTimeout(60 * time.Second)
wd.SetPageLoadTimeout(15 * time.Second)
wd.MaximizeWindow("")
page1Buttons, _ := wd.FindElements(selenium.ByXPATH, "//div[@type='button']")
sshot(wd, "001.png")
fmt.Println("page1Button number is ", len(page1Buttons))
page1Buttons[2].Click()
page2Buttons, _ := wd.FindElements(selenium.ByXPATH, "//span[@type='button']")
fmt.Println("page2Button number is ", len(page2Buttons))
sshot(wd, "002.png")
page2Buttons[2].Click()
sshot(wd, "003.png")
}