2014-09-12 16:14:24 +00:00
# Using Selenium and WebDriver
2014-09-12 16:07:21 +00:00
2015-03-04 13:59:27 +00:00
From [ChromeDriver - WebDriver for Chrome][chrome-driver]:
2014-09-12 16:07:21 +00:00
> WebDriver is an open source tool for automated testing of web apps across many
> browsers. It provides capabilities for navigating to web pages, user input,
> JavaScript execution, and more. ChromeDriver is a standalone server which
> implements WebDriver's wire protocol for Chromium. It is being developed by
> members of the Chromium and WebDriver teams.
2015-04-16 03:31:12 +00:00
In Electron's [releases ](https://github.com/atom/electron/releases ) page you
can find archives of `chromedriver` , there is no difference between Electron's
2014-09-12 16:07:21 +00:00
distribution of `chromedriver` and upstream ones, so in order to use
2015-04-16 03:31:12 +00:00
`chromedriver` together with Electron, you will need some special setup.
2014-09-12 16:07:21 +00:00
2014-09-20 14:39:52 +00:00
Also notice that only minor version update releases (e.g. `vX.X.0` releases)
include `chromedriver` archives, because `chromedriver` doesn't change as
2015-04-16 03:31:12 +00:00
frequent as Electron itself.
2014-09-20 14:39:52 +00:00
2014-09-12 16:07:21 +00:00
## Setting up with WebDriverJs
[WebDriverJs ](https://code.google.com/p/selenium/wiki/WebDriverJs ) provided
a Node package for testing with web driver, we will use it as an example.
### 1. Start chrome driver
First you need to download the `chromedriver` binary, and run it:
```bash
$ ./chromedriver
Starting ChromeDriver (v2.10.291558) on port 9515
Only local connections are allowed.
```
Remember the port number `9515` , which will be used later
### 2. Install WebDriverJS
```bash
$ npm install selenium-webdriver
```
### 3. Connect to chrome driver
2015-04-16 03:31:12 +00:00
The usage of `selenium-webdriver` with Electron is basically the same with
2014-09-12 16:07:21 +00:00
upstream, except that you have to manually specify how to connect chrome driver
2015-04-16 03:31:12 +00:00
and where to find Electron's binary:
2014-09-12 16:07:21 +00:00
```javascript
var webdriver = require('selenium-webdriver');
2015-06-09 16:18:47 +00:00
var driver = new webdriver.Builder()
// The "9515" is the port opened by chrome driver.
.usingServer('http://localhost:9515')
.withCapabilities({chromeOptions: {
// Here is the path to your Electron binary.
binary: '/Path-to-Your-App.app/Contents/MacOS/Atom'}})
.forBrowser('electron')
.build();
2014-09-12 16:07:21 +00:00
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
```
2015-06-09 09:29:47 +00:00
## Workflow
To test your application without rebuilding Electron, simply [place ](https://github.com/atom/electron/blob/master/docs/tutorial/application-distribution.md ) your app source into Electron's resource directory.
2015-03-04 13:59:27 +00:00
[chrome-driver]: https://sites.google.com/a/chromium.org/chromedriver/
2015-06-09 09:29:47 +00:00