nightwatch + selenium 基于浏览器的web自动化测试 教程(一)

使用nightwatch进行E2E测试中文教程 E2E测试 E2E(end to end)测试是指端到端测试又叫功能测试,站在用户视角,使用各种功能、各种交互,是用户的真实使用场景的仿真。在产品高速迭代的现在,有个自动化测试,是重构、迭代的重要保障。对web前端来说,主要的测试就是,表单、动画、页面跳转、dom渲染、Ajax等是否按照期望。 E2E测试驱动重构 重构代码的目的是什么?是为了使代码质量更高、性能更好、可读性和拓展性更强。 阅读详情

目录

 

什么是nightwatch

nightwatch的实现原理

安装与配置

安装nodejs

安装nightwatch

Selenium Server Setup

Selenium Server

下载 Selenium

启动Selenium

配置nightwatch + selenium


什么是nightwatch

Nightwatch.js 是一个用于web网站或应用的自动化测试框架,使用node.js和W3C WebDriver API (熟知的selenium)

它是一个完整的浏览器自动化测试解决方案,能够简化持续集成及自动化测试编写工作。当然它也可以用于nodejs的单元测试过程中。

webdriver 简介

webdriver是一个浏览器自动化的标准库, 它是selenium(最开始是为java设计,现在基本上已经支持大部分语言了)解决方案中的一部分。

Nightwatch使用webdriver作为浏览器任务相关的task,例如打开浏览器实例,保持连接。

webdriver现在已经成为W3C标准, 用于标准化浏览器自动化的实现。

nightwatch的实现原理

nightwatch 通过restful http api与 selenium server通信,从而操作浏览器

Theory of Operation

安装与配置

安装nodejs

首先当然需要安装node.js,安装教程请参考,这里就不详述了

安装nightwatch

npm install -g nightwatch

其中-g参数表示全局安装

Selenium Server Setup

selenium server是webdriver的一个标准化实现,也是最常用的,它允许你通过配置在一个地方同时操作多个不同类型的浏览器,而且可以跟浏览器保持分离,在不同服务器或者电脑上,使用rest http进行通信操作。

Selenium Server

selenium server是一个java应用,nightwatch使用它和多浏览器进行通信。所以你首先需要安装jdk, 不能低于1.7

下载 Selenium

现在最新版本的 selenium-server-standalone-{VERSION}.jar, 下载地址 Selenium downloads 

启动Selenium

$ java -jar selenium-server-standalone-{VERSION}.jar

配置nightwatch + selenium

首先创建一个node.js工程, 创建一个目录名为myproject, 然后进入目录,在终端上运行npm init -y, 生成一个配置文件package.json。

nigthwatch test runner 需要配置一个名为nigthwatch.json的配置文件, 或者nightwatch.conf.js(优先会加载nightwatch.conf.js,没有的话就加载nightwatch.json), 配置文件示例如下

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "page_objects_path" : "",
  "globals_path" : "",

  "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "",
      "webdriver.gecko.driver" : "",
      "webdriver.edge.driver" : ""
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "firefox",
        "marionette": true
      }
    },

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

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

基础配置解析

Nametype

 

 

default

description
src_foldersstring|arraynone测试脚本代码放置的目录
output_folder 
Optional
stringtests_outputJUnit XML report files 保存的位置
custom_commands_path Optionalstring|arraynonecommands 模块的位置目录
custom_assertions_path Optionalstring|arraynoneassertions 模块的位置目录
page_objects_path 
Optional
string|arraynonepage object files 的位置目录
globals_path 
Optional
stringnoneLocation of an external globals module which will be loaded and made available to the test as a property globals on the main client instance. 

Globals can also be defined/overwritten inside a test_settings environment.
selenium 
Optional
object Selenium Server 相关的配置文件
test_settingsobject test 配置模块文件
live_output 
Optional
booleanfalse

并发运行情况下是否缓存测试结果

