1. 安装配置nightwatch 和 selenium css
> npm install nightwatch --save-devhtml
> npm install selenium-standalone --save-devnode
编写配置文件:git
> selenium-conf.js github
https://selenium-release.storage.googleapis.com/index.html 查看 selenium 的最新版本号chrome
若是执行 node ./build/selenium-setup.js 安装selenium 时发现装不上的话,能够尝试修改版本号。本文编写时,用的版本是:version: '3.9.0' 。 能够正常安装。npm
经过 https://chromedriver.storage.googleapis.com/index.html 查看 Chrome 的 Driver 最新版本号api
chrome版本号对应表:测试
chrome Driver | chrome |
v2.38 | v66 |
v2.33 | v60-62 |
v2.32 | v59-61 |
... | ... |
以此类推,如出现安装不上的状况,能够尝试更改版本号,尽可能跟测试环境上装的chrome版本保持匹配。ui
我这边就出现过测试用例能够正常跑起来,可是尝试给输入框赋值的时候,setValue方法却始终无效。缘由是driver版本跟本机chrome不一致致使。
更改版本号,从新 setup后,跑测试用例,一切ok。
默认使用的是css selector, 若是没有id之类的,不方便写选择器的话,能够使用Xpath ,不过须要先使用 browser.useXpath()
count(selector, count)
attributePresent(selector, attr)
evaluate(fn, [args], [message])
checked(selector, expected)
focused(selector, expected)
hasHTML(selector, html)
notVisible(selector)
dblClick(selector)
waitFor(duration)
trigger(selector, event, [keyCode])
enterValue(selector, value)