rules_webtesting

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: Apache-2.0

README

Bazel Web Testing Rules

Build Status

Bazel rules and supporting code to allow testing against a browser with WebDriver.

Configure your Bazel project

Add the following to your WORKSPACE file:

# Load rules_go at master for example purposes only. You should specify
# a specific version in your project.
http_archive(
    name = "io_bazel_rules_go",
    strip_prefix = "rules_go-master",
    urls = [
        "https://github.com/bazelbuild/rules_go/archive/master.tar.gz",
    ],
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()

# Load rules_webtesting at master for example purposes only. You should specify
# a specific version in your project.
http_archive(
    name = "io_bazel_rules_webtesting",
    strip_prefix = "rules_webtesting-master",
    urls = [
        "https://github.com/bazelbuild/rules_webtesting/archive/master.tar.gz",
    ],
)

load("@io_bazel_rules_webtesting//web:repositories.bzl",
    "browser_repositories",
    "web_test_repositories")

web_test_repositories()

# Load repositories for example browser definitions.
# You should create your own browser definitions and link
# to the specific browser versions you are interested in
# testing with.
browser_repositories(
    chromium = True,
    firefox = True,
)

Write your tests

Write your test in the language of your choice, but use our provided Browser API to get an instance of WebDriver.

Example Test (Java):

import com.google.testing.web.WebTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.openqa.selenium.WebDriver;

@RunWith(JUnit4.class)
public class BrowserTest {
  private WebDriver driver;

  @Before public void createDriver() {
    driver = new WebTest().newWebDriverSession();
  }

  @After public void quitDriver() {
    try {
      driver.quit();
     } finally {
      driver = null;
     }
   }

  // your tests here
}

Example Test (Go):

import (
    "testing"

    "github.com/tebeka/selenium"
    "github.com/bazelbuild/rules_webtesting/go/webtest"
)

func TestWebApp(t *testing.T) {
    wd, err := webtest.NewWebDriverSession(selenium.Capabilities{})
    if err != nil {
        t.Fatal(err)
    }

    // your test here

    if err := wd.Quit(); err != nil {
        t.Logf("Error quitting webdriver: %v", err)
    }
}

Example Test (Python):

import unittest
from testing.web import webtest


class BrowserTest(unittest.TestCase):
  def setUp(self):
    self.driver = webtest.new_webdriver_session()

  def tearDown(self):
    try:
      self.driver.quit()
    finally:
      self.driver = None

  # Your tests here

if __name__ == "__main__":
  unittest.main()

In your BUILD files, load the correct language specific build rule and create a test target using it:

load("@io_bazel_rules_webtesting//web:py.bzl", "py_web_test_suite")

py_web_test_suite(
    name = "browser_test",
    srcs = ["browser_test.py"],
    browsers = [
        # For experimental purposes only. Eventually you should
        # create your own browser definitions.
        "@io_bazel_rules_webtesting//browsers:chromium-native",
    ],
    local = True,
    deps = ["@io_bazel_rules_webtesting//testing/web"],
)

Directories

Path Synopsis
go
bazel
Package bazel provides utilities for interacting with the surrounding Bazel environment.
Package bazel provides utilities for interacting with the surrounding Bazel environment.
cmdhelper
Package cmdhelper provides functions to make working os/exec Command easier.
Package cmdhelper provides functions to make working os/exec Command easier.
cropper
Package cropper provides an image cropping function.
Package cropper provides an image cropping function.
errors
Package errors provides an Error interface that includes the component name with the underlying error.
Package errors provides an Error interface that includes the component name with the underlying error.
healthreporter
Package healthreporter provides polling wait functions.
Package healthreporter provides polling wait functions.
httphelper
Package httphelper provides simple wrappers for working with HTTP.
Package httphelper provides simple wrappers for working with HTTP.
metadata
Package metadata provides a struct for storing browser metadata.
Package metadata provides a struct for storing browser metadata.
metadata/capabilities
Package capabilities performs operations on maps representing WebDriver capabilities.
Package capabilities performs operations on maps representing WebDriver capabilities.
metadata/main
Binary merger takes multiple metadata files and merges them to produce a single metadata file.
Binary merger takes multiple metadata files and merges them to produce a single metadata file.
portpicker
Package portpicker provides methods for picking unused TCP ports.
Package portpicker provides methods for picking unused TCP ports.
screenshotter
Package screenshotter provides a client-side API for accessing the google/screenshot Web Test Launcher endpoint.
Package screenshotter provides a client-side API for accessing the google/screenshot Web Test Launcher endpoint.
webdriver
Package webdriver provides a simple and incomplete WebDriver client for use by web test launcher.
Package webdriver provides a simple and incomplete WebDriver client for use by web test launcher.
webtest
Package webtest provides WebDriver provisioning and information APIs.
Package webtest provides WebDriver provisioning and information APIs.
wsl
Package wsl implements the basic server code for WSL (Webdriver Server Light), a lightweight replacement for Selenium Server.
Package wsl implements the basic server code for WSL (Webdriver Server Light), a lightweight replacement for Selenium Server.
wsl/driver
Package driver launches a WebDriver driver endpoint binary (e.g.
Package driver launches a WebDriver driver endpoint binary (e.g.
wsl/hub
Package hub launches WebDriver servers and correctly dispatches requests to the correct server based on session id.
Package hub launches WebDriver servers and correctly dispatches requests to the correct server based on session id.
wsl/main
WSL (Webdriver Server Light) is a lightweight replacement for Selenium Server.
WSL (Webdriver Server Light) is a lightweight replacement for Selenium Server.
wsl/resolver
Package resolver resolves WSL, WSLPORT, and WSLENV variables in capabilities.
Package resolver resolves WSL, WSLPORT, and WSLENV variables in capabilities.
wsl/upload
Package files handles file uploads and downloads.
Package files handles file uploads and downloads.
wtl
Binary launcher is used to manage the envrionment for web tests and start the underlying test.
Binary launcher is used to manage the envrionment for web tests and start the underlying test.
wtl/diagnostics
Package diagnostics provides the Diagnostics interface for reporting various test statistics as well as a no-op implementation of the interface.
Package diagnostics provides the Diagnostics interface for reporting various test statistics as well as a no-op implementation of the interface.
wtl/environment
Package environment provides an interface for defining how browser environments are managed.
Package environment provides an interface for defining how browser environments are managed.
wtl/environment/external
Package external works with an externally started WebDriver server located at EXTERNAL_WEBDRIVER_SERVER_ADDRESS.
Package external works with an externally started WebDriver server located at EXTERNAL_WEBDRIVER_SERVER_ADDRESS.
wtl/environment/local
Package local provides a basic environment for web tests locally.
Package local provides a basic environment for web tests locally.
wtl/environment/sauce
Package sauce provides a simple environment for accessing a SauceLabs browser.
Package sauce provides a simple environment for accessing a SauceLabs browser.
wtl/main
Binary launcher is used to manage the envrionment for web tests and start the underlying test.
Binary launcher is used to manage the envrionment for web tests and start the underlying test.
wtl/proxy
Package proxy provides a WebDriver protocol that forwards requests to a WebDriver server provided by an environment.Env.
Package proxy provides a WebDriver protocol that forwards requests to a WebDriver server provided by an environment.Env.
wtl/proxy/driverhub
Package driverhub provides a handler for proxying connections to a Selenium server.
Package driverhub provides a handler for proxying connections to a Selenium server.
wtl/proxy/driverhub/debugger
Package debugger enables WTL Debugger.
Package debugger enables WTL Debugger.
wtl/proxy/driverhub/drivermu
Package drivermu implements a handler that temporally serializes all commands to a session.
Package drivermu implements a handler that temporally serializes all commands to a session.
wtl/proxy/driverhub/googlescreenshot
Package googlescreenshot includes a handler for an advanced screenshot endpoint at POST google/screenshot.
Package googlescreenshot includes a handler for an advanced screenshot endpoint at POST google/screenshot.
wtl/proxy/driverhub/quithandler
Package quithandler checks if a window close command is closing the last window and treats it as a quit if it is.
Package quithandler checks if a window close command is closing the last window and treats it as a quit if it is.
wtl/proxy/driverhub/scripttimeout
Package scripttimeout translates calls to set script timeout into calls on the WebDriver object so it can record the last set script timeout.
Package scripttimeout translates calls to set script timeout into calls on the WebDriver object so it can record the last set script timeout.
wtl/proxy/healthz
Package healthz provides an HTTPHandler that always returns the string "ok".
Package healthz provides an HTTPHandler that always returns the string "ok".
wtl/service
Package service provides the Service interface for managing the life-cycle of a single binary.
Package service provides the Service interface for managing the life-cycle of a single binary.
wtl/service/wsl
Package wsl provides a Service for launching WebDriver Server Light (WSL).
Package wsl provides a Service for launching WebDriver Server Light (WSL).

Jump to

Keyboard shortcuts

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