Skip to content

Latest commit

 

History

History
114 lines (84 loc) · 2.25 KB

README.md

File metadata and controls

114 lines (84 loc) · 2.25 KB

Bazel Web Testing Rules

Build status

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

Configure your Bazel project

For all languages, you need to add the following to your MODULE.bazel file:

bazel_dep(name = "rules_webtesting", version = "0.4.0")

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 Java Test

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 Python Test

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()

Example Go Test

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)
    }
}

BUILD file

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

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

py_web_test_suite(
    name = "browser_test",
    srcs = ["browser_test.py"],
    browsers = [
        "@rules_webtesting//browsers:chromium-local",
    ],
    local = True,
    deps = ["@rules_webtesting//testing/web"],
)