e2e 模拟用户行为的测试

nightwatch.js

Nightwatch.js是一种易于使用的基于浏览器的应用程序和网站的基于Node.js的端到端(E2E)测试解决方案。它使用强大的W3C WebDriver API来对DOM元素执行命令和断言。

需要安装的npm包

selenium-server:webdriver测试服务器的nodejs搭建
nightwatch:对selenium-server的包装,简化其配置
chromedriver:selenium的chrome测试环境插件,如果是firefox、ie等都需要重新下测试环境插件。
chromedriver npm 装不上 就用 cnpm
Firefox 使用GeckoDriver进行测试

nightwatch.json

默认情况下 使用 nightwatch.json 的配置文件
也可以使用 nightwatch.conf.js 来配置文件
两个文件同时存在 优先使用 nightw atch.conf.js

{
//  测试所在的文件夹 不能识别自文件夹
  "src_folders" : ["tests"],

//输出报告文件位置
  "output_folder" : "reports",

//加载自定义命令
  "custom_commands_path" : "",

//加载自定义断言
  "custom_assertions_path" : "",

//加载页面对象文件
  "page_objects_path" : "",

//全局位置
  "globals_path" : "",

//Selenium Server 相关配置
  "selenium" : {

      //是否自动管理 selenium 过程。
    "start_process" : false,

    //selenium jar
    "server_path" : "",

    //Selenium日志记录
    "log_path" : "",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "",
      "webdriver.gecko.driver" : "",
      "webdriver.edge.driver" : ""
    }
  },
//测试相关的配置
  "test_settings" : {
    "default" : {
    //brower.launch_url 可以在用例中使用
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
    //是否显示扩展的Selenium命令日志
      "silent": true,

    //错误截图
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
    //传递给Selenium WebDriver指定浏览器名称以及其他功能
      "desiredCapabilities": {
        "browserName": "firefox",
        "marionette": true
      }
    },

    "chrome" : {
      "desiredCapabilities": {
        "browserName": "chrome"
      }
    },

    "edge" : {
      "desiredCapabilities": {
        "browserName": "MicrosoftEdge"
      }
    }
  }
}

desiredCapabilities 相关配置
nightwatch.js 官网

Chai Expect

Nightwatch 基于Chai expect 的断言库

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章