forked from dreddsa5dies/automateGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (61 loc) · 1.46 KB
/
main.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
//test Selenium
package main
import (
"fmt"
"io"
"log"
"os"
"time"
"github.com/tebeka/selenium"
)
var code = `
package main
import "fmt"
func main() {
fmt.Println("Hello WebDriver!\n")
}
`
func main() {
pwdDir, _ := os.Getwd()
// создание файла log
// и нормальная обработка лога
fLog, err := os.OpenFile(pwdDir+"/log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0640)
check(err, fLog)
// FireFox driver without specific version
// *** Add gecko driver here if necessary (see notes above.) ***
caps := selenium.Capabilities{
"browserName": "firefox",
"webdriver.gecko.driver": "$GOPATH/bin/geckodriver",
}
wd, err := selenium.NewRemote(caps, "")
check(err, fLog)
defer wd.Quit()
// Get simple playground interface
wd.Get("http://play.golang.org/?simple=1")
// Enter code in textarea
elem, _ := wd.FindElement(selenium.ByCSSSelector, "#code")
elem.Clear()
elem.SendKeys(code)
// Click the run button
btn, _ := wd.FindElement(selenium.ByCSSSelector, "#run")
btn.Click()
// Get the result
div, _ := wd.FindElement(selenium.ByCSSSelector, "#output")
output := ""
// Wait for run to finish
for {
output, _ = div.Text()
if output != "Waiting for remote server..." {
break
}
time.Sleep(time.Millisecond * 100)
}
fmt.Printf("Got: %s\n", output)
}
// err check to log
func check(err error, fLog *os.File) {
if err != nil {
log.Println(err)
}
log.SetOutput(io.MultiWriter(fLog, os.Stdout))
}