webdriver

package
v0.0.0-...-e6a9d9d Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

README

wpt.fyi Webdriver tests

This directory containers integration tests for webapp/. These tests bring up the full webserver then use a Golang Webdriver client, tebeka/selenium, to load pages in a browser (Chrome or Firefox) and assert that the webapp behaves as expected.

To run the tests, from the root wpt.fyi directory, run:

make go_large_test

You can run just one of Chrome or Firefox via:

make go_chrome_test
make go_firefox_test

Note that when running these tests outside of docker (see Running in docker), they will use your locally installed browser and webdriver clients, so it is worth making sure they are the versions you expect.

Debugging

Debugging the webdriver/ tests can be difficult as they are integration tests and the problem can occur anywhere from controlling the browser, to the webapp frontend, to the backend - and other weird bugs inbetween! This section contains some tips on how to effectively debug them.

After running one of the above make commands at least once, one can directly run the golang tests via:

# You can copy GECKODRIVER_PATH out of the make output; it should be installed
# locally under webapp/node_modules/selenium-standalone/...
go test -v -timeout=15m -tags=large ./webdriver -args \
    -firefox_path=/usr/bin/firefox \
    -geckodriver_path=$GECKODRIVER_PATH \
    -chrome_path=/usr/bin/google-chrome \
    -chromedriver_path=/usr/bin/chromedriver \
    -frame_buffer=true \
    -staging=false \
    -browser=chrome  # Or firefox

It is worth comparing this command-line against the Makefile, in case this documentation becomes out of date.

Running only one test

If you only need to run one test, you can use the golang test -run parameter. For example:

go test -v -timeout=15m -tags=large ./webdriver \
    -run TestProductParam_Order/Order \
    -args \
    -firefox_path=/usr/bin/firefox \
    -geckodriver_path=$GECKODRIVER_PATH \
    -chrome_path=/usr/bin/google-chrome \
    -chromedriver_path=/usr/bin/chromedriver \
    -frame_buffer=true \
    -staging=false \
    -browser=chrome  # Or firefox
Visual Output

Many of the tests run some javascript (or click on an element, etc) and expect to find some resulting change on the page. When that doesn't occur, they usually just timeout and it can be difficult to know why. One very useful trick is to enable visual output, so that you can actually see the webpage as the test runs.

To do this, set the frame_buffer argument to false, e.g.:

go test -v -timeout=15m -tags=large ./webdriver -args \
    -firefox_path=/usr/bin/firefox \
    -geckodriver_path=$GECKODRIVER_PATH \
    -chrome_path=/usr/bin/google-chrome \
    -chromedriver_path=/usr/bin/chromedriver \
    -frame_buffer=false \
    -staging=false \
    -browser=chrome  # Or firefox
Verbose webdriver output

By default, webdriver output is hidden as it is very noisy. You can re-enable it by passing -debug=true to the tests, e.g.:

go test -v -timeout=15m -tags=large ./webdriver -args \
    -firefox_path=/usr/bin/firefox \
    -geckodriver_path=$GECKODRIVER_PATH \
    -chrome_path=/usr/bin/google-chrome \
    -chromedriver_path=/usr/bin/chromedriver \
    -frame_buffer=true \
    -staging=false \
    -browser=chrome \
    -debug=true

Redirecting stderr to stdout and saving it to a log-file is recommended due to the verbosity of webdriver logs (append 2>&1 | tee my-log.txt to the above command).

Running in docker

Sometimes bugs only occur in a docker-like environment. This can be difficult to reproduce, but a first step is to run the tests inside of docker. To do this, first start the docker container in one terminal tab:

./util/docker-dev/run.sh

Then, in another tab, we need to get the instance id of the container, exec 'bash' inside of it, and run our test:

docker container ls
[ note the CONTAINER ID ]
docker exec -it $CONTAINER_ID bash
user@abce84dd426d:~/wpt.fyi$
[now you can run 'make go_chrome_test', or 'go test ...' directly, etc]

Note that this maps the host machine's wpt.fyi checkout into docker, so any code edits you make on the host are reflected in the container and vice-versa.

Documentation

Index

Constants

View Source
const (
	// LongTimeout is the timeout for waiting the full page to load, with
	// data coming from Datastore. You may not need this if you only need
	// to wait for the initial Polymer rendering.
	LongTimeout = time.Second * 30
)
View Source
const StaticTestDataRevision = "24278ab61781de72ed363b866ae6b50b86822b27"

StaticTestDataRevision is the SHA for the local (static) test run summaries.

Variables

This section is empty.

Functions

func ChromeWebDriver

func ChromeWebDriver(port int, options []selenium.ServiceOption) (*selenium.Service, selenium.WebDriver, error)

ChromeWebDriver starts up ChromeDriver on the given port.

func ExtractScriptRawValue

func ExtractScriptRawValue(bytes []byte, key string) (value interface{}, err error)

ExtractScriptRawValue extracts the value of a given key from the return value of webdriver.ExecuteScriptRaw (raw bytes).

func FindShadowElement

func FindShadowElement(
	d selenium.WebDriver,
	e selenium.WebElement,
	selectors ...string) (selenium.WebElement, error)

FindShadowElement returns the first element found by an equivalent call to FindShadowElements.

func FindShadowElements

func FindShadowElements(
	d selenium.WebDriver,
	e selenium.WebElement,
	selectors ...string) ([]selenium.WebElement, error)

FindShadowElements finds the shadow DOM children via the given query selectors, recursively. The function takes a variable number of selectors; the selectors are combined together similar to CSS descendant combinators. However, all but the the last selector are expected to match to hosts of shadow DOM, and the shadow DOM boundaries will be crossed.

e.g. FindShadowElements(wd, node, "bar", "baz blah"). All matches of "bar" must have shadow roots, and the function finds all "baz blah" within each shadow DOM.

func FindShadowText

func FindShadowText(
	d selenium.WebDriver,
	e selenium.WebElement,
	selectors ...string) (string, error)

FindShadowText returns the Text of the element returned by an equivalent call to FindShadowElement.

func FirefoxWebDriver

func FirefoxWebDriver(port int, options []selenium.ServiceOption) (*selenium.Service, selenium.WebDriver, error)

FirefoxWebDriver starts up GeckoDriver on the given port.

func GetWebDriver

func GetWebDriver() (*selenium.Service, selenium.WebDriver, error)

GetWebDriver starts a WebDriver service (server) and creates a remote (client). Note: Make sure to close the remote first and the service later, e.g.

server, driver, err := GetWebDriver()

if err != nil {
  panic(err)
}

defer server.Stop() defer driver.Quit()

Types

type AppServer

type AppServer interface {
	// Hook for closing the process that runs the webserver.
	io.Closer

	// GetWebappURL returns the URL for the given path on the running webapp.
	GetWebappURL(path string) string
}

AppServer is an abstraction for navigating an instance of the webapp.

func NewWebserver

func NewWebserver() (s AppServer, err error)

NewWebserver creates an AppServer instance, which may be backed by local or remote (staging) servers.

Jump to

Keyboard shortcuts

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