This article will introduce to you the automated testing of nightwatch in js, so that you can master the method of automated testing of nightwatch. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
nightwatch.js is a web-ui automated testing framework that is deeply integrated into vue-cli. If a project is built based on vue-cli, it can basically be used out of the box.
But we cannot use vue-cli all the time. Because it often cannot meet our customized needs. Many times we will customize the build framework or completely rebuild it. At this time, it will be difficult to integrate nightwatch. This article will help you get started with building such a testing framework.
Required environment
First install nightwatch in the project, switch to the project directory
npm intall nightwatch -D
Installing this is not enough, you also need to install selenium-server, which can also be installed using npm
npm install selenium-server -D
selenium-server is developed based on Java and is used to connect to the browser. So you need to install java before installing selenium-server. How to install Java?
In addition, you also need to install a browser driver. Generally, we use chrome for testing
npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedrive -D
If you install chromedriver directly, it will prompt that the installation is unsuccessful, and you need to manually specify the mirror address
The parts that need to be downloaded have been downloaded.
Project configuration
nightwatch uses nightwatch.conf.js
in the project root directory by default as the configuration file. The official website also has another configuration file format which is nightwatch.json
. Here we use the js configuration method because the format is more flexible.
The following is a simple configuration file.
module.exports = { 'src_folders': [ 'e2e/case' ], 'output_folder': 'reports', 'custom_commands_path': '', 'custom_assertions_path': '', 'page_objects_path': '', 'globals_path': require('./e2e/config/global.config').path, 'selenium': { 'start_process': true, 'server_path': require('selenium-server').path, 'log_path': '', 'host': '127.0.0.1', 'port': 4444, 'cli_args': { 'webdriver.chrome.driver': require('chromedriver').path } }, 'test_settings': { 'default': { 'launch_url': 'http://localhost', 'selenium_port': 4444, 'selenium_host': 'localhost', 'silent': true, 'screenshots': { 'enabled': false, 'path': '' }, 'desiredCapabilities': { 'browserName': 'chrome', 'marionette': true } }, 'chrome': { 'desiredCapabilities': { 'browserName': 'chrome' } }, 'edge': { 'desiredCapabilities': { 'browserName': 'MicrosoftEdge' } } } }
src_folders: represents the folder where the case is located
output_folder: represents the folder for report output
server_path under selenium: represents selenium-server The installation path
start_process under selenium: represents whether to automatically start selenium-server. If the investment is set to false, the server will not be automatically started.
"cli_args" : { "webdriver.chrome.driver" : "", "webdriver.gecko.driver" : "", "webdriver.edge.driver" : "" }
The driver below cli_args represents the installation paths of several drivers. Just install them successfully.
test_settings is the data passed to the nightwatch instance. Multiple environments can be configured here. The default is It is necessary, other environments can be prepared by yourself.
nightwatch --env default
Then we run the above command in the project.
I found an error in windows and couldn't run it. We need to configure
"scripts": { "e2e": "nightwatch --env default", },
under package.json so that it can run normally.
If you need to see the real effect, we can just create some cases under the case folder
For example:
module.exports = { 'Test login': function (browser) { browser .windowMaximize() .url('https://trans.qa.17u.cn/saas') .waitForElementVisible('.login', 3000) .assert.urlContains('/saas/login') } }
Summary: The above is the entire article The content and code are very simple, you can try it. I hope it will be helpful to everyone's learning. For more related tutorials, please visit JavaScript Video Tutorial, jQuery Video Tutorial, bootstrap Tutorial!
The above is the detailed content of Detailed explanation of automated testing of nightwatch in js. For more information, please follow other related articles on the PHP Chinese website!

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
