Write End-to-End tests in Node.js quickly and effortlessly that run against a Selenium/WebDriver server.
http://nightwatchjs.org/
{
"name": "test selenium",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nightwatch"
},
"author": "",
"license": "ISC",
"dependencies": {
"chrome-driver-standalone": "^2.25.0",
"nightwatch": "^0.9.9"
"selenium-server-standalone-jar": "^3.0.1"
}
}
在執行 nightwatch 之前要先有一個設定檔案告訴 nightwatch 一些你連線的資訊
var selenium = require('selenium-server-standalone-jar'); var chromeDriver = require('chrome-driver-standalone'); var config = { "src_folders": ["test"], "selenium": { "start_process": true, "server_path": selenium.path, "cli_args": { "webdriver.chrome.driver": chromeDriver.path } }, "test_settings": { "default": { "globals": { "waitForConditionTimeout": 30000 }, "desiredCapabilities": { "browserName": "chrome", } } } } module.exports = config;
好的測試項目應該盡量不要使用pause
並且要有驗證的機制
.click('input.btn')
//.pause(3000)
.waitForElementVisible('img.avatar')
.click('.header-nav-link.tooltipped.tooltipped-s.js-menu-target')
把重複使用率高的功能抽出來變成模組
browser
.resizeWindow(1920, 1080)
.login(username, password)
.createRepository(repositoryName)
.deleteRepository(username, repositoryName)
.end()
phantomjs 可以用,但是不建議
firefox 的 不一定比 chrome 還穩定
docker 的 container 裡面中文顯示有問題,要用 class/id 判斷