disable_colors 
Optional
booleanfalse

控制台输出颜色开关

parallel_process_delay 
Optional
integer10

Specifies the delay(in milliseconds) between starting the child processes when running in parallel mode.

 

test_workers 
Optional
boolean|objectfalseWhether or not to run individual test files in parallel. If set to true, runs the tests in parallel and determines the number of workers automatically. 
If set to an object, can specify specify the number of workers as "auto" or a number. 

Example: "test_workers" : {"enabled" : true, "workers" : "auto"}
test_runner 
Optionalsince v0.8.0
string|object"default"Specifies which test runner to use when running the tests. Values can be either default (built in nightwatch runner) or mocha.


Example: "test_runner" : {"type" : "mocha", "options" : {"ui" : "tdd"}}

测试配置

{
  ...
  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "globals" : {
        "myGlobalVar" : "some value",
        "otherGlobal" : "some other value"
      }
    },

    "integration" : {
      "launch_url" : "http://staging.host",
      "globals" : {
        "myGlobalVar" : "other value"
      }
    }
  }
}

如上即为测试配置,测试配置为nightwatch实例运行过程中的配置,配置可以区分环境,例如上述配置中含default配置和integration配置,运行时通过--env来区分:

nightwatch --env integration

通常用这个来区分环境,在不同运行环境下加载不同的配置

安装浏览器驱动 

这里以chrome为例

chrome driver

从 ChromeDriver Downloads 下载合适版本的chrome driver,然后配置项可设置如下

{
  "selenium" : {
    "start_process" : true,
    "server_path" : "./bin/selenium-server-standalone-3.{VERSION}.jar",
    "log_path" : "",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "./bin/chromedriver"
    }
  }
}

至此配置结束,执行命令nightwatch 即可。

 

完整的工程配置请参考https://www.cnblogs.com/saryli/p/6861864.html  这位大神有非常详尽的描述!

 

课程目录

nightwatch + selenium 基于浏览器的web自动化测试 教程(二)

从入门到不放弃:多浏览器的自动化测试(1)- 本地测试 本文将作为多浏览器自动化测试的第一篇文章,给读者从头介绍如何进行本地多浏览的自动化测试工作,包括测试的原理、测试框架的选取、测试工程的搭建和实现等。另外“从入门到不放弃”系列将给读者们带来更多从零开始的前端实践案例,诸如前端组件库设计与实施、项目自动化构建等案例,欢迎大家关注本系列的其他文章。 前端之殇 要是你碰到前端工程师朋友,那聊聊浏览器的兼 阅读详情

相关推荐

掌握Nightwatch与Selenium实现端到端自动化测试

本文深入探讨了使用Nightwatch进行端到端自动化测试的方法,包括其与Selenium的配合使用。从WebDriver的介绍开始,文章详细解释了Selenium Server的REST API、Nightwatch配置以及如何运行端到端测试。同时,文章提供了一个具体的测试用例,帮助读者理解如何在实际项目中应用Nightwatch进行自动化测试。

weixin_30598047的博客 377

【重点】Selenium + Nightwatch 自动化测试环境搭建

1. 创建项目 我们来找个地方新建一个目录,起名为 "my-test-toolkit",然后在目录内使用终端运行 npm init -y 生成项目配置文件package.json。 2. 安装工具 然后我们将安装 Selenium 与 Nightwatch。我们先开始配置 Nightwatch,之前提到这是一款 Test Runner 来着,它负责读取我们的测试脚本,为我们提供 API 来操作浏览器,帮我们控制 Selenium。一. 配置 Nightwatch1.首先,在项目根目录建立文件 "nightw

nhb687095的博客 367

NightWatchTest:使用Nightwatchjs进行Selenium测试的测试工具套件

