This is a Selenium client for Go. It supports the WebDriver protocol and has been tested on Selenium WebDriver and ChromeDriver.
selenium
is currently maintained by Eric Garrido (@minusnine).
Run
go get github.com/tebeka/selenium
Docs are at https://godoc.org/github.com/tebeka/selenium
GetHTTPClient
exposes the HTTP client used by the driver. You can access it to
add the request context.
func myRequestHandler(w http.ResponseWriter, r *http.Request) {
selenium.GetHTTPClient().Transport = &urlfetch.Transport{
Context: appengine.NewContext(r),
Deadline: 30 * time.Second,
}
...
}
Thanks to bthomson for this one.
- Finish full Selenium API.
- SauceLabs integration
- Add usage examples
- Support Firefox profiles
- Test Chrome interaction on Travis. Currently, only Firefox is tested.
- Any additional TODOs marked in the code.
- Allow testing on Windows and OS X.
- Selenium 2 does not support versions of Firefox newer than 47.0.2.
- Geckodriver GetAllCookies does not return the expiration date of the cookie.
- Selenium 3 NewSession does not implement the W3C-specified parameters.
- Selenium 3 NewSession does not support Firefox capabilities.
- Marionnette does not implement the actions API, which is needed for keyboard and mouse actions, among others. Then, Geckodriver doesn't implement this support. Then, Selenium 3 doesn't implement this support for Firefox.
The Geckodriver team recommends using the newest available Firefox version, as the integration is actively being developed.
ChromeDriver has not yet implemented the nascent W3C standard. So far, this only means that GetCookie is not available for Chrome.
Patches are encouraged through GitHub pull requests. Please ensure that a test is added for anything more than a trivial change and that the existing tests pass.
First, download the ChromeDriver binary, the Firefox binary and the Selenium WebDriver JARs:
$ cd vendor
$ go run init.go
$ cd ..
You only have to do this once initially and later when version numbers in init.go change.
Ensure that the chromium
binary is in your path. If the binary is named
differently, run the tests with the flags --chrome_binary=<binary name>
.
Run the tests:
$ go test
-
There is one top-level test for each of:
- Chromium and ChromeDriver.
- A new version of Firefox and Selenium 3.
- An old version of Firefox and Selenium 2
There are subtests that are shared between both top-level tests.
-
To run only one of the top-level tests, pass
-test.run=TestFirefoxSelenium2
,-test.run=TestFirefoxSelenium3
, or-test.run=TestChrome
. To run a specific subtest, pass-test.run=Test<Browser>/<subtest>
as appropriate. This flag supports regular expressions. -
If the Chrome or Firefox binaries, the Selenium JAR, the Geckodriver binary, or the ChromeDriver binary cannot be found, the corresponding tests will be skipped.
-
The binaries and JAR under test can be configured by passing flags to
go test
. See the available flags withgo test --arg --help
. -
Add the argument
-test.v
to see detailed output from Selenium and the browsers.
You will need an installed and running Docker system.
To run the tests under Docker, run:
$ go test --docker
This will create a new Docker container and run the tests in it. (Note: flags
supplied to this invocation are not curried through to the go test
invocation
within the Docker container).
For debugging docker directly, run the following commands:
$ docker build -t go-selenium testing/
$ docker run --volume=${GOPATH?}:/code --workdir=/code/src/github.com/tebeka/selenium -it go-selenium bash
This project is licensed under the MIT license.