Cypress Tutorial – Basics

前端Cypress自动化测试全网详解 Cypress 是一个强大的端到端(End-to-End, E2E)功能测试框架,基于 Node.js构建,支持本地浏览器直接模拟测试,并具有测试录屏功能,极大地方便了测试失败时的场景重现与问题定位。本文将详细介绍 Cypress的安装、配置以及一个实际的自动化测试示例。 阅读详情

注明本文转载于:https://www.toolsqa.com/cypress-tutorial/

Cypress Tutorial

Cypress Basics

Cypress  is a free and open source automation tool, MIT-licensed and written in  JavaScript . As of this writing, it has over 19.3K Stars on Github and is used by organisations such as NASA and DHL. With help of Cypress End to End test , integration and unit tests are easy to write and debug.

Along with the test script runner, Cypress provides you a visual interface to indicate what all tests and which all commands are running, passed or failed. It allows us to test highly interactive applications and carry out different tests such as manipulating the DOM, asserting that if some element is available or present on the screen, reading or writing data into/from fields, submitting forms and even redirecting to a different page without actually making direct modifications to your code.

Cypress is built and optimized as a tool for local development. In fact, after using Cypress for some time, you may be tempted to do all of your development within it since it provides a platform to quickly debug and maintain your code easily.

Cypress Tutorial – Basics

Introduction and Architecture: Cypress is a next-generation front end testing tool constructed for modern web applications. Most testing tools (like Selenium) operate by running outside of the browser and executing remote commands across the network. But the Cypress engine directly operates inside the browser.  It enables Cypress to listen and modify the browser behavior at run time by manipulating DOM and altering Network requests and responses on the fly.

Node Installation and Setup: Node.js is a server-side runtime environment that is built on top of Chrome’s V8 JavaScript engine.  It is open-source, totally free of cost, and millions of developers use it across the globe. It is a runtime environment. Additionally, it includes everything you need to run a program written in JavaScript. You are required to Install Node JS framework before start building your Node.js application.

