测试未执行 - 使用标准 mocha 和 phantomjs 的夜视
test is not executed - nightwatch with standard mocha and phantomjs
所以我有一个 nodejs 服务器,我想开始使用 nightwatch 进行一些功能测试。
如果我手动启动 selenium 并使用 mocha 运行 它(命令:mocha ./test/functional/*.spec.js --compilers js:babel-register)它启动节点服务器并且 运行 在 firefox 中正常(默认 - 顺便说一句,使用标准 mocha 如何将它从默认 firefox 更改为其他浏览器?):
import nightwatch from 'nightwatch';
require('../../server');
describe('Functional', function wrapIt() {
const client = nightwatch.initClient({
silent: true,
});
const browser = client.api();
this.timeout(99999999);
beforeEach((done) => {
client.start(done);
});
it('should login', (done) => {
browser
.url('http://localhost:8441/')
.waitForElementVisible('button[name=login]', 1000)
.click('button[name=login]')
.pause(1000);
browser.expect.element('button').to.have.attribute('class').which.contains('theme__button');
browser.end();
client.start(done);
});
after((done) => {
browser.end();
client.start(done);
});
});
现在我想把它放在 Bamboo 上并使用 phantomjs,selenium 服务器启动,nodejs 服务器启动但没有执行测试。
我有 nightwatch.json:
{
"src_folders" : ["test/night"],
"output_folder": "reports",
"test_runner" : "mocha",
"selenium" : {
"start_process": true,
"server_path": ".//bin/selenium-server-standalone-2.53.1.jar",
"log_path": "./reports",
"host": "127.0.0.1",
"port": 4444
},
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "phantomjs",
"phantomjs.cli.args" : ["--ignore-ssl-errors=true"],
"version":"latest",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
,nightwatch.conf.js 是:
require('babel-core/register');
module.exports = require('./nightwatch.json');
和 night 文件夹中的测试脚本:
require('../../server');
describe('Functional', function wrapIt() {
const client = this.client;
const browser = client.api();
this.timeout(99999999);
beforeEach((done) => {
client.start(done);
});
it('should login', (done) => {
browser
.url('http://localhost:8441/')
.waitForElementVisible('button[name=login]', 1000)
.click('button[name=login]')
.pause(1000);
browser.expect.element('button').to.have.attribute('class').which.contains('theme__button');
browser.end();
client.start(done);
});
after((done) => {
browser.end();
client.start(done);
});
});
所以 运行用 nightwatch 启动 selenium 服务器,nodejs 服务器也启动正常,但没有任何反应。
我使用 webdriver 更改了它:
export const client = require('webdriverjs').remote({ // eslint-disable-line
// Settings
desiredCapabilities: {
// You may choose other browsers
// http://code.google.com/p/selenium/wiki/DesiredCapabilities
browserName: 'phantomjs',
},
// webdriverjs has a lot of output which is generally useless
// However, if anything goes wrong, remove this to see more details
logLevel: 'silent',
});
client.init();
和:
require('../../server');
const client = require('./client').client;
describe('Functional testing', function wrapIt() {
this.timeout(99999999);
before((done) => {
client.init().url('http://localhost:8441/', done);
});
describe('Check homepage', () => {
it('should login', (done) => {
client.waitFor('button[name=login]', 100, () => {
client.click('button[name=login]', () => {
client.element('.theme__button*');
client.waitForVisible(1000);
client.end();
});
});
done();
});
});
after((done) => {
client.end();
done();
});
});
并且有效 运行 mocha './test/funcTest.js' --compilers js:babel-register -t 10000
PS: selenium 已经在本地启动,在 bamboo 上我添加了一个命令来启动它
所以我有一个 nodejs 服务器,我想开始使用 nightwatch 进行一些功能测试。
如果我手动启动 selenium 并使用 mocha 运行 它(命令:mocha ./test/functional/*.spec.js --compilers js:babel-register)它启动节点服务器并且 运行 在 firefox 中正常(默认 - 顺便说一句,使用标准 mocha 如何将它从默认 firefox 更改为其他浏览器?):
import nightwatch from 'nightwatch';
require('../../server');
describe('Functional', function wrapIt() {
const client = nightwatch.initClient({
silent: true,
});
const browser = client.api();
this.timeout(99999999);
beforeEach((done) => {
client.start(done);
});
it('should login', (done) => {
browser
.url('http://localhost:8441/')
.waitForElementVisible('button[name=login]', 1000)
.click('button[name=login]')
.pause(1000);
browser.expect.element('button').to.have.attribute('class').which.contains('theme__button');
browser.end();
client.start(done);
});
after((done) => {
browser.end();
client.start(done);
});
});
现在我想把它放在 Bamboo 上并使用 phantomjs,selenium 服务器启动,nodejs 服务器启动但没有执行测试。 我有 nightwatch.json:
{
"src_folders" : ["test/night"],
"output_folder": "reports",
"test_runner" : "mocha",
"selenium" : {
"start_process": true,
"server_path": ".//bin/selenium-server-standalone-2.53.1.jar",
"log_path": "./reports",
"host": "127.0.0.1",
"port": 4444
},
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "phantomjs",
"phantomjs.cli.args" : ["--ignore-ssl-errors=true"],
"version":"latest",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
,nightwatch.conf.js 是:
require('babel-core/register');
module.exports = require('./nightwatch.json');
和 night 文件夹中的测试脚本:
require('../../server');
describe('Functional', function wrapIt() {
const client = this.client;
const browser = client.api();
this.timeout(99999999);
beforeEach((done) => {
client.start(done);
});
it('should login', (done) => {
browser
.url('http://localhost:8441/')
.waitForElementVisible('button[name=login]', 1000)
.click('button[name=login]')
.pause(1000);
browser.expect.element('button').to.have.attribute('class').which.contains('theme__button');
browser.end();
client.start(done);
});
after((done) => {
browser.end();
client.start(done);
});
});
所以 运行用 nightwatch 启动 selenium 服务器,nodejs 服务器也启动正常,但没有任何反应。
我使用 webdriver 更改了它:
export const client = require('webdriverjs').remote({ // eslint-disable-line
// Settings
desiredCapabilities: {
// You may choose other browsers
// http://code.google.com/p/selenium/wiki/DesiredCapabilities
browserName: 'phantomjs',
},
// webdriverjs has a lot of output which is generally useless
// However, if anything goes wrong, remove this to see more details
logLevel: 'silent',
});
client.init();
和:
require('../../server');
const client = require('./client').client;
describe('Functional testing', function wrapIt() {
this.timeout(99999999);
before((done) => {
client.init().url('http://localhost:8441/', done);
});
describe('Check homepage', () => {
it('should login', (done) => {
client.waitFor('button[name=login]', 100, () => {
client.click('button[name=login]', () => {
client.element('.theme__button*');
client.waitForVisible(1000);
client.end();
});
});
done();
});
});
after((done) => {
client.end();
done();
});
});
并且有效 运行 mocha './test/funcTest.js' --compilers js:babel-register -t 10000
PS: selenium 已经在本地启动,在 bamboo 上我添加了一个命令来启动它