Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bazelbuild/rules_webtesting
Bazel rules to allow testing against a browser with WebDriver.
https://github.com/bazelbuild/rules_webtesting
bazel-rules go java python selenium webdriver
Last synced: 3 days ago
JSON representation
Bazel rules to allow testing against a browser with WebDriver.
- Host: GitHub
- URL: https://github.com/bazelbuild/rules_webtesting
- Owner: bazelbuild
- License: apache-2.0
- Created: 2016-09-09T18:25:37.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-12-20T21:13:06.000Z (29 days ago)
- Last Synced: 2025-01-09T14:27:07.924Z (10 days ago)
- Topics: bazel-rules, go, java, python, selenium, webdriver
- Language: Go
- Homepage:
- Size: 1.16 MB
- Stars: 97
- Watchers: 13
- Forks: 56
- Open Issues: 37
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
- Codeowners: CODEOWNERS
- Authors: AUTHORS
Awesome Lists containing this project
- awesome-golang-repositories - rules_webtesting
- awesome-bazel - WebDriver
README
# Bazel Web Testing Rules
[![Build status](https://badge.buildkite.com/d9c3974f925876394ca9d3e00670c0950b6f7ebf325412def7.svg?branch=master)](https://buildkite.com/bazel/rules-webtesting-saucelabs)
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:
```bzl
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
```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 Python Test
```python
import unittest
from testing.web import webtestclass 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
```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)
}
}
```### BUILD file
In your BUILD files, load the correct language specific build rule and create a
test target using it:```bzl
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"],
)
```