-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper_test.go
51 lines (39 loc) · 1 KB
/
scraper_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
package fbmktplcscraper
import (
"context"
"fmt"
"log"
"testing"
"github.com/tebeka/selenium"
"github.com/tebeka/selenium/chrome"
)
func TestNewInstance(t *testing.T) {
// initialize a Chrome browser instance on port 4444
service, err := selenium.NewChromeDriverService("chromedriver", 4444)
if err != nil {
log.Fatal("Error:", err)
}
log.Println("Started selenium chrome driver service.")
// configure the browser options
caps := selenium.Capabilities{}
caps.AddChrome(chrome.Capabilities{Args: []string{
//"--headless", // comment out this line for testing
}})
// Make a new fancy new scraper
scraper, err := NewInstance(&caps)
if err != nil {
panic(err)
}
log.Println("Created new scraper instance")
// Create a context with cancellation
ctx, cancel := context.WithCancel(context.Background())
scraper.Start(ctx)
// Get a bunch of products from the instance
listing := <-scraper.Products
fmt.Println(listing)
cancel()
err = service.Stop()
if err != nil {
t.Fatal(err)
}
}