Typography

活版印字


  • Home
  • Archive
  • Categories
  • Tags
  •  

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo

第一個 Nightwatch 自動化測試

Posted at 2016-04-21 前端測試  nightwatch 

安裝

必要環境

  • 有 Firefox 或 Chrome
  • 有 NodeJS

安裝必要 modules

npm i selenium-server nightwatch chromedriver -S

安裝 nightwatch

1
2
3
mkdir nightwatch-sandbox && cd nightwatch-sandbox
npm init -y
npm i nightwatch -g

設定

撰寫nightwatch環境設定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module.exports = {
src_folders: ['./tests'],
output_folder: './results',
live_output: true,

selenium: {
start_process: true,
server_path: './node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.0.jar',
log_path: './results',
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': './node_modules/.bin/chromedriver'
}
},

test_settings: {
default: {
launch_url: 'http://localhost',
selenium_host: '127.0.0.1',
selenium_port: 4444,
silent: true,
disable_colors: false,
screenshots: {
enabled: true,
path: './results/screenshots'
},
desiredCapabilities: {
browserName: 'firefox',
javascriptEnabled: true,
acceptSslCerts: true
}
},

chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true
}
}
}
};

實作

撰寫一個簡單的自動化測試

1
2
3
4
5
6
7
8
9
module.exports = {
'載入Blog': function (client) {
client
.url('http://blog.mokayo.com')
.waitForElementVisible('body', 1000)
.assert.title('教你所想學的,用眼樂讀 - blog.mokayo.com')
.end();
}
};

執行
nightwatch -c ./Nightwatch.js --env default

原始碼下載

Share 

 Previous post: 自動化測試框架比較 with NodeJS Next post: Selenium with Nodejs 

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo