88 lines
2.9 KiB
Go
88 lines
2.9 KiB
Go
package cplient
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/tebeka/selenium"
|
|
"github.com/tebeka/selenium/chrome"
|
|
)
|
|
|
|
func TestPort(t *testing.T) {
|
|
cli := New("http://localhost:7123")
|
|
ltest := cli.Register("test", func(tid, content string) {
|
|
log.Println(tid, content)
|
|
|
|
})
|
|
cli.Connect()
|
|
t.Error(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser"))
|
|
t.Error(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/yanngu?lang=en&deviceType=browser"))
|
|
t.Error(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser"))
|
|
t.Error(ltest.Open("https://playerduo.com/api/playerDuo-service-v2/yanngu?lang=en&deviceType=browser"))
|
|
http.ListenAndServe(":42311", nil)
|
|
}
|
|
|
|
func TestChrome(t *testing.T) {
|
|
port := 41331
|
|
|
|
var err error
|
|
caps := selenium.Capabilities{"browserName": "chrome"}
|
|
|
|
chromecaps := chrome.Capabilities{}
|
|
// for _, epath := range []string{"../../../crx/myblock.crx", "../../crx/myblock.crx", "./crx/myblock.crx"} {
|
|
// _, err := os.Stat(epath)
|
|
// if err == nil {
|
|
// err := chromecaps.AddExtension(epath)
|
|
// if err != nil {
|
|
// panic(err)
|
|
// }
|
|
// break
|
|
// }
|
|
// }
|
|
|
|
chromecaps.Args = append(chromecaps.Args, "--disable-blink-features=AutomationControlled")
|
|
chromecaps.Args = append(chromecaps.Args, "user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36")
|
|
if proxy := os.Getenv("chrome_proxy"); proxy != "" {
|
|
log.Println("proxy-server", proxy)
|
|
chromecaps.Args = append(chromecaps.Args, "--proxy-server="+proxy)
|
|
}
|
|
|
|
if proxy := os.Getenv("pac_proxy"); proxy != "" {
|
|
log.Println("--proxy-pac-url=" + proxy)
|
|
chromecaps.Args = append(chromecaps.Args, "--proxy-pac-url="+proxy)
|
|
}
|
|
|
|
// chromecaps.Args = append(chromecaps.Args, "--proxy-pac-url=http://127.0.0.1:1081/pac")
|
|
chromecaps.Args = append(chromecaps.Args, "--disk-cache-dir=/tmp/chromedriver-cache")
|
|
chromecaps.Args = append(chromecaps.Args, "--user-data-dir=/tmp/chromedriver-userdata")
|
|
chromecaps.Args = append(chromecaps.Args, "--auto-open-devtools-for-tabs")
|
|
|
|
chromecaps.Args = append(chromecaps.Args, "--disable-gpu", "--disable-images", "--start-maximized", "--disable-infobars")
|
|
// chromecaps.Args = append(chromecaps.Args, "--headless")
|
|
chromecaps.Args = append(chromecaps.Args, "--no-sandbox")
|
|
chromecaps.Args = append(chromecaps.Args, "--disable-dev-shm-usage", "--mute-audio", "--safebrowsing-disable-auto-update")
|
|
|
|
chromecaps.ExcludeSwitches = append(chromecaps.ExcludeSwitches, "enable-automation")
|
|
caps.AddChrome(chromecaps)
|
|
|
|
_, err = selenium.NewChromeDriverService("/usr/bin/chromedriver", port)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", 9222))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = wd.Get("https://www.amazon.com/")
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
time.Sleep(time.Second * 10)
|
|
}
|