-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
45 lines (36 loc) · 966 Bytes
/
service.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
package webshot
import (
"fmt"
"os"
"github.com/tebeka/selenium"
)
// NewWebshot sets up a new browser with the config provided
func NewWebshot(c NewConfig) (*Webshot, error) {
// var webdriver selenium.WebDriver
opts := []selenium.ServiceOption{
selenium.StartFrameBuffer(),
selenium.GeckoDriver(c.DriverPath),
selenium.Output(os.Stderr),
}
if c.DebugMode {
selenium.SetDebug(true)
}
service, err := selenium.NewGeckoDriverService(c.DriverPath, c.Port, opts[0])
if err != nil {
return nil, err
}
caps := selenium.Capabilities{"browserName": c.BrowserName}
wd, err := selenium.NewRemote(caps, fmt.Sprintf("%s:%d", c.Address, c.Port))
if err != nil {
return nil, err
}
fmt.Printf("The service ran successfully\n")
return &Webshot{
Webdriver: wd,
Service: service,
}, nil
}
// Extend allow you to use use all of the functionalities provided by selenium
func (w *Webshot) Extend() selenium.WebDriver {
return w.Webdriver
}