Skip to content

Commit

Permalink
Make rules_webtesting lighter weight: (#321)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
DrMarcII authored Jan 9, 2019
1 parent 239b491 commit 1f430d5
Show file tree
Hide file tree
Showing 18 changed files with 727 additions and 425 deletions.
213 changes: 107 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,118 +7,117 @@ WebDriver.

## Configure your Bazel project

Add the following to your WORKSPACE file:
For all languages, you need to add the following to your WORKSPACE file:

```bzl
# Load rules_go at master for example purposes only. You should specify
# a specific version in your project.
http_archive(
name = "io_bazel_rules_go",
strip_prefix = "rules_go-master",
urls = [
"https://github.com/bazelbuild/rules_go/archive/master.tar.gz",
],
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Load rules_webtesting at master for example purposes only. You should specify
# a specific version in your project.
http_archive(
name = "io_bazel_rules_webtesting",
strip_prefix = "rules_webtesting-master",
sha256 = "<version-specific-sha>",
urls = [
"https://github.com/bazelbuild/rules_webtesting/archive/master.tar.gz",
https://github.com/bazelbuild/rules_webtesting/releases/download/<version>/rules_webtesting.tar.gz
],
)

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

web_test_repositories()
```

platform_http_file(
name = "org_chromium_chromium",
licenses = ["notice"], # BSD 3-clause (maybe more?)
amd64_sha256 =
"6933d0afce6e17304b62029fbbd246cbe9e130eb0d90d7682d3765d3dbc8e1c8",
amd64_urls = [
"https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/561732/chrome-linux.zip",
],
macos_sha256 =
"084884e91841a923d7b6e81101f0105bbc3b0026f9f6f7a3477f5b313ee89e32",
macos_urls = [
"https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/561733/chrome-mac.zip",
],
windows_sha256 =
"d1bb728118c12ea436d8ea07dba980789e7d860aa664dd1fad78bc20e8d9391c",
windows_urls = [
"https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win_x64/540270/chrome-win32.zip",
],
)
You can use the predefined browsers in `@io_bazel_rules_webtesting//browsers` by
adding:

platform_http_file(
name = "org_chromium_chromedriver",
licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT
amd64_sha256 =
"71eafe087900dbca4bc0b354a1d172df48b31a4a502e21f7c7b156d7e76c95c7",
amd64_urls = [
"https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip",
],
macos_sha256 =
"fd32a27148f44796a55f5ce3397015c89ebd9f600d9dda2bcaca54575e2497ae",
macos_urls = [
"https://chromedriver.storage.googleapis.com/2.41/chromedriver_mac64.zip",
],
windows_sha256 =
"a8fa028acebef7b931ef9cb093f02865f9f7495e49351f556e919f7be77f072e",
windows_urls = [
"https://chromedriver.storage.googleapis.com/2.38/chromedriver_win32.zip",
```bzl
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories")

browser_repositories(chrome=True, firefox=True)
```

Then you should add the appropriate dependencies depending on what language you
are writing your tests in:

### Java

```bzl
load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "java_repositories")

java_repositories()
```

### Scala

```bzl
load("@io_bazel_rules_webtesting//web:java_repositories.bzl", "java_repositories")

java_repositories()

http_archive(
name = "io_bazel_rules_scala",
sha256 = "6c69597f373a01989b9f7119bd5d28cffc9cc35d44d1f6440c409d8ef420057d",
strip_prefix = "rules_scala-da5ba6d97a1abdadef89d509b30a9dcfde7ffbe4",
urls = [
"https://github.com/bazelbuild/rules_scala/archive/da5ba6d97a1abdadef89d509b30a9dcfde7ffbe4.tar.gz",
],
)

platform_http_file(
name = "org_mozilla_firefox",
licenses = ["reciprocal"], # MPL 2.0
amd64_sha256 =
"3a729ddcb1e0f5d63933177a35177ac6172f12edbf9fbbbf45305f49333608de",
amd64_urls = [
"https://mirror.bazel.build/ftp.mozilla.org/pub/firefox/releases/61.0.2/linux-x86_64/en-US/firefox-61.0.2.tar.bz2",
"https://ftp.mozilla.org/pub/firefox/releases/61.0.2/linux-x86_64/en-US/firefox-61.0.2.tar.bz2",
],
macos_sha256 =
"bf23f659ae34832605dd0576affcca060d1077b7bf7395bc9874f62b84936dc5",
macos_urls = [
"https://mirror.bazel.build/ftp.mozilla.org/pub/firefox/releases/61.0.2/mac/en-US/Firefox%2061.0.2.dmg",
"https://ftp.mozilla.org/pub/firefox/releases/61.0.2/mac/en-US/Firefox%2061.0.2.dmg",
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")

scala_repositories()

load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")

scala_register_toolchains()
```

### Python

```bzl
load("@io_bazel_rules_webtesting//web:py_repositories.bzl", "py_repositories")

py_repositories()
```

### Go

```bzl
http_archive(
name = "io_bazel_rules_go",
sha256 = "b7a62250a3a73277ade0ce306d22f122365b513f5402222403e507f2f997d421",
urls = [
"https://github.com/bazelbuild/rules_go/releases/download/0.16.3/rules_go-0.16.3.tar.gz",
],
)

platform_http_file(
name = "org_mozilla_geckodriver",
licenses = ["reciprocal"], # MPL 2.0
amd64_sha256 =
"c9ae92348cf00aa719be6337a608fae8304691a95668e8e338d92623ba9e0ec6",
amd64_urls = [
"https://mirror.bazel.build/github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz",
"https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz",
],
macos_sha256 =
"ce4a3e9d706db94e8760988de1ad562630412fa8cf898819572522be584f01ce",
macos_urls = [
"https://mirror.bazel.build/github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-macos.tar.gz",
"https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-macos.tar.gz",
http_archive(
name = "bazel_gazelle",
sha256 = "6e875ab4b6bf64a38c352887760f21203ab054676d9c1b274963907e0768740d",
urls = [
"https://github.com/bazelbuild/bazel-gazelle/releases/download/0.15.0/bazel-gazelle-0.15.0.tar.gz",
],
)

load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

load("@io_bazel_rules_webtesting//web:go_repositories.bzl", "go_repositories")

go_repositories()
```

## 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 Test (Java):
### Example Java Test

```java
import com.google.testing.web.WebTest;
Expand Down Expand Up @@ -147,7 +146,30 @@ public class BrowserTest {
}
```

Example Test (Go):
### Example Python Test

```python
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

```go
import (
Expand All @@ -171,28 +193,7 @@ func TestWebApp(t *testing.T) {
}
```

Example Test (Python):

```python
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()
```
### BUILD file

In your BUILD files, load the correct language specific build rule and create a
test target using it:
Expand Down
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ browser_repositories(
sauce = True,
)

load("//web:go_repositories.bzl", "go_repositories", "go_internal_repositories")

go_repositories()

go_internal_repositories()

load("//web:java_repositories.bzl", "java_repositories")

java_repositories()

load("//web:py_repositories.bzl", "py_repositories")

py_repositories()

http_archive(
name = "io_bazel_rules_scala",
sha256 = "6c69597f373a01989b9f7119bd5d28cffc9cc35d44d1f6440c409d8ef420057d",
Expand Down
29 changes: 29 additions & 0 deletions build_files/metadata.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
#
package(default_testonly = True)

licenses(["notice"]) # Apache 2.0

alias(
name = "main",
actual = select({
"//common/conditions:linux": "linux_amd64_stripped/main",
"//common/conditions:mac": "darwin_amd64_pure_stripped/main",
"//common/conditions:windows": "windows_amd64_pure_stripped/main.exe",
}),
visibility = ["//visibility:public"],
)
32 changes: 32 additions & 0 deletions build_files/wsl.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
#
load("//web:web.bzl", "web_test_named_executable")

package(default_testonly = True)

licenses(["notice"]) # Apache 2.0

web_test_named_executable(
name = "wsl",
alt_name = "WEBDRIVER_SERVER_LIGHT",
executable = select({
"//common/conditions:linux": "main/linux_amd64_stripped/main",
"//common/conditions:mac": "main/darwin_amd64_pure_stripped/main",
"//common/conditions:windows": "main/windows_amd64_pure_stripped/main.exe",
}),
visibility = ["//visibility:public"],
)
29 changes: 29 additions & 0 deletions build_files/wtl.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
#
package(default_testonly = True)

licenses(["notice"]) # Apache 2.0

alias(
name = "main",
actual = select({
"//common/conditions:linux": "linux_amd64_stripped/main",
"//common/conditions:mac": "darwin_amd64_pure_stripped/main",
"//common/conditions:windows": "windows_amd64_pure_stripped/main.exe",
}),
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion common/conditions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
package(
default_testonly = True,
default_visibility = ["//third_party:__subpackages__"],
default_visibility = ["//:__subpackages__"],
)

config_setting(
Expand Down
Loading

0 comments on commit 1f430d5

Please sign in to comment.