@@ -7,118 +7,117 @@ WebDriver.
7
7
8
8
## Configure your Bazel project
9
9
10
- Add the following to your WORKSPACE file:
10
+ For all languages, you need to add the following to your WORKSPACE file:
11
11
12
12
``` 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" )
25
14
26
- # Load rules_webtesting at master for example purposes only. You should specify
27
- # a specific version in your project.
28
15
http_archive(
29
16
name = " io_bazel_rules_webtesting" ,
30
- strip_prefix = " rules_webtesting-master " ,
17
+ sha256 = " <version-specific-sha> " ,
31
18
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
33
20
],
34
21
)
35
22
36
23
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" )
38
24
39
25
web_test_repositories()
26
+ ```
40
27
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:
60
30
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" ,
78
61
],
79
62
)
80
63
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" ,
95
89
],
96
90
)
97
91
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" ,
112
97
],
113
98
)
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()
114
113
```
115
114
116
115
## Write your tests
117
116
118
117
Write your test in the language of your choice, but use our provided Browser API
119
118
to get an instance of WebDriver.
120
119
121
- Example Test ( Java):
120
+ ### Example Java Test
122
121
123
122
``` java
124
123
import com.google.testing.web.WebTest ;
@@ -147,7 +146,30 @@ public class BrowserTest {
147
146
}
148
147
```
149
148
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
151
173
152
174
``` go
153
175
import (
@@ -171,28 +193,7 @@ func TestWebApp(t *testing.T) {
171
193
}
172
194
```
173
195
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
196
197
197
198
In your BUILD files, load the correct language specific build rule and create a
198
199
test target using it:
0 commit comments