NightWatchTest 使用端到端的UI测试测试测试自动化框架 , , , 对本地测试和 。 ##先决条件 要继续,您需要Mac,Windows或Linux计算机,并且: 已安装。 (4. * LTS版本) 已安装(通常与node一起安装)。 安装nodejs后,nodejs发行的4. * LTS发行版非常旧,需要升级到最新版本(3. *)。 安装npm npm install npm -g 如果要在Sauce Labs上执行测试,则用户的Sauce Labs用户名和API密钥 使用Git或从浏览器复制此存储库 git clone https://github.com/rkavalap/NightWatchTest or https://github.com/rkavalap/NightWatchTest/archive/master.z

Nightwatch入门(二):安装

安装Node.js 来自nodejs.org: “Node.js是一个基于Chrome JavaScript运行时的平台,可轻松构建快速,可扩展的网络应用程序.Node.js使用事件驱动的非阻塞I / O模型,使其轻量级,高效,非常适合数据密集型实际跨分布式设备运行的时间应用程序。“ 在其网站nodejs.org上有大多数主要操作系统的安装包和说明。请记住还要安装npm工具,它是节点包管理器...

s100200275的博客 1100

nightwatch-browserstack:Nightwatch和BrowserStack自动化的Selenium示例

守夜人浏览器堆栈 与BrowserStack的集成。 设置 克隆仓库 安装依赖项npm install 使用您的BrowserStack用户名和访问密钥更新conf/目录中的*.conf.js文件( ) 运行测试 要运行单个测试,请运行npm run single 要运行本地测试,请运行npm run local 要运行并行测试,请运行npm run parallel 使用我们的了解您需要多少个并行会话 笔记 您可以在查看测试结果 要在一组不同的浏览器上进行测试,请查看我们的 您可以导出BrowserStack帐户的用户名和访问密钥的环境变量 export BROWSERSTACK_USERNAME=<browserstack> && export BROWSERSTACK_ACCESS_KEY=<browserstack> 通过代理服务器

【 Git学习记录(三)】推荐四款主流的Git代码托管平台 —— GitHub、GitLab、Gitee、Coding

了解过Git之后,作为一个程序猿最基本的,你还需要了解目前主流的在线代码托管平台,并至少选择其中一款在平时开发中使用。这里特别介绍以下四款: 国外平台 GitHub —— 全球最流行的代码托管平台 GitLab —— 基于git的仓库管理程序 国内平台 Gitee —— 开源中国旗下的代码托管平台 Coding —— 支持社交元素的代码托管平台 一. GitHub 链接地址:https://github.com/ GitHub目前是全球最流行的代码托管平台(别称:全球最大的同性交友.

JZevin的博客 6114

使用Nightwatch进行E2E测试

本文在线预览E2E测试不同于行为驱动测试(BDD)和单元测试独立运行并使用模拟/存根,端到端测试将试着尽可能从用户的视角,对真实系统的访问行为进行仿真。对Web应用来说,这意味着需要打开浏览器、加载页面、运行JavaScript,以及进行与DOM交互等操作。 然而,项目在快速迭代中不可避免的要进行一遍又一遍测试,费时又费力,而且极有可能因人工失误忽略某些环节。再者,怎么能容忍一次搞定的事非要多次重

祝小余不定时更新 5820

openlayers6【十九】vue HeatmapLayer热力图层实现热力图效果详解

