Comparing version 0.33.1 to 0.33.2
@@ -0,3 +1,5 @@ | ||
var ChromeDriver = require('./chrome-driver') | ||
var DevNull = require('dev-null') | ||
var path = require('path') | ||
var WebDriver = require('webdriverio') | ||
var ChromeDriver = require('./chrome-driver') | ||
@@ -12,2 +14,3 @@ function Application (options) { | ||
this.args = options.args || [] | ||
this.env = options.env || {} | ||
} | ||
@@ -28,2 +31,5 @@ | ||
var self = this | ||
if (!self.client) throw new Error('Application not started') | ||
return new Promise(function (resolve, reject) { | ||
@@ -56,2 +62,12 @@ self.client.quitApplication().then(function () { | ||
Application.prototype.createClient = function (callback) { | ||
var args = [] | ||
args.push('spectron-path=' + this.path) | ||
this.args.forEach(function (arg, index) { | ||
args.push('spectron-arg' + index + '=' + arg) | ||
}) | ||
for (var name in this.env) { | ||
args.push('spectron-env-' + name + '=' + this.env[name]) | ||
} | ||
var options = { | ||
@@ -63,18 +79,12 @@ host: this.host, | ||
chromeOptions: { | ||
binary: this.path, | ||
args: this.args | ||
binary: path.join(__dirname, 'launcher.js'), | ||
args: args | ||
} | ||
} | ||
}, | ||
logOutput: DevNull() | ||
} | ||
var self = this | ||
self.client = WebDriver.remote(options) | ||
self.addCommands() | ||
self.client.init().then(function () { callback() }) | ||
self.client.on('error', function (error) { | ||
console.error('Client Error', error.message) | ||
self.client.end().then(function () { | ||
self.chromeDriver.stop() | ||
}) | ||
}) | ||
this.client = WebDriver.remote(options) | ||
this.addCommands() | ||
this.client.init().then(function () { callback() }) | ||
} | ||
@@ -100,2 +110,14 @@ | ||
this.client.addCommand('getWindowWidth', function () { | ||
return this.getWindowDimensions().then(function (dimensions) { | ||
return dimensions.width | ||
}) | ||
}) | ||
this.client.addCommand('getWindowHeight', function () { | ||
return this.getWindowDimensions().then(function (dimensions) { | ||
return dimensions.height | ||
}) | ||
}) | ||
this.client.addCommand('setWindowDimensions', function (x, y, width, height) { | ||
@@ -138,2 +160,8 @@ return this.execute(function (x, y, width, height) { | ||
this.client.addCommand('getWindowCount', function () { | ||
return this.windowHandles().then(function (response) { | ||
return response.value.length | ||
}) | ||
}) | ||
this.addCurrentWindowGetter('isDevToolsOpened', 'isWindowDevToolsOpened') | ||
@@ -140,0 +168,0 @@ this.addCurrentWindowGetter('isFocused', 'isWindowFocused') |
{ | ||
"name": "spectron", | ||
"version": "0.33.1", | ||
"version": "0.33.2", | ||
"description": "Easy ChromeDriver tests for Electron apps", | ||
@@ -29,2 +29,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"dev-null": "^0.1.1", | ||
"electron-chromedriver": "^0.33.4", | ||
@@ -34,2 +35,4 @@ "webdriverio": "^3.2.5" | ||
"devDependencies": { | ||
"chai": "^3.3.0", | ||
"chai-as-promised": "^5.1.0", | ||
"electron-prebuilt": "^0.33.7", | ||
@@ -36,0 +39,0 @@ "mocha": "^2.3.3", |
226
README.md
@@ -5,6 +5,16 @@ # spectron | ||
[![Build Status](https://travis-ci.org/kevinsawicki/spectron.svg?branch=master)](https://travis-ci.org/kevinsawicki/spectron) | ||
[![devDependencies:?](https://img.shields.io/david/kevinsawicki/spectron.svg)](https://david-dm.org/kevinsawicki/spectron) | ||
<br> | ||
[![license:mit](https://img.shields.io/badge/license-mit-blue.svg)](https://opensource.org/licenses/MIT) | ||
[![npm:](https://img.shields.io/npm/v/spectron.svg)](https://www.npmjs.com/packages/spectron) | ||
[![dependencies:?](https://img.shields.io/npm/dm/spectron.svg)](https://www.npmjs.com/packages/spectron) | ||
Easily test your [Electron](http://electron.atom.io) apps using [ChromeDriver](https://code.google.com/p/selenium/wiki/ChromeDriver) | ||
and [webdriverio](http://webdriver.io). | ||
Easily test your [Electron](http://electron.atom.io) apps using | ||
[ChromeDriver](https://code.google.com/p/selenium/wiki/ChromeDriver) and | ||
[WebdriverIO](http://webdriver.io). | ||
This minor version of this library tracks the minor version of the Electron | ||
versions released. So if you are using Electron `0.33.x` you would want to use | ||
a `spectron` dependency of `^0.33` in your `package.json` file. | ||
## Using | ||
@@ -17,3 +27,3 @@ | ||
Spectron works with any testing framework but the following example uses | ||
[mocha](https://mochajs.org). | ||
[mocha](https://mochajs.org): | ||
@@ -24,23 +34,20 @@ ```js | ||
describe('application loading', function () { | ||
describe('application launch', function () { | ||
this.timeout(10000) | ||
var app = null | ||
beforeEach(function (done) { | ||
app = new Application({ | ||
beforeEach(function () { | ||
this.app = new Application({ | ||
path: '/Applications/MyApp.app/Contents/MacOS/MyApp' | ||
}) | ||
app.start().then(done, done) | ||
return this.app.start() | ||
}) | ||
afterEach(function (done) { | ||
app.stop().then(done, done) | ||
app = null | ||
afterEach(function () { | ||
return this.app.stop() | ||
}) | ||
it('launches the application and shows an initial window', function (done) { | ||
app.client.windowHandles().then(function (response) { | ||
assert.equal(response.value.length, 1) | ||
}).then(done, done) | ||
it('shows an initial window', function () { | ||
return this.app.client.getWindowCount().then(function (count) { | ||
assert.equal(count, 1) | ||
}) | ||
}) | ||
@@ -50,2 +57,53 @@ }) | ||
### With Chai As Promised | ||
WebdriverIO is promise-based and so it pairs really well with the | ||
[Chai as Promised](https://github.com/domenic/chai-as-promised) library that | ||
builds on top of [Chai](http://chaijs.com). | ||
Using these together allows you to chain assertions together and have fewer | ||
callback blocks. See below for a simple example: | ||
```sh | ||
npm install --save-dev chai | ||
npm install --save-dev chai-as-promised | ||
``` | ||
```js | ||
var Application = require('spectron').Application | ||
var chai = require('chai') | ||
var chaiAsPromised = require('chai-as-promised') | ||
var path = require('path') | ||
chai.should() | ||
chai.use(chaiAsPromised) | ||
describe('application launch', function () { | ||
beforeEach(function () { | ||
this.app = new Application({ | ||
path: path: '/Applications/MyApp.app/Contents/MacOS/MyApp' | ||
}) | ||
return this.app.start() | ||
}) | ||
beforeEach(function () { | ||
chaiAsPromised.transferPromiseness = this.app.client.transferPromiseness | ||
}) | ||
afterEach(function () { | ||
return this.app.stop() | ||
}) | ||
it('opens a window', function () { | ||
return this.app.client.waitUntilWindowLoaded() | ||
.getWindowCount().should.eventually.equal(1) | ||
.isWindowMinimized().should.eventually.be.false | ||
.isWindowVisible().should.eventually.be.true | ||
.isWindowFocused().should.eventually.be.true | ||
.getWindowWidth().should.eventually.be.above(0) | ||
.getWindowHeight().should.eventually.be.above(0) | ||
}) | ||
}) | ||
``` | ||
### Application | ||
@@ -60,2 +118,4 @@ | ||
See [here](https://sites.google.com/a/chromium.org/chromedriver/capabilities) for more details. | ||
* `env` - Object of additional environment variables to set in the launched | ||
application. | ||
* `host` - String host name of the launched `chromedriver` process. | ||
@@ -81,12 +141,23 @@ Defaults to `'localhost'`. | ||
Spectron uses [webdriverio](http://webdriver.io) and exposes the managed | ||
Spectron uses [WebdriverIO](http://webdriver.io) and exposes the managed | ||
`client` property on the created `Application` instances. | ||
The full `client` API provided by `webdriverio` can be found [here](http://webdriver.io/api.html). | ||
The full `client` API provided by WebdriverIO can be found | ||
[here](http://webdriver.io/api.html). | ||
Several additional commands are provided specific to Electron. | ||
#### getWindowCount() | ||
Gets the number of open windows. | ||
```js | ||
app.client.getWindowCount().then(function (count) { | ||
console.log(count) | ||
}) | ||
``` | ||
#### getWindowDimensions() | ||
Gets the window dimensions of the current window. Object returned has | ||
Gets the dimensions of the current window. Object returned has | ||
`x`, `y`, `width`, and `height` properties. | ||
@@ -96,9 +167,96 @@ | ||
app.client.getWindowDimensions().then(function (dimensions) { | ||
assert.equal(dimensions.x, 25) | ||
assert.equal(dimensions.y, 35) | ||
assert.equal(dimensions.width, 200) | ||
assert.equal(dimensions.height, 100) | ||
}).then(done, done) | ||
console.log(dimensions.x, dimensions.y, dimensions.width, dimensions.height) | ||
}) | ||
``` | ||
#### getWindowHeight() | ||
Get the height of the current window. | ||
```js | ||
app.client.getWindowHeight().then(function (height) { | ||
console.log(height) | ||
}) | ||
``` | ||
#### getWindowWidth() | ||
Get the width of the current window. | ||
```js | ||
app.client.getWindowWidth().then(function (width) { | ||
console.log(width) | ||
}) | ||
``` | ||
#### isWindowDevToolsOpened() | ||
Returns whether the current window's dev tools are opened. | ||
```js | ||
app.client.isWindowDevToolsOpened().then(function (devToolsOpened) { | ||
console.log(devToolsOpened) | ||
}) | ||
``` | ||
#### isWindowFocused() | ||
Returns whether the current window has focus. | ||
```js | ||
app.client.isWindowFocused().then(function (focused) { | ||
console.log(focused) | ||
}) | ||
``` | ||
#### isWindowFullScreen() | ||
Returns whether the current window is in full screen mode. | ||
```js | ||
app.client.isWindowFullScreen().then(function (fullScreen) { | ||
console.log(fullScreen) | ||
}) | ||
``` | ||
#### isWindowLoading() | ||
Returns whether the current window is loading. | ||
```js | ||
app.client.isWindowLoading().then(function (loading) { | ||
console.log(loading) | ||
}) | ||
``` | ||
#### isWindowMaximized() | ||
Returns whether the current window is maximized. | ||
```js | ||
app.client.isWindowMaximized().then(function (maximized) { | ||
console.log(maximized) | ||
}) | ||
``` | ||
#### isWindowMinimized() | ||
Returns whether the current window is minimized. | ||
```js | ||
app.client.isWindowMinimized().then(function (minimized) { | ||
console.log(minimized) | ||
}) | ||
``` | ||
#### isWindowVisible() | ||
Returns whether the current window is visible. | ||
```js | ||
app.client.isWindowVisible().then(function (visible) { | ||
console.log(visible) | ||
}) | ||
``` | ||
#### setWindowDimensions(x, y, width, height) | ||
@@ -109,3 +267,21 @@ | ||
```js | ||
app.client.setWindowDimensions(100, 200, 50, 75).then(done, done) | ||
app.client.setWindowDimensions(100, 200, 50, 75) | ||
``` | ||
#### waitUntilTextExists(selector, text, [timeout]) | ||
Waits until the element matching the given selector contains the given | ||
text. Takes an optional timeout in milliseconds that defaults to `5000`. | ||
```js | ||
app.client.waitUntilTextExists('#message', 'Success', 10000) | ||
``` | ||
#### waitUntilWindowLoaded([timeout]) | ||
Wait until the window is no longer loading. Takes an optional timeout | ||
in milliseconds that defaults to `5000`. | ||
```js | ||
app.client.waitUntilWindowLoaded(10000) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15626
6
224
280
3
6
2
3
+ Addeddev-null@^0.1.1
+ Addeddev-null@0.1.1(transitive)