js e2e测试-nightwatch入门
来源:互联网 发布:网络用语1是什么意思 编辑:程序博客网 时间:2024/05/29 13:42
nightwatch是基于selenium(webdriver)的e2e测试框架。
selenium还需要java环境。提前安装java环境。
实现效果:自动打开bing页面,搜索内容,关闭页面。
1 安装
mkdir nightwatchDemocd nightwatchDemonpm init -ynpm install nightwatch selenium-server chromedriver --save
2 创建nightwatch.conf.js
const path = require('path');module.exports = { // 测试文件入口 src_folders: ['tests'], // 输出报表路径 output_folder: 'reports', // selenium配置 selenium: { start_process: true, server_path: require('selenium-server').path, host: '127.0.0.1', // selenium log输出 log_path: 'reports', port: 9090, cli_args: { 'webdriver.chrome.driver': require('chromedriver').path, 'webdriver.gecko.driver': require('chromedriver').path } }, test_settings: { default: { launch_url: 'http://localhost', selenium_port: 9090, selenium_host: 'localhost', silent: true, screenshots: { enabled: false, path: '' } }, chrome: { desiredCapabilities: { browserName: 'chrome', javascriptEnabled: true, acceptSslCerts: true } } }};
3 根据配置的src_folders创建tests文件夹,下面创建个demo.js
module.exports = { 'Find the answer.': function(client) { // 定义 Bing 页面中的节点. const searchInput = '#sb_form_q'; const searchBtn = '#sb_form_go'; const question = '测试nightwatch自动打开网站搜索'; // 启动浏览器并打开 bing.com. client.url('http://bing.com').maximizeWindow(); // 确保 "body" 和输入框可以使用. client.expect.element('body').to.be.present; client.expect.element(searchInput).to.be.visible; client.pause(2000); // 稍等两秒. // 输入 "what is microsoft" 然后搜索. client.setValue(searchInput, question); client.click(searchBtn); client.pause(2000); // 截一张图然后保存到 "reports/answer.png". client.expect.element('body').to.be.present; client.saveScreenshot('reports/answers.png'); client.end(); }};
4 修改package.json的script字段
"scripts": { "test": "./node_modules/.bin/nightwatch --env" },
5 运行 npm run test
成功完成,输出日志。
阅读全文
1 0
- js e2e测试-nightwatch入门
- 使用Nightwatch进行端到端测试
- 使用Nightwatch.js做基于浏览器的web应用自动测试
- angularjs中的e2e测试实例
- e2e test 端到端的测试
- Nightwatch.js 异步中调用等待执行
- 【Angular2】Tour of Heroes 之 e2e测试
- e2e 模拟用户行为的测试
- angularJS的e2e和unit测试环境部署
- 自动化e2e测试 – WebDriverJS,Jasmine和Protractor
- E2E-X5ME1,
- E3X-DA41-S,E2E-X1C1、E2E-XR5E1
- 初步了解Angular 2端到端的测试 Introduction to E2E Testing with the Angular CLI and Protractor
- vue.js入门学习(搭建环境和测试demo)
- AngularJs学习笔记--E2E Testing
- E2E dm8168 相关帖子整理
- 测试入门
- 测试入门
- linux用户及用户组管理
- jQuery AJAX 与 AJAX
- JavaScript类的声明与使用
- 你会使用五笔打字吗?
- Effective Modern C++ Item 1
- js e2e测试-nightwatch入门
- 设计模式六大原则
- 前端基础面试题,菜鸟必备
- EventBus3.0 使用
- Linux中epoll()函数的底层实现
- ViewPager的高度根据item的高度自适应
- Android--快速接入微信支付
- vs2015的程序在vs2013上运行出现:error MSB8020
- elasticsearch.net search使用指南