Bazel rules and supporting code to allow testing against a browser with WebDriver.
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 test in the language of your choice, but use our provided Browser API to get an instance of WebDriver.
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
}
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()
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)
}
}
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"],
)