Skip to content

Commit

Permalink
Merge pull request electron#5575 from electron/link-to-spectron
Browse files Browse the repository at this point in the history
Add spectron to ChromeDriver doc
  • Loading branch information
zcbenz committed May 18, 2016
2 parents 397d0e3 + b301c47 commit 5368da1
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions docs/tutorial/using-selenium-and-webdriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,45 @@ From [ChromeDriver - WebDriver for Chrome][chrome-driver]:
> implements WebDriver's wire protocol for Chromium. It is being developed by
> members of the Chromium and WebDriver teams.
In order to use `chromedriver` with Electron you have to tell it where to
find Electron and make it think Electron is the Chrome browser.
## Setting up Spectron

[Spectron][spectron] is the officially supported ChromeDriver testing framework
for Electron. It is built on top of [WebdriverIO](http://webdriver.io/) and
has helpers to access Electron APIs in your tests and bundles ChromeDriver.

```bash
$ npm install --save-dev spectron
```

```js
// A simple test to verify a visible window is opened with a title
var Application = require('spectron').Application
var assert = require('assert')

var app = new Application({
path: '/Applications/MyApp.app/Contents/MacOS/MyApp'
})

app.start().then(function () {
// Check if the window is visible
return app.browserWindow.isVisible()
}).then(function (isVisible) {
// Verify the window is visible
assert.equal(isVisible, true)
}).then(function () {
// Get the window's title
return app.client.getTitle()
}).then(function (title) {
// Verify the window's title
assert.equal(title, 'My App')
}).then(function () {
// Stop the application
return app.stop()
}).catch(function (error) {
// Log any failures
console.error('Test failed', error.message)
})
```

## Setting up with WebDriverJs

Expand All @@ -21,7 +58,8 @@ a Node package for testing with web driver, we will use it as an example.
First you need to download the `chromedriver` binary, and run it:

```bash
$ ./chromedriver
$ npm install electron-chromedriver
$ ./node_modules/.bin/chromedriver
Starting ChromeDriver (v2.10.291558) on port 9515
Only local connections are allowed.
```
Expand Down Expand Up @@ -77,7 +115,8 @@ driver.
First you need to download the `chromedriver` binary, and run it:

```bash
$ chromedriver --url-base=wd/hub --port=9515
$ npm install electron-chromedriver
$ ./node_modules/.bin/chromedriver --url-base=wd/hub --port=9515
Starting ChromeDriver (v2.10.291558) on port 9515
Only local connections are allowed.
```
Expand Down Expand Up @@ -130,3 +169,4 @@ your app's folder. This eliminates the need to copy-paste your app into
Electron's resource directory.

[chrome-driver]: https://sites.google.com/a/chromium.org/chromedriver/
[spectron]: http://electron.atom.io/spectron

0 comments on commit 5368da1

Please sign in to comment.