Socket
Socket
Sign inDemoInstall

spectron

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spectron

Easy ChromeDriver tests for Electron apps


Version published
Weekly downloads
6.3K
decreased by-5.61%
Maintainers
1
Weekly downloads
 
Created
Source

spectron

js-standard-style Build Status

Easily test your Electron apps using ChromeDriver and webdriverio

Using

npm --save-dev spectron

Spectron works with any testing framework but the following example uses mocha.

var Application = require('spectron').Application
var assert = require('assert')
var path = require('path')

describe('application loading', function () {
  this.timeout(10000)

  var app = null

  beforeEach(function (done) {
    app = new Application({
      path: '/Applications/MyApp.app/Contents/MacOS/MyApp'
    })
    app.start().then(done, done)
  })

  afterEach(function (done) {
    app.stop().then(done, done)
    app = null
  })

  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)
  })
})

Application

new Application(options)

Create a new application with the following options:

  • path - String path to the application executable to launch. Required
  • args - Chrome arguments to pass to the executable. See here for more details.
  • host - String host name of the launched chromedriver process. Defaults to 'localhost'.
  • port - Number port of the launched chromedriver process. Defaults to 9515.
  • quitTimeout - Number in milliseconds to wait for application quitting. Defaults to 1000 milliseconds.
start()

Starts the application. Returns a Promise that will be resolved when the application is ready to use. You should always wait for start to complete before running any commands.

stop(callback)

Stops the application. Returns a Promise that will be resolved once the application has stopped.

Client Commands

spectron uses webdriverio and exposes the managed client property on the created Application instances.

The full client API provided by webdriverio can be found here.

Several additional commands are provided specific to Electron.

getWindowDimensions()

Gets the window dimensions of the current window. Object returned has x, y, width, and height properties.

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)
setWindowDimensions(x, y, width, height)

Sets the window position and size.

app.client.setWindowDimensions(100, 200, 50, 75).then(done, done)

Keywords

FAQs

Package last updated on 13 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc