├── reports // 输出报表文件夹
├── screenshots // 自动截屏
├── nightwatch.conf.js // nightwatch 运行配置
├── runner.js // 运行器
└── specs // 测试文件
└── test.spec.js
以上是vue-cli为我们自动创建的Nightwatch工程结构,specs是测试文件存放的文件夹,nightwatch.conf.js是Nightwatch的运行配置文件。其他的目录将会在具体的章节逐一地进行讲述。
基本配置
Nightwatch的配置项都集中在nightwatch.conf.js中,其实这个配置也可以是一个JSON格式,采用JSON格式只需要简单地对配置项写入一些常量即可。但使用模块的方式进行配置可以执行一些额外的配置代码,这样则显得更为灵活。以下是我调整过的nightwatch.conf.js文件内容:
require('babel-register');
var config = require('../../config');
var seleniumServer = require('selenium-server');
var phantomjs = require('phantomjs-prebuilt');
module.exports = {
"src_folders": ["test/e2e/specs"],
"output_folder": "test/e2e/reports",
"custom_assertions_path": ["test/e2e/custom-assertions"],
"page_objects_path": "test/e2e/page-objects",
"selenium": {
"start_process": true,
"server_path": seleniumServer.path,
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": require('chromedriver').path
}
},
"test_settings": {
"default": {
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
launch_url:"http://localhost:" + (process.env.PORT || config.dev.port),
"globals": {
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"firefox": {
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
Nightwatch的配置分为以下三类:
● 基本配置;
● Selenium配置;
● 测试环境配置。
在配置模块中的所有根元素配置项都属于基本配置,用于控制Nightwatch的全局性运行的需要。下表为Nightwatch的基本配置项的详细说明。