Install VS Code: Visual Studio Code editor is a lightweight but strong source code editor that runs on your desktop and is available for Windows, macOS, and Linux. Visual Studio Code has built-in support for JavaScript, TypeScript, and Node.js and has an extensive ecosystem of extensions for other languages (such as C++, C#, Java, Python, PHP, Go) and runtimes (such as .NET and Unity).

Cypress Installation and Project Setup: Cypress can be downloaded directly from the Cypress CDN (https://download.cypress.io/desktop). The direct download will always download the latest version for your platform. It will download a zip file, which can be extracted by the user. and it can also be Downloaded using npm. It also explains how to set up a basic project with package.json and cypress installed with it.

Cypress Test: The basis of Cypress is Mocha and Chai (one of the famous assertion libraries in JavaScript), and it adheres to the same style of writing test cases as will be used by any other JavaScript-based framework. We will use the default folder structure provided by Cypress to manage and write our test cases in the Cypress Workshop project and will learn how to operate Cypress with its basic test case.

Cypress Test Runner: Cypress has a unique test runner that allows us to see commands as they execute. Additionally, it also shows the real-time run of the application under test. We will complete the development of our first automated test case using Cypress and we will be executing that test case with the help of the Cypress Test Runner. We will also learn about different components Test Runner has and how we can operate that using the terminal.

Locator in Cypress: Locators are the backbone for all automation frameworks for Web-based applications. Additionally, a locator is an identifier that tells any automation tool that GUI elements ( say Text Box, Buttons, Check Boxes, etc.); it needs to operate. Following the same concepts, Cypress also uses the locators to identify the UI element for the application under test.

Get and Find Command: Cypress provides two essential methods get() and find() to search for the web elements based on the locators. The results for both of these methods are almost identical. But each has its importance and place of implementation. Subsequently, in this article, we will be covering aspects detailing where get() and find() methods that can be used during the web test automation using Cypress.

Cypress Asynchronous Nature: Asynchronous programming is a means of parallel programming whereby, a unit of work runs separately from the main application thread. Additionally, it notifies the calling thread of its completion, failure, or progress. These types of programs are “non-blocking.” When you execute something synchronously, you wait for it to finish before moving on to another task.  On the other hand, when you run something asynchronously, you can move on to another task before it ends.

Handle Non-Cypress async promises: We know that Cypress internally handles the asynchronous behavior of its commands and still provides a seamless, sequential, and consistent execution of the test cases. Still, there can be situations, such as combining the Cypress commands with third-party libraries or JavaScript commands, where we have to handle the async promises or commands explicitly. We will learn that how Cypress can help in managing these Non-Cypress Async Promises explicitly

Cypress Assertions: Assertions are the validation steps that determine whether the specified step of the automated test case succeeded or not. In actual, Assertions validates the desired state of your elements, objects, or application under test. Eg. assertions enable you to validate scenarios such as whether an element is visible or has a particular attribute, CSS class, or state. It is always a recommended practice that all the automated test cases should have assertion steps, otherwise, it will not be feasible to validate whether the application reached the expected state or not.  

Interacting with DOM Elements: Each UI automation tool provides some APIs or methods to interact with the web elements, so the designated operation can be performed on the UI element. In addition to this, these methods also assist in the needed user journey simulation. Continuing the same practice, Cypress also provides multiple commands which can simulate the user’s interaction with the application.

 

There are many more articles planned for Cypress Tutorial series, please stay tuned with us at TOOLSQA. Happy Learning.

注明本文转载于:https://www.toolsqa.com/cypress-tutorial/

2024Cypress自动化测试开发指南!_cypress教程 在实际使用cypress过程中,cypress是支持直接对js文件直接运行的,但如果所写的自动化测试代码在不同的文件,当启动测试时需要在不同的文件间切换,每次切换需要重启浏览器,这使得测试过程显得十分臃肿,cucumber建议:可以通过创建.features文件来利用这一点。确保你已经运行过npm init或者有node_modules文件夹或包package.Json文件,以确保cypress安装在正确的目录下。当然使用上述安装方式也可也直接实现cypress的创建,但建议使用npm统一创建,统一管理。 阅读详情

相关推荐

利用Cypress建立自动化项目:重复任务系统案例研究

在当今快节奏的开发环境中,自动化测试已成为确保软件质量和效率的必要条件。在各种测试框架中,Cypress 以其速度、可靠性和易用性脱颖而出。本文探讨如何使用 Cypress 建立强大的自动化项目,重点关注重复任务系统 (RTS) 作为被测系统 (SUT)。

software_test010的博客 1057

03 Tutorial: basics

Usage of computations All reikna computation classes are derived from the Computation class and therefore share the same API and behavior. A computation object is an opaque typed function-like obj...

Loong Cheng的博客 303

basic-cypress-set-up

如何执行这个专案 待定 Cypress.json示例 { "watchForFileChanges": false, "env": { "siteUsername": "example email address", "sitePassword": "password", "incorrectPassword": "123456" } }

cypress自动化测试工具开发指南

待到秋来九月八,我花开后百花杀简介 简介

qq_40893595的博客 8280

cypress-basic

UI计数器 超简单的任务来学习赛普拉斯 :fire: 项目! 通过称为计数器的简单任务,熟悉名为Cypress的E2E工具。 通过实现以下简单功能,您可以轻松使用赛普拉斯工具。 创建后,它将呈现按钮和初始值(10)。 单击+按钮时,计数增加1。 -单击按钮时,计数减少一。 按下+按钮时,如果计数超过12,则无法再增加。 (最大值为12) -按下按钮时,如果计数少于8,则不能减少计数。 (最小值为8) :thermometer: 动手:赛普拉斯的安装和使用 yarn install or npm install cypress open 检查结果 运行画面 动作日志 :clapping_hands: 贡献 如果您在执行任务时看到任何改进,请随时发送PR。 :lady_beetle: 错误报告 如果发现错误,请注册问题。 :memo: 执照 该项目是麻省理工学院许可的。

手把手带你编写miniQMT实盘量化执行程序(3) | 交易系统

本文介绍了miniQMT实盘量化执行系统的核心交易系统代码,重点讲解了其模块化设计和工作流程。系统采用主控类LiveSystem管理交易全流程,包含初始化引擎、交易日判断、交易时段划分(开盘前、盘中、收盘等)、主循环调度和异常处理等核心功能。作者详细解析了系统如何实现365天不间断运行、精准判断交易日、分阶段执行交易策略等功能,并强调系统的稳定性和异常处理机制。

1306

2024Cypress自动化测试开发指南!

在实际使用cypress过程中,cypress是支持直接对js文件直接运行的,但如果所写的自动化测试代码在不同的文件,当启动测试时需要在不同的文件间切换,每次切换需要重启浏览器,这使得测试过程显得十分臃肿,cucumber建议:可以通过创建.features文件来利用这一点。在这个示例中,我们使用cypress编写了一个测试套件,包括访问登录页面、输入用户名和密码、点击登录按钮以及验证登录成功这四个测试步骤。通过这个示例,可以看到cypress的简洁语法和强大功能,使得编写自动化测试变得非常容易和高效。

2301_77709772的博客 1267

LMK04821时钟芯片SPI配置避坑指南:从寄存器读写到频率校准全流程

本文详细解析了LMK04821时钟芯片的SPI配置全流程,涵盖寄存器读写、频率校准及JESD204B系统设计中的关键技巧。通过实战案例和避坑指南,帮助工程师高效解决时钟输出异常、同步失败等常见问题,提升高速数据采集系统的时钟稳定性。

weixin_29172963的博客 159

自动化测试-Cypress快速入门

cypress是一个前端自动化测试工具,测试代码和测试程序可以在同一个浏览器下运行,运行效率高,支持F12调试,操作截图等,是一个很简便的自动化测试工具

seanyang_的博客 2168

ZYNQ出现问题及解决办法汇总(一直更新)

问题目录使用软件及开发板版本一,vitis在build project时卡住。二,Could not find FPGA device on the board for connection 'Local'三,FPGA configuration failed:DONE PIN is not high四,Could not find ARM device on the board for connection 'Local' 使用软件及开发板版本 开发板:MZ7XA-7020 软件:vitis2020.2(

qq_45057368的博客 1万+

ISP模块之色彩增强算法--HSV空间Saturation通道调整

色彩增强不同于彩色图像增强,图像增强的一般处理方式为直方图均衡化等,目的是为了增强图像局部以及整体对比度。而色彩增强的目的是为了使的原有的不饱和的色彩信息变得饱和、丰富起来。对应于Photoshop里面的“色相/饱和度”调节选项里面对饱和度的操作。色彩增强的过程,并不改变原有彩色图像的颜色以及亮度信息。     在我的色彩增强算法模块里面,始终只针对色彩饱和度(Saturation)信息做研究,

松间明月 1万+

Cypress自动化测试框架基础(一)

npx详解npx(Node Package Runner)和npm(Node Package Manager) 是两个不同的 Node.js 工具,它们之间有着一些区别和联系。npm是 Node.js 的包管理器,用于安装、升级和删除 Node.js 模块。它还提供了一些有用的命令,如npm initnpm update等。与此不同,npx仅用于执行已安装的模块或从 npm 仓库下载和执行模块。npm可以在全局范围内安装模块,使其在任何目录中可用。与此相比,npx。

Fddadd的博客 4090

Visual Studio 命令提示符工具区别与使用场景

Visual Studio会提供一系列命令提示符工具,这些工具应用在哪些场景呢?本文进行了相关介绍。

cicada15的博客 3493

Cypress自动化测试开发指南!零基础入门到精通,收藏这篇就够了

cypress是基于JavaScript语言为编写语言的自动化测试开发工具,配合使用cucumber测试开发框架,以node.js为服务进程,可以简单的帮助测试人员完成需要人工手点的所有页面人机交互操作,可以模拟键盘和鼠标输入,快捷完成case的测试。

leah126的博客 1098

2026年AI技能进阶指南:从提示词工程到智能体开发实战

提示词工程作为AI时代的基础沟通技能,其核心原理是通过系统化的交互方法论实现与大模型的高效对话。这项技术通过明确性、具体性和可操作性的设计原则,显著提升了AI生成内容的质量和实用性。在工程实践层面,提示词工程已经发展出角色扮演、步骤分解等成熟模式,广泛应用于代码生成、技术方案设计等场景。随着AI智能体开发的兴起,提示词工程进一步演化为定义智能体身份认知和行为规范的系统接口设计,成为构建自主AI系统的关键技术基础。掌握从基础提示词到智能体开发的完整技能栈,能够帮助开发者在AI技术浪潮中保持核心竞争力。

weixin_33139275的博客 333

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Cypress自动化测试中文教程:让自动化测试更高效

Cypress自动化测试中文教程:让自动化测试更高效 【下载地址】Cypress自动化测试中文教程 Cypress自动化测试中文教程为您提供了全面的中文学习资源,专为测试工程师和开发人员设计。Cypress是一款现代化的JavaScript端到端测试框架,具有易于安装、内置断言库和高效并行化测试等显著特点。本教程从基础知...

gitblog_06764的博客 478

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Cypress 自动化测试框架教程

Cypress 自动化测试框架教程 【免费下载链接】cypress Fast, easy and reliable testing for anything that runs in a browser. 项目地址: https:...

gitblog_00050的博客 1052

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Cypress系列(101)- intercept() 命令详解

如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 作用 使用该命令在网络层管理 HTTP 请求的行为 包含以下功能 对任何类型的 HTTP 请求进行 stub 或 spy 在 HTTP 请求发送到目标服务器前,可以修改 HTTP 请求 body、headers、URL(类似抓包...

qq_33801641的博客 2959

e2e测试框架之Cypress

谈起web自动化测试,大家首先想到的是Selenium!随着近几年前端技术的发展,出现了不少前端测试框架,这些测试框架大多并不依赖于Selenium,这一点跟后端测试框架有很大不同,如Robot Framework做Web自动化测试本质上还是使用的Selenium,包括各语言的xUnit单元测试框架。 多吧!这还只是一部分呢?你以为这些都是不知名的小项目?错了! 我特地把Selenium加了进...

weixin_34167819的博客 662

前端开发:基于cypress的自动化实践

作为一个伪开发,在一个平台项目中负责前端的开发工作,开发框架为vue,本文我会站在前端开发的角度介绍,我是如何使用cypress的。 [x] 如何在vue中使用cypress [x] 如何运行cypress [x] 如何编写测试用例 [x] 如何解决测试数据的问题 [x] 遇到的元素定位的问题 [x] 如何看待cypress [x] cypress是否为最佳工具 [x] 测试怎么办? 如何在vue中使用cypress购优惠 m.fenfaw.cn vue提供了vue-cli 可以快速的创建vue项目。 v.

nidongla的博客 314
上一篇: loadrunner Lr_类函数之 lr_xml_transform()
下一篇: What is Cypress: Introduction and Architecture
testingstar
博客等级 码龄15年 77粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值