标签:代码 rgs config 初始化 out drivers fun row 自动启动
注:
1. 安装底层环境
2. 创建nightwatch项目
basic settings: page_object,sections…的路径
selenium:
test settings: (命令行中env中的值 --env=‘‘)
3. 集成到gulp
最简单的一个配置
var gulp = require(‘gulp‘),
nightwatch = require(‘gulp-nightwatch‘);
gulp.task(‘nightwatch‘, function() {
return gulp.src(‘‘)
.pipe(nightwatch({
configFile: ‘src/config/nightwatch.json‘
}));
});
项目结构
test-project
--lib (selenium-server-standalone-2.53.0.jar)
--node_modules
--src
--config (nightwatch.json)
--page_objects
--sections
--commands
--assertions
--ui_tests
--package.json
--gulpfile.js
4. gulp其他插件
var eslint = require(‘gulp-eslint‘);
gulp.task(‘lint‘, function() {
return gulp
.src([‘**/*.js‘, ‘!node_modules/**‘])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
5. 问题
1. selenium的配置
"cli_args": {
"webdriver.chrome.driver": "D:/test-project/node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
"webdriver.ie.driver" : "D:/test-project/node_modules/iedriver/lib/iedriver/IEDriverServer.exe",
}
2. test_settings的配置
"desiredCapabilities" : {
"browserName" : "internet explorer",
"javascriptEnabled" : true,
"acceptSslCerts" : true
}
browserName要和driver里面的名字相同,这样才能找到对应的driver
命令行不输入任何env的时候,就直接使用default里面的配置
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
如果只有nightwatch本身,则可以直接cmd中 --env chrome
gulp.task(‘nightwatch‘, function() {
return gulp.src(‘‘)
.pipe(nightwatch({
configFile: ‘src/config/nightwatch.json‘,
cliArgs: {
reporter: ‘src/config/html-reporter.js‘,
env: globals.env
}
}));
});
"phantomjs" : {
"desiredCapabilities" : {
"browserName" : "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
"phantomjs.binary.path" : "D:/test-project/node_modules/.bin/phantomjs.cmd"
}
}
浏览器
"browserstack_chrome" : {
"selenium_host" : "hub-cloud.browserstack.com",
"selenium_port" : 80,
"desiredCapabilities": {
"browserstack.user": "catherinewang2",
"browserstack.key": "kKkbwdQyErB92aeStAB1",
"browser": "chrome"
}
}
模拟机
"browserstack_android" : {
"selenium_host" : "hub-cloud.browserstack.com",
"selenium_port" : 80,
"desiredCapabilities": {
"browserstack.user": "catherinewang2",
"browserstack.key": "kKkbwdQyErB92aeStAB1",
"platform": "WIN8",
"browserName": "chrome",
"device": "Google Nexus 5"
}
}
物理机(real mobile)
"browserstack_real_android" : {
"selenium_host" : "hub-cloud.browserstack.com",
"selenium_port" : 80,
"desiredCapabilities": {
"browserstack.user": "catherinewang2",
"browserstack.key": "kKkbwdQyErB92aeStAB1",
"platform": "ANDROID",
"browserName": "chrome",
"device": "Google Nexus 9",
"realMobile": true
}
}
在nightwatch.json文件中配置:‘‘browserstack.local‘: true’
js文件中配置
var browserstack = require(‘browserstack-local‘);
var bs_local;
console.log("BrowserStack connecting local");
bs_local = new browserstack.Local();
bs_local.start({"key": globals.BROWSERSTACK_ACCESS_KEY}, function (error) {
if (error) throw error;
console.log(‘Connected. Now testing...‘);
});
var browserStack = require(‘gulp-browserstack‘);
gulp.task(‘testUI:test‘, [‘cleanTestUI‘], function() {
return gulp
.src(‘‘)
.pipe(browserStack.startTunnel({
key: ‘TQtWg9ELqiNAscJSH4qz‘
}))
.pipe(uiAutomation({
output: output,
tag: ‘end2end1‘,
env: ‘browserstack_chrome‘
}))
.pipe(browserStack.stopTunnel());
});
3. 问题
1. 第三方包
2. 使用第三包
nightwatch({
configFile: ‘src/config/nightwatch.json‘,
cliArgs: {
reporter: ‘src/config/html-reporter.js‘
}
})
globals.js -
var gutil = require(‘gulp-util‘),
module.exports = {reporter: gutil.env.reporter}
gulpfiles.js --
nightwatch({
configFile: ‘src/config/nightwatch.json‘,
cliArgs: {
reporter: globals.reporter
}
})
cmd: --reporter ./html-reporter.js
学习地址: http://nightwatchjs.org/
(一) Nightwatch扩展
(二)Nightwatch自己的一些API
(三)问题
1. gulp.task(‘taks name‘, function () {return ...}) 定义一个task任务
2. gulp.src(‘‘) --源文件路径
.pipe()的作用 -- Unix操作系统的管道(pipe)思想,前一集的输出,直接变成后一集的输入。通常命令和命令之前的衔接就是用pipe。类似jQuery的链式编程
标签:代码 rgs config 初始化 out drivers fun row 自动启动
原文地址:http://www.cnblogs.com/lj8023wh/p/7059421.html