Skip to content

Commit 1f430d5

Browse files
authored
Make rules_webtesting lighter weight: (#321)
- Add release script that creates a release version where: - Go binaries are precompiled - Most Go code is removed - Add separate rules for loading only language-specific repositories. Fixes #319
1 parent 239b491 commit 1f430d5

18 files changed

+727
-425
lines changed

README.md

Lines changed: 107 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -7,118 +7,117 @@ WebDriver.
77

88
## Configure your Bazel project
99

10-
Add the following to your WORKSPACE file:
10+
For all languages, you need to add the following to your WORKSPACE file:
1111

1212
```bzl
13-
# Load rules_go at master for example purposes only. You should specify
14-
# a specific version in your project.
15-
http_archive(
16-
name = "io_bazel_rules_go",
17-
strip_prefix = "rules_go-master",
18-
urls = [
19-
"https://github.com/bazelbuild/rules_go/archive/master.tar.gz",
20-
],
21-
)
22-
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
23-
go_rules_dependencies()
24-
go_register_toolchains()
13+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2514

26-
# Load rules_webtesting at master for example purposes only. You should specify
27-
# a specific version in your project.
2815
http_archive(
2916
name = "io_bazel_rules_webtesting",
30-
strip_prefix = "rules_webtesting-master",
17+
sha256 = "<version-specific-sha>",
3118
urls = [
32-
"https://github.com/bazelbuild/rules_webtesting/archive/master.tar.gz",
19+
https://github.com/bazelbuild/rules_webtesting/releases/download/<version>/rules_webtesting.tar.gz
3320
],
3421
)
3522

3623
load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")
37-
load("@io_bazel_rules_webtesting//web/internal:platform_http_file.bzl", "platform_http_file")
3824

3925
web_test_repositories()
26+
```
4027

41-
platform_http_file(
42-
name = "org_chromium_chromium",
43-
licenses = ["notice"], # BSD 3-clause (maybe more?)
44-
amd64_sha256 =
45-
"6933d0afce6e17304b62029fbbd246cbe9e130eb0d90d7682d3765d3dbc8e1c8",
46-
amd64_urls = [
47-
"https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/561732/chrome-linux.zip",
48-
],
49-
macos_sha256 =
50-
"084884e91841a923d7b6e81101f0105bbc3b0026f9f6f7a3477f5b313ee89e32",
51-
macos_urls = [
52-
"https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/561733/chrome-mac.zip",
53-
],
54-
windows_sha256 =
55-
"d1bb728118c12ea436d8ea07dba980789e7d860aa664dd1fad78bc20e8d9391c",
56-
windows_urls = [
57-
"https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win_x64/540270/chrome-win32.zip",
58-
],
59-
)
28+
You can use the predefined browsers in `@io_bazel_rules_webtesting//browsers` by
29+
adding:
6030

61-
platform_http_file(
62-
name = "org_chromium_chromedriver",
63-
licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT
64-
amd64_sha256 =
65-
"71eafe087900dbca4bc0b354a1d172df48b31a4a502e21f7c7b156d7e76c95c7",
66-
amd64_urls = [
67-
"https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip",
68-
],
69-
macos_sha256 =
70-
"fd32a27148f44796a55f5ce3397015c89ebd9f600d9dda2bcaca54575e2497ae",
71-
macos_urls = [
72-
"https://chromedriver.storage.googleapis.com/2.41/chromedriver_mac64.zip",
73-
],
74-
windows_sha256 =
75-
"a8fa028acebef7b931ef9cb093f02865f9f7495e49351f556e919f7be77f072e",
76-
windows_urls = [
77-
"https://chromedriver.storage.googleapis.com/2.38/chromedriver_win32.zip",
31+
```bzl
32+
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories")
33+
34+
browser_repositories(chrome=True, firefox=True)
35+
```
36+
37+
Then you should add the appropriate dependencies depending on what language you
38+
are writing your tests in:
39+
40+
### Java
41+
42+
```bzl
43+
load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "java_repositories")
44+
45+
java_repositories()
46+
```
47+
48+
### Scala
49+
50+
```bzl
51+
load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "java_repositories")
52+
53+
java_repositories()
54+
55+
http_archive(
56+
name = "io_bazel_rules_scala",
57+
sha256 = "6c69597f373a01989b9f7119bd5d28cffc9cc35d44d1f6440c409d8ef420057d",
58+
strip_prefix = "rules_scala-da5ba6d97a1abdadef89d509b30a9dcfde7ffbe4",
59+
urls = [
60+
"https://github.com/bazelbuild/rules_scala/archive/da5ba6d97a1abdadef89d509b30a9dcfde7ffbe4.tar.gz",
7861
],
7962
)
8063

81-
platform_http_file(
82-
name = "org_mozilla_firefox",
83-
licenses = ["reciprocal"], # MPL 2.0
84-
amd64_sha256 =
85-
"3a729ddcb1e0f5d63933177a35177ac6172f12edbf9fbbbf45305f49333608de",
86-
amd64_urls = [
87-
"https://mirror.bazel.build/ftp.mozilla.org/pub/firefox/releases/61.0.2/linux-x86_64/en-US/firefox-61.0.2.tar.bz2",
88-
"https://ftp.mozilla.org/pub/firefox/releases/61.0.2/linux-x86_64/en-US/firefox-61.0.2.tar.bz2",
89-
],
90-
macos_sha256 =
91-
"bf23f659ae34832605dd0576affcca060d1077b7bf7395bc9874f62b84936dc5",
92-
macos_urls = [
93-
"https://mirror.bazel.build/ftp.mozilla.org/pub/firefox/releases/61.0.2/mac/en-US/Firefox%2061.0.2.dmg",
94-
"https://ftp.mozilla.org/pub/firefox/releases/61.0.2/mac/en-US/Firefox%2061.0.2.dmg",
64+
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
65+
66+
scala_repositories()
67+
68+
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
69+
70+
scala_register_toolchains()
71+
```
72+
73+
### Python
74+
75+
```bzl
76+
load("@io_bazel_rules_webtesting//web:py_repositories.bzl", "py_repositories")
77+
78+
py_repositories()
79+
```
80+
81+
### Go
82+
83+
```bzl
84+
http_archive(
85+
name = "io_bazel_rules_go",
86+
sha256 = "b7a62250a3a73277ade0ce306d22f122365b513f5402222403e507f2f997d421",
87+
urls = [
88+
"https://github.com/bazelbuild/rules_go/releases/download/0.16.3/rules_go-0.16.3.tar.gz",
9589
],
9690
)
9791

98-
platform_http_file(
99-
name = "org_mozilla_geckodriver",
100-
licenses = ["reciprocal"], # MPL 2.0
101-
amd64_sha256 =
102-
"c9ae92348cf00aa719be6337a608fae8304691a95668e8e338d92623ba9e0ec6",
103-
amd64_urls = [
104-
"https://mirror.bazel.build/github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz",
105-
"https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz",
106-
],
107-
macos_sha256 =
108-
"ce4a3e9d706db94e8760988de1ad562630412fa8cf898819572522be584f01ce",
109-
macos_urls = [
110-
"https://mirror.bazel.build/github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-macos.tar.gz",
111-
"https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-macos.tar.gz",
92+
http_archive(
93+
name = "bazel_gazelle",
94+
sha256 = "6e875ab4b6bf64a38c352887760f21203ab054676d9c1b274963907e0768740d",
95+
urls = [
96+
"https://github.com/bazelbuild/bazel-gazelle/releases/download/0.15.0/bazel-gazelle-0.15.0.tar.gz",
11297
],
11398
)
99+
100+
load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")
101+
102+
go_rules_dependencies()
103+
104+
go_register_toolchains()
105+
106+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
107+
108+
gazelle_dependencies()
109+
110+
load("@io_bazel_rules_webtesting//web:go_repositories.bzl", "go_repositories")
111+
112+
go_repositories()
114113
```
115114

116115
## Write your tests
117116

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

121-
Example Test (Java):
120+
### Example Java Test
122121

123122
```java
124123
import com.google.testing.web.WebTest;
@@ -147,7 +146,30 @@ public class BrowserTest {
147146
}
148147
```
149148

150-
Example Test (Go):
149+
### Example Python Test
150+
151+
```python
152+
import unittest
153+
from testing.web import webtest
154+
155+
156+
class BrowserTest(unittest.TestCase):
157+
def setUp(self):
158+
self.driver = webtest.new_webdriver_session()
159+
160+
def tearDown(self):
161+
try:
162+
self.driver.quit()
163+
finally:
164+
self.driver = None
165+
166+
# Your tests here
167+
168+
if __name__ == "__main__":
169+
unittest.main()
170+
```
171+
172+
### Example Go Test
151173

152174
```go
153175
import (
@@ -171,28 +193,7 @@ func TestWebApp(t *testing.T) {
171193
}
172194
```
173195

174-
Example Test (Python):
175-
176-
```python
177-
import unittest
178-
from testing.web import webtest
179-
180-
181-
class BrowserTest(unittest.TestCase):
182-
def setUp(self):
183-
self.driver = webtest.new_webdriver_session()
184-
185-
def tearDown(self):
186-
try:
187-
self.driver.quit()
188-
finally:
189-
self.driver = None
190-
191-
# Your tests here
192-
193-
if __name__ == "__main__":
194-
unittest.main()
195-
```
196+
### BUILD file
196197

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

WORKSPACE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ browser_repositories(
7171
sauce = True,
7272
)
7373

74+
load("//web:go_repositories.bzl", "go_repositories", "go_internal_repositories")
75+
76+
go_repositories()
77+
78+
go_internal_repositories()
79+
80+
load("//web:java_repositories.bzl", "java_repositories")
81+
82+
java_repositories()
83+
84+
load("//web:py_repositories.bzl", "py_repositories")
85+
86+
py_repositories()
87+
7488
http_archive(
7589
name = "io_bazel_rules_scala",
7690
sha256 = "6c69597f373a01989b9f7119bd5d28cffc9cc35d44d1f6440c409d8ef420057d",

build_files/metadata.BUILD

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2019 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
#
17+
package(default_testonly = True)
18+
19+
licenses(["notice"]) # Apache 2.0
20+
21+
alias(
22+
name = "main",
23+
actual = select({
24+
"//common/conditions:linux": "linux_amd64_stripped/main",
25+
"//common/conditions:mac": "darwin_amd64_pure_stripped/main",
26+
"//common/conditions:windows": "windows_amd64_pure_stripped/main.exe",
27+
}),
28+
visibility = ["//visibility:public"],
29+
)

build_files/wsl.BUILD

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2019 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
#
17+
load("//web:web.bzl", "web_test_named_executable")
18+
19+
package(default_testonly = True)
20+
21+
licenses(["notice"]) # Apache 2.0
22+
23+
web_test_named_executable(
24+
name = "wsl",
25+
alt_name = "WEBDRIVER_SERVER_LIGHT",
26+
executable = select({
27+
"//common/conditions:linux": "main/linux_amd64_stripped/main",
28+
"//common/conditions:mac": "main/darwin_amd64_pure_stripped/main",
29+
"//common/conditions:windows": "main/windows_amd64_pure_stripped/main.exe",
30+
}),
31+
visibility = ["//visibility:public"],
32+
)

build_files/wtl.BUILD

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2019 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
#
17+
package(default_testonly = True)
18+
19+
licenses(["notice"]) # Apache 2.0
20+
21+
alias(
22+
name = "main",
23+
actual = select({
24+
"//common/conditions:linux": "linux_amd64_stripped/main",
25+
"//common/conditions:mac": "darwin_amd64_pure_stripped/main",
26+
"//common/conditions:windows": "windows_amd64_pure_stripped/main.exe",
27+
}),
28+
visibility = ["//visibility:public"],
29+
)

common/conditions/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
package(
1818
default_testonly = True,
19-
default_visibility = ["//third_party:__subpackages__"],
19+
default_visibility = ["//:__subpackages__"],
2020
)
2121

2222
config_setting(

0 commit comments

Comments
 (0)