文章目录1. 写在前面2. Heatmap 类实现热力图2.1 Heatmap 参数2.2 实现热力图3. 完整代码4. 添加删除map图层的方法5. 热力图自身的get,set方法 1. 写在前面 我们主要看热力图的效果,区域绘制效怎么设置详细内容可以访问 openlayers6【十七】vue VectorLayer矢量图层画地图省市区,多省市区(粤港澳大湾区)效果详解 在 openlayers 中,图层是使用 layer 对象表示的,主要有 WebGLPoints Layer、热度图(HeatMap L

@必意玲 1万+

e2e自动化之Nightwatch(转)

前言怎么说呢?本司之前用的是selenium Java写的前端自动化。倒也是我写了。不过为什么会想着Nightwatch呢?因为有一天发现自动化挂了。一查看才发现前端加了个蒙板。结果导致xpath变了,然后导航页点击挂了(不能点到导航页,也就进不了具体页面)。改了下倒也不麻烦,但是导runable jar包没给折腾死。实在太多了。想着如今js也是很强的,就找到了Nightwatch。为什么不用ph...

yanpinvon的博客 1314

PID详解

1、什么是PID及其作用 设定一个输出目标,反馈系统传回输出值,如与目标不一致,则存在一个误差,PID 根据此误差调整输入值,直至输出达到设定值. 为什么需要PID呢,比如控制温度,我们需要设置一个要达到的目标温度值,当将温度稳定在目标温度值 例如,我们希望水的目标温度值为70°,其希望无非就是可以快速而且无抖动的达到70°,并稳定在70° 如果我们使用普通的方式加热,当温度到达70°后就以及停止加热,岂不是简单快速,当然用在要求不高的场合也可以,但是如果要求更高的场合呢,会出现温度到达70°后......

weixin_48435215的博客 5万+

谷粒商城篇章9 ---- P248-P261/P292-P294 ---- 消息队列【分布式高级篇六】

RabbitMQ消息队列、RabbitMQ延时队列。

weixin_48568302的博客 1561

使用Nightwatch进行端到端测试

Nightwatch是一套新近问世的基于Node.js的验收测试框架,使用Selenium WebDriver API以将Web应用测试自动化。它提供了简单的语法,支持使用JavaScript和CSS选择器,来编写运行在Selenium服务器上的端到端测试。 不同于行为驱动测试(BDD)和单元测试独立运行并使用模拟/存根,端到端测试将试着尽可能从用户的视角,对真实系统的访问行为进行仿真。对Web

楠人的博客-随风而过 2199

避开ego_planner仿真的第一个坑:深度相机、点云与odom话题配置全指南

本文详细解析了ego_planner仿真中深度相机、点云与odom话题配置的关键问题,帮助开发者避开常见陷阱。从数据流架构到具体配置细节,包括深度相机的内外参匹配、点云数据规范要求以及odom话题的验证方法,提供了全面的实战指南和优化建议。

weixin_30335575的博客 500

Nightwatch——自动化测试(端对端e2e)

背景: 前端页面模拟仿真操作,目的是避免每次更新相关内容重复之前的测试操作,减少不必要的时间投入,以及校验功能的可用性。但是目前元素定位是个问题(每次页面有修改都要重设某些元素定位) 使用Nightwatch进行E2E测试 E2E测试 不同于行为驱动测试(BDD)和单元测试独立运行并使用模拟/存根,端到端测试将试着尽可能从用户的视角,对真实系统的访问行为进行仿真。...

weixin_30492047的博客 233

安装 Claude Code 并接入阿里云百炼(Bailian)

这些工具通常提供可视化界面,只需在设置中填入阿里云百炼的 API Key 和 Base URL 即可,无需配置环境变量。注意:如果你使用的是阿里云百炼的 Coding Plan 套餐,请使用该套餐专属的 API Key 和 Base URL。你可以使用文本编辑器打开该文件,或者在终端使用命令(如 macOS/Linux 下使用 nano ~/.claude/settings.json)。你可以直接用自然语言下达指令,例如:“帮我在这个目录下写一个 Python 脚本,实现两数之和的功能”。

hopsky的博客 1867

stata 工具变量法【计量经济系列(七)】

stata 工具变量法【计量经济系列(七)】 1. 内生性 2. 工具变量3. 2SLS (二阶段最小二乘法) 4. 弱工具变量5. 工具变量外生性的过度识别检验 6. 豪斯曼检验6.1 传统豪斯曼 6.2 杜宾-吴-豪斯曼检验(DWH)

侯小啾技术博客 2万+

基于Nightwatch.js与Cucumber的跨浏览器自动化测试实战指南

自动化测试是现代软件工程保障质量的关键环节,其核心原理是通过脚本模拟用户操作,对应用进行端到端验证。行为驱动开发(BDD)作为一种敏捷实践,通过自然语言描述测试场景,弥合了技术与非技术人员之间的沟通鸿沟,提升了测试用例的可读性与可维护性。结合Nightwatch.js这一基于Node.js的E2E测试框架,能够直接与WebDriver协议交互,实现对Chrome、Firefox等多浏览器的自动化控制,其价值在于构建稳定、可重复且易于协作的测试体系。本文聚焦于将BDD理念与跨浏览器自动化测试相结合的具体工程实

weixin_33739627的博客 410

linux内核学习(一)---内核社区介绍及补丁提交

本系列开始会对linux内核进行系统性的学习,以源码与内核社区为基础,了解前沿的内核机制,同时也深度了解linux内核中的一些经典机制 本章会先对linux内核社区进行简单的介绍,包括源码下载、内核社区的修改提交

文艺小少年的博客 542

Nightwatch入门(一):概述

什么是Nightwatch? Nightwatch.js是一个用于Web应用程序和网站的自动化测试框架,使用Node.js编写并使用W3C WebDriver API(以前称为Selenium WebDriver)。它是一个完整的浏览器(端到端)测试解决方案,旨在简化设置持续集成和编写自动化测试的过程。 Nightwatch也可用于编写Node.js单元测试。 –Nightwatch的名字来源...

s100200275的博客 8222

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

nightwatch + selenium 基于浏览器的web自动化测试 教程(二)

上一篇已经讲述了如何搭建环境,这一片主要针对语法进行 目录 测试案例 Using XPath选择器   测试案例 module.exports = { 'Demo test Google' : function (browser) { browser .url('http://www.google.com') .waitForElementVisi...

Viogs的专栏 1303

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Nightwatch.js – 轻松实现浏览器的自动测试

  Nightwatch.js是一个易于使用的,基于 Node.js 平台的浏览器自动化测试解决方案。它使用强大的 SeleniumWebDriver API 来在 DOM 元素上执行命令和断言。...

QDY5945的博客 212

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

几个Web自动化测试框架的比较:Cypress、Selenium和Playwright

Cypress擅长开发人员友好性和强大的调试功能,Selenium则因其广泛的浏览器、语言和社区支持而令人印象深刻,而Playwright则因其速度和本地并行测试执行而脱颖而出。本文探讨来3种流行的Web自动化测试框架——Cypress、Selenium和Playwright,总结了它们的优点和缺点,希望可以为大家在选择测试框架时提供参考。这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!

NHB456789的博客 1453

Nightwatch.js深度解析

Nightwatch.js是一个基于Node.js的Web自动化测试框架,使用WebDriver API模拟用户操作进行端到端测试。它能验证功能、跨浏览器兼容性、响应式布局和性能指标,并通过自动化回归测试确保代码更新不影响现有功能。安装简单,测试脚本编写直观,支持页面对象模式和数据驱动测试。相比Selenium配置更简单,比Cypress支持更多浏览器,比Puppeteer更专注于测试场景。最佳实践包括合理组织测试结构、分离测试数据、优化等待策略以及集成到CI/CD流程中,适合需要快速实现Web自动化测试的

leohu0723的博客 322

nightwatch系列教程01——Hello Nightwatch

本文主要介绍了流行的端到端测试框架nightwatch的基本知识,并且介绍了安装步骤,最后实现了一个小的测试用例并且运行成功。欢迎围观。

袁杰Jerry 2921
上一篇: centos 安装 docker-ce
下一篇: nightwatch + selenium 基于浏览器的web自动化测试 教程(二)
Viogs
博客等级 码龄15年 29粉丝 60原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址