我试图用spectron来测试我的电子应用程序https://github.com/rafaelleru/torrent_player,我尝试在https://github.com/electron/spectron中设置示例的测试蚂蚁它通过我的本地电脑,但在特拉维斯我不知道如何设置bin文件以测试或如何告诉travis生成bin文件。与spectron和travis的测试电子应用程序
这样做的正确方法是什么?
我试图用spectron来测试我的电子应用程序https://github.com/rafaelleru/torrent_player,我尝试在https://github.com/electron/spectron中设置示例的测试蚂蚁它通过我的本地电脑,但在特拉维斯我不知道如何设置bin文件以测试或如何告诉travis生成bin文件。与spectron和travis的测试电子应用程序
这样做的正确方法是什么?
这是很难回答你的问题,如果你不指定正是发生。但下面是我如何解决它,我希望它可以帮助。
我这是怎么了SPECTRON特拉维斯运行我的电子申请(仅限Linux):
.travis.yml
os:
- linux
language: node_js
node_js:
- "7.7"
before_script:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh -e /etc/init.d/xvfb start; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sleep 3; fi
script:
- node --version
- npm --version
- npm install
- npm run e2e
cache:
directories:
- node_modules
notifications:
email:
on_success: never
on_failure: change
utils.js
const electron = require('electron');
const beforeEach = function (env = {}) {
this.app = new Application({
path: electron,
args: ['.'],
});
return this.app.start();
};
const afterEach = function() {
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
return undefined;
};
.e2e.js个-files
describe('test case', function() {
beforeEach(testUtils.beforeEach);
afterEach(testUtils.afterEach);
it('should run', function() {
});
});
如何存储
如果你有你的测试运行SPECTRON测试失败的截图,但他们由于某种原因失败,那么它可以帮助您可以通过截图电子应用。
utils.js
const fs = require('fs');
const saveErrorShot = function (e) {
const filename = `errorShot-${this.test.parent.title}-${this.test.title}-${new Date().toISOString()}.png`
.replace(/\s/g, '_')
.replace(/:/g, '');
this.app.browserWindow.capturePage().then(imageBuffer => {
fs.writeFile(filename, imageBuffer, error => {
if (error) throw error;
console.info(`Screenshot saved: ${process.cwd()}/${filename}`);
});
});
throw e;
};
.e2e.js -files
describe('test case', function() {
it('should store a screenshot', function() {
return this.app.client
.then(() => this.app.client.getText('.non-existing-element')
.catch(testUtils.saveErrorShot.bind(this));
});
});
为了让特拉维斯发送您的文物,一个Amazon S3存储
加入您的AWS S3证书到您的Travis env变量,read here for more information。
以下添加到.travis.yml
after_failure:
- curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash
- artifacts upload $(git ls-files -o | grep -Fv -e node_modules)
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then artifacts upload $(ls /home/travis/.npm/_logs/); fi
它所做的是,它
-e unnecessary_folder -e unnecesarry_file
。/home/travis/.npm/_logs
上传npm日志。如果您正在运行MacOS,这些文件将出现在另一个文件夹中。