Skip to content

Commit

Permalink
feat: add launch with custom browser option supressing the installati…
Browse files Browse the repository at this point in the history
…on process, updated tests
  • Loading branch information
nicholasvuono committed Feb 24, 2022
1 parent 7fb85e2 commit 345b202
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ func (p *Playwright) Launch(args []string) {
p.Browser = browser
}

func (p *Playwright) LaunchCustomBrowser(args []string, browserPath string) {
runOptions := playwright.RunOptions{
DriverDirectory: "./",
SkipInstallBrowsers: true,
Browsers: []string {browserPath},
}
pw, err := playwright.Run(&runOptions)
if err != nil {
log.Fatalf("could not start playwright: %v", err)
}
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false),
Args: args,
})
if err != nil {
log.Fatalf("could not launch browser: %v", err)
}
p.Self = pw
p.Browser = browser
}

//NewPage opens a new page within the browser
func (p *Playwright) NewPage() {
page, err := p.Browser.NewPage()
Expand Down
15 changes: 15 additions & 0 deletions playwright_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

var tests = []func(t *testing.T){
TestPlaywright,
TestPlaywrightCustomBrowser,
}

func TestPlaywright(t *testing.T) {
Expand All @@ -21,6 +22,20 @@ func TestPlaywright(t *testing.T) {
pw.NewPage()
pw.Goto("https://www.google.com", opts2)
pw.WaitForSelector("//html/body/div[1]/div[2]", opts3)
pw.Kill()
}

func TestPlaywrightCustomBrowser(t *testing.T) {
var pw Playwright
var opts []string
var opts2 playwright.PageGotoOptions
var opts3 playwright.PageWaitForSelectorOptions

pw.LaunchCustomBrowser(opts, "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe")
pw.NewPage()
pw.Goto("https://www.google.com", opts2)
pw.WaitForSelector("//html/body/div[1]/div[2]", opts3)
pw.Kill()
}

func TestAll(t *testing.T) {
Expand Down

0 comments on commit 345b202

Please sign in to comment.