2016-08-17 2 views
2

EnvironmentСпектрон Безголовый Тестирование на CentOS 7 не работает

  • Mac OSX 10.11.5 работает Vagrant 1.8.4 работает Cent OS 7
  • Узел v6.4.0
  • НПМ v3 .10.3
  • Электронные преоб- разованы^1.2.0
  • Электрон-упаковщик^7.6.0
  • Спектрон v3.3.0

Запуск теста без головы, с Xvfb

  • Xvfb :99 -screen 0 1024x768x24 +extension RANDR &
  • export DISPLAY=':99.0'

установки

  • У меня есть git clonedelectron-quick-start репо.
  • Тогда построил его с помощью electron-packager . MyApp --platform=linux --arch=x64 --prune (Script в package.json)
  • Затем выполните проверку: node test_app.js

Выход

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

Дополнительные примечания

Ева rything, похоже, работает, так как проверка видимости главного окна возвращает true, но Spectron, похоже, не может запрашивать элементы HTML, как я ожидал.

Зачем мне нужно: An element could not be located on the page using the given search?

Кроме того, заголовок пуст. Обнаружено, удалив getText тест, и утверждают, что заголовок не работает, говоря «» не равен "Hello World!"

Я также подтвердил, что приложение запускается путем создания для Mac OS и проверки его, но то, что я хочу сделать, тесты для моей установки CI.

Отрывки

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 this 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>

скриншот XWD

  • Ран приложение: npm start

Выход

>[email protected] start /home/vagrant/electron-quick-start

>electron .

Xlib: extension "RANDR" missing on display ":99.0".

Xlib: extension "RANDR" missing on display ":99.0".

Сформирован скриншот

  • xwd -root -silent > grab.xwd
  • convert grab.xwd grab.jpg

enter image description here

+0

Пробовал 'Xvfb: 99 -screen 0 1024x768x24 + расширение RandR &', чтобы избавиться от 'Xlib: расширение "RandR" отсутствует на дисплее ": 99,0" .' когда я бегу контрольная работа. Он избавился от сообщений, но с теми же результатами. – mauricio777

ответ

1

Я изменил мой test_app.js использовать функции стрелок, возможно, я исправил некоторые тонкие ошибки в этом процессе, но теперь он работает!

Выходной

Running app...

Main window is visible: true

Checking text...

Text: Does this work?

Checking the windows title...

Title: Hello World!

Stopping the application

Новые 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(() => app.browserWindow.isVisible()) 
 
    .then((isVisible) => console.log('Main window is visible: ', isVisible)) 
 
    .then(() => { 
 
     console.log('Checking text...') 
 
     return app.client.getText('#par')  
 
    }) 
 
    .then((text) => { 
 
     assert.equal(text, "Does this work?") 
 
     console.log("Text: ", text) 
 
    }) 
 
    .then(() => { 
 
     console.log('Checking the windows title...') 
 
     return app.client.getTitle() 
 
    }) 
 
    .then((title) => { 
 
     assert.equal(title, 'Hello World!') 
 
     console.log("Title: ", title) 
 
    }) 
 
    .then(() => { 
 
     console.log('Stopping the application') 
 
     return app.stop() 
 
    }) 
 
    .catch((error) => { 
 
     //Log any failures 
 
     console.error('Test failed: ', error.message) 
 
     console.log('Stopping the application') 
 
     return app.stop() 
 
    })

Смежные вопросы