playwright

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

README

⚠️ This is currently an alpha version

This is not supported by the k6 team, and is worked on by an individual contributor. It may also break in the future as both xk6 and playwright-go. Any issues with the tool should be raised here.

It is not production ready yet, but definitely works as intended! Please enjoy the tool!



pdq

xk6 playwright


k6 extension that adds support for browser automation and end-to-end web testing using playwright-go

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

Here's to open source!

GitHub license Go Report Card GitHub license


This project was inspired by xk6-browser. Having seen the release we were excited to play around with the tool, but while using it we ran into some issues around context, page navigation, typing and button clicks. Having previously worked with playwright-go we thought it would be a great idea to create an extension around this so we had something we know would work to our liking. Thus xk6 playwright was born!

NOTE: we totally understand at the time of writing this that xk6-browser is not yet production ready, and that it is currently an early beta that has been released to the public that will evolve and get better over time. However, we still saw validity in creating this extension aiming to support something we have used and know works to our liking. Competition is not intended, we just want to make cool things that help us do our jobs!


Build from source

To build a k6 binary with this extension, first ensure you have the prerequisites:

  • Go toolchain
  • Git
  • Clone the k6 repository (Note: make sure you are in the k6 repo base directory before attempting the below steps)

Then:

  1. Install xk6:
go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
xk6 build --output xk6-playwright --with github.com/wosp-io/xk6-playwright

This will create a xk6-playwright binary file in the current working directory. This file can be used exactly the same as the main k6 binary, with the addition of being able to run xk6-browser scripts.

  1. Run scripts that import k6/x/playwright with the new xk6-playwright binary. On Linux and macOS make sure this is done by referencing the file in the current directory, e.g. ./xk6-playwright run <script>, or you can place it somewhere in your PATH so that it can be run from anywhere on your system.

Simplest Working Example

import pw from 'k6/x/playwright';

export default function () {
  pw.launch()
  pw.newPage()
  pw.goto("https://www.google.com/", {waitUntil: 'networkidle'})
  pw.waitForSelector("//html/body/div[1]/div[2]", {state: 'visible'})
  pw.kill()
}

Currently Supported Actions

Playwright API coverage is as follows:

Action Encompassed Playwright Function(s) Description
launch() Run() & Launch() starts playwright client and launches browser
newPage() NewPage() opens up a new page within the browser
waitForSelector() WaitForSelector() waits for an element to be on the page based on the provided selector
click() Click() clicks an element on the page based on the provided selector
type() Type() types in an 'input' element on the page based on the provided selector and string to be entered

NOTE: the above 'Encompassed Playwright Function(s)' will link to the playwright-go package documentation to give an in-depth overview of how these functions will behave from a low-level perspective.

If you would like a high-level perspective on how these actions work you will be better served with the Playwright API Documentation


Contributing

  1. Fork it (https://github.com/your-github-user/xk6-playwright/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Nick Vuono - creator and maintainer

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Playwright

type Playwright struct {
	Self    *playwright.Playwright
	Browser playwright.Browser
	Page    playwright.Page
}

Playwright is the k6 extension for a playwright-go client.

func (*Playwright) Click

func (p *Playwright) Click(selector string, opts playwright.PageClickOptions)

Click wrapper around playwright click page function that takes in a selector and a set of options

func (*Playwright) Goto

func (p *Playwright) Goto(url string, opts playwright.PageGotoOptions)

Goto wrapper around playwright goto page function that takes in a url and a set of options

func (*Playwright) Kill

func (p *Playwright) Kill()

Kill closes browser instance and stops puppeteer client

func (*Playwright) Launch

func (p *Playwright) Launch(args []string)

Launch starts the playwright client and launches a browser

func (*Playwright) NewPage

func (p *Playwright) NewPage()

NewPage opens a new page within the browser

func (*Playwright) Type

func (p *Playwright) Type(selector string, typedString string, opts playwright.PageTypeOptions)

Type wrapper around playwright type page function that takes in a selector, string, and a set of options

func (*Playwright) WaitForSelector

func (p *Playwright) WaitForSelector(selector string, opts playwright.PageWaitForSelectorOptions)

WaitForSelector wrapper around playwright waitForSelector page function that takes in a selector and a set of options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL