我正在尝试为学生自动化测试。作为一个非常基本的例子:编写一些HTML。所以我创建了一个测试用例来检查无序列表。 无论如何:它在本地工作,但似乎我不能让它在travis上工作。我可能会想念一件小事,但不知道出了什么问题:
https://travis-ci.com/maciossek/hft-asgmt-html-01/jobs/127338669/config https://github.com/maciossek/hft-asgmt-html-01
任何帮助都非常感谢!
答案 0 :(得分:2)
这是我最终得到的(工作)
的travis.ymllanguage: node_js
node_js:
- "9"
dist: trusty
sudo: false
addons:
chrome: stable
before_install:
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
cache:
yarn: true
directories:
- node_modules
install:
- yarn install
script:
- yarn test
答案 1 :(得分:1)
Travis CI更新了启用了sudo的Ubuntu构建环境(dist: trusty
),因此不再需要安装google-chrome-stable
。
这是一个完整的运行示例:
.travis.yml
dist: trusty
sudo: required
language: node_js
node_js:
- "8.11.3"
script:
- yarn test
package.json
{
"dependencies": {
"express": "4.16.3"
},
"devDependencies": {
"jasmine": "3.2.0",
"puppeteer": "1.9.0"
},
"main": "src/Server.js",
"name": "example-puppeteer-travis-ci",
"scripts": {
"test": "jasmine"
},
"version": "1.0.0"
}
src / Server.js
const express = require('express');
class Server {
constructor() {
this.app = express();
this.app.get('/', (request, response) => response.send('<title>Hello</title>'));
}
start(port = 8080) {
return new Promise((resolve, reject) => {
if (this.server) {
reject(new Error('Server is already running.'));
} else {
this.server = this.app.listen(port, () => resolve(port));
}
});
}
stop() {
if (this.server) {
this.server.close();
this.server = undefined;
}
}
}
module.exports = Server;
spec / support / ServerSpec.js
const puppeteer = require('puppeteer');
const Server = require('../../src/Server');
describe('Server', () => {
let browser = undefined;
let server = undefined;
beforeEach(async () => {
browser = await puppeteer.launch({args: ['--disable-setuid-sandbox', '--no-sandbox'], dumpio: true});
server = new Server();
});
afterEach(async () => {
if (browser) await browser.close();
if (server) await server.stop();
});
it('serves a homepage with a title', async () => {
const port = await server.start();
const url = `http://localhost:${port}/`;
const page = await browser.newPage();
await page.goto(url);
const title = await page.title();
expect(title).toBe('Hello');
});
});