mercredi 17 août 2016

Spectron Headless Testing on CentOS 7 not working

Environment

  • Mac OSX 10.11.5 running Vagrant 1.8.4 running Cent OS 7
  • Node v6.4.0
  • Npm v3.10.3
  • Electron-prebuilt ^1.2.0
  • Electron-packager ^7.6.0
  • Spectron v3.3.0

Running test headless, with Xvfb running and DISPLAY env var exported.

Setup

  • I've git cloned the electron-quick-start repo.
  • Then built it via electron-packager . MyApp --platform=linux --arch=x64 --prune (Script in package.json)
  • Then run test: node test_app.js

Output

Running app Main window is visible: true Check text Test failed An element could not be located on the page using the given search parameters. Stopping the application

Additional Notes

Everything seems to be working, since Main window visibility test returns true, but Spectron doesn't seem able to query elements of the HTML as I expected.

Why do I get: An element could not be located on the page using the given search?

Also, title is empty. Found out by removing getText test, and assert for title fails, saying " " does not equal "Hello World!"

I've also confirmed the app runs by building for Mac OS and checking it, but what I want to do is run headless tests for my CI setup.

Snippets

index.html / test_app.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: '/home/vagrant/electron-quick-start/MyApp-linux-x64/MyApp'})

console.log('Running app')

app.start()
    .then(function () {
    return app.browserWindow.isVisible()
    })
    .then(function (isVisible) {
    console.log('Main window is visible: ' + isVisible)
    })
    .then(function () {
    console.log('Check text')
    return app.client.getText('#par')    
    })
    .then(function (text) {
    assert.equal(text, "Does it work?")
    })
    .then(function () {
    console.log('Check the windows title')
    return app.client.getTitle()
    })
    .then(function (title) {
    assert.equal(title, 'Hello World!')
    })
    .then(function () {
    console.log('Stopping the application')
    return app.stop()
    })
    .catch(function (error) {
    //Log any failures
    console.error('Test failed', error.message)
    console.log('Stopping the application')
    return app.stop()
    })
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
  </head>
  
  <body>
    <p id="par">Does this work?</p>
  </body>
  
  <script>
    require('./renderer.js')
  </script>
</html>

Aucun commentaire:

Enregistrer un commentaire