diff --git a/README.md b/README.md index 1f398f5..ebf6de7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@

Special thanks to all the contributors over at k6 and playwright-go

Here's to open source!

- GitHub license + GitHub license Go Report Card GitHub license @@ -87,6 +87,7 @@ export default function () { | fill() | [`Fill()`](https://pkg.go.dev/github.com/mxschmitt/playwright-go#Page.Fill) | fills an 'input' element on the page based on the provided selector and string to be entered | | dragAndDrop() | [`DragAndDrop()`](https://pkg.go.dev/github.com/mxschmitt/playwright-go#Page.DragAndDrop) | drag an item from one place to another based on two selectors | | evaluate() | [`Evaluate()`](https://pkg.go.dev/github.com/mxschmitt/playwright-go#Page.Evaluate) | evaluate an expresion or function and get the return value | +| reload() | [`Reload()`](https://pkg.go.dev/github.com/mxschmitt/playwright-go#Page.Reload) | reloads the current page | NOTE: the above 'Encompassed Playwright Function(s)' will link to the [playwright-go package documentation](https://pkg.go.dev/github.com/mxschmitt/playwright-go#section-readme) to give an in-depth overview of how these functions will behave from a low-level perspective. diff --git a/playwright.go b/playwright.go index 2bcbcd1..52dbb97 100644 --- a/playwright.go +++ b/playwright.go @@ -24,35 +24,12 @@ type Playwright struct { } //Launch starts the playwright client and launches a browser -func (p *Playwright) Launch(args []string) { +func (p *Playwright) Launch(args playwright.BrowserTypeLaunchOptions) { pw, err := playwright.Run() if err != nil { log.Fatalf("could not start playwright: %v", err) } - browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{ - Args: args, - }) - if err != nil { - log.Fatalf("could not launch browser: %v", err) - } - p.Self = pw - p.Browser = browser -} - -func (p *Playwright) LaunchCustomBrowser(args []string, browserPath string, driver string) { - runOptions := playwright.RunOptions{ - DriverDirectory: driver, - 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{ - Args: args, - ExecutablePath: &browserPath, - }) + browser, err := pw.Chromium.Launch(args) if err != nil { log.Fatalf("could not launch browser: %v", err) } @@ -163,4 +140,10 @@ func (p *Playwright) Evaluate(expression string, opts playwright.PageEvaluateOpt log.Fatalf("error evaluating the expression: %v", err) } return returnedValue; +} + +func (p *Playwright) Reload() { + if _, err := p.Page.Reload(); err != nil { + log.Fatalf("error with reloading the page: %v", err) + } } \ No newline at end of file diff --git a/playwright_test.go b/playwright_test.go index c145ae3..f9b9e34 100644 --- a/playwright_test.go +++ b/playwright_test.go @@ -9,12 +9,14 @@ import ( var tests = []func(t *testing.T){ TestPlaywright, - TestPlaywrightCustomBrowser, } func TestPlaywright(t *testing.T) { var pw Playwright - var opts []string + headless := true + opts := playwright.BrowserTypeLaunchOptions { + Headless: &headless, + } var opts2 playwright.PageGotoOptions var opts3 playwright.PageWaitForSelectorOptions @@ -25,19 +27,6 @@ func TestPlaywright(t *testing.T) { 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) { for i, test := range tests { t.Run(strconv.Itoa(i), test)