zoukankan      html  css  js  c++  java
  • NightWatch端到端测试

    NightWatch

    http://nightwatchjs.org/

    Nightwatch.js

    Browser automated testing done easy.

    Write End-to-End tests in Node.js quickly and effortlessly that run against a Selenium/WebDriver server.

    Browser Automation

    Nightwatch.js is an easy to use Node.js based End-to-End (E2E) testing solution for browser based apps and websites. It uses the powerful W3C WebDriver API to perform commands and assertions on DOM elements.

    安装

    https://github.com/nightwatchjs/nightwatch

    1. Install Nightwatch

    Install Node.js (together with the NPM tool) by following instructions available on nodejs.org.

    From NPM:

    $ npm install nightwatch

    From GitHub:

    $ git clone https://github.com/nightwatchjs/nightwatch.git
    $ cd nightwatch
    $ npm install

    2. Download WebDriver

    Nightwatch uses a WebDriver compatible server to control the browser. WebDriver is a W3C specification and industry standard which provides a platform and HTTP protocol to interact with a browser.

    Nightwatch includes support for automatically managing the following services:

    ChromeDriver

    Selenium Standalone Server

    It's important to note that, while the Selenium Server was required with older Nightwatch versions (v0.9 and prior), starting with version 1.0 Selenium is no longer necessary.

    安装报错解决方法:

    https://github.com/nightwatchjs/nightwatch/issues/913

    Nightwatch: Error retrieving a new session from the selenium server #913

    https://github.com/nightwatchjs/nightwatch/issues/1390

            "chromeOptions" : {
              "args" : ["disable-web-security", "ignore-certificate-errors", "headless"],
            }

    他山之石

    https://blog.risingstack.com/end-to-end-testing-with-nightwatch-js-node-js-at-scale/

    th these three tools, we are going to implement the flow this diagram shows below. node.js end-to-end testing with nightwatch.js flowchart

    自己动手

    https://github.com/fanqingsong/code-snippet/tree/master/web/night_watch

    package.json

    {
      "name": "night_watch",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "dev": "./node_modules/.bin/nightwatch"
      },
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "chromedriver": "^2.41.0",
        "nightwatch": "^0.9.21",
        "selenium-server": "^3.14.0"
      }
    }

    nigthwatch.json

    {
      "src_folders" : ["./examples/tests"],
      "output_folder" : "./examples/reports",
    
      "selenium" : {
        "start_process" : true,
        "server_path" : "./node_modules/selenium-server/lib/runner/selenium-server-standalone-3.14.0.jar",
        "log_path" : "",
        "host": "127.0.0.1",
        "port" : 4444,
        "cli_args" : {
          "webdriver.chrome.driver" : "./node_modules/chromedriver/lib/chromedriver/chromedriver.exe"
        }
      },
    
      "test_settings" : {
        "default" : {
          "launch_url" : "http://localhost",
          "selenium_port"  : 4444,
          "selenium_host"  : "localhost",
          "desiredCapabilities": {
            "browserName": "chrome",
            "javascriptEnabled": true,
            "acceptSslCerts": true,
            "chromeOptions" : {
              "args" : ["disable-web-security", "ignore-certificate-errors"]
            }
          }
        }
      }
    }

    nightwatch.js

    module.exports = {
      'Find the answer.': function(client) {
        // 启动浏览器并打开 bing.com.
        client.url('http://www.txrjy.com');
    
        // 确保 "body" 和输入框可以使用.
        client.expect.element('body').to.be.present;
        client.end();
      },
    };

  • 相关阅读:
    【Vue】详解Vue生命周期
    千万不要用window自带文本编辑器编辑配置文件或者代码
    [其它]iOS 13 正式版发布 iPhone 6s或更新型号均可升级
    [转]解决ubuntu16.04 ‘E: 无法获得锁 /var/lib/dpkg/lock-frontend
    [golang]使用gomail发邮件(在Go中发送电子邮件的最佳方式)
    [golang]按图片中心旋转后的新图左顶点和原图左顶点的偏移量计算
    分布式CAP定理,为什么不能同时满足三个特性?
    Java如何运行一个class文件的main方法
    数据库的四大特性以及四个隔离级别和引发的问题
    Redis为什么可以支持那么大的并发访问量?为什么redis没有单点并发瓶颈?
  • 原文地址:https://www.cnblogs.com/lightsong/p/9440434.html
Copyright © 2011-2022 走看看