cypress

Incrementing and decrementing the value of an <input type=“number”/> in Cypress

烈酒焚心 提交于 2020-08-09 21:08:06
问题 I would like to test incrementing and decrementing the value of an HTML input field ( type="number" ) in Cypress. More precisely, I would prefer to increment and decrement the value using the arrow keys, but I can't seem to get this to work using the most apparent approach. As a minimal working example, I have set up a React component whose render method looks as follows: render() { return (<input type="number" />); }; Outside of Cypress, typing into this field works without any problems. The

Cypress学习3-操作页面元素(Actions行为事件)

[亡魂溺海] 提交于 2020-08-09 05:27:00
前言 ui自动化操作页面上的元素,常用的方法就那么几个,输入文本,点击元素,清空文本,点击按钮。 还有一些特殊的checkbox,radio,滚动条等。 .type() 往输入框输入文本元素 <form> <div class="form-group"> <label for="email1">Email address</label> <input type="email" class="form-control action-email" id="email1" placeholder="Email"> </div> <div class="form-group"> <label>Disabled Textarea</label> <textarea class="form-control action-disabled" disabled="disabled"></textarea> </div> </form> cy.get('.action-email') .type('fake@email.com').should('have.value', 'fake@email.com') // .type() with special character sequences .type('{leftarrow}{rightarrow}{uparrow}{downarrow}')

why is drag drop not working as per expectation in cypress.io?

不想你离开。 提交于 2020-08-08 05:17:07
问题 I am trying to automate a simple drag and drop scenario on a website . https://gojs.net/latest/samples/htmldragdrop.html I am going as per the method provided in cypress doc https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__drag-drop/cypress/integration/drag_n_drop_spec.js my sample testcases is : cy.visit("https://gojs.net/latest/samples/htmldragdrop.html") cy.get('#paletteZone .draggable').first().trigger('mousedown', { which: 1 }) .trigger('mousemove',

How do interact correctly with a range input (slider) in Cypress?

一笑奈何 提交于 2020-08-08 05:15:26
问题 I'm writing my bachelor thesis about e2e testing in javascript althought I'm not familiar with testing or javascript. So I have this the range input "slider" from the src <input id="sum_slider" class="input-range js-inv-calc-input-sum-range js-input-range" type="range" name="investmentsum" min="20000" max="150000" value="20000" step="1000" title="Investitionsbetrag" style="background: -webkit-linear-gradient(left, rgb(255, 196, 0) 0%, rgb(255, 196, 0) 0%, rgb(119, 119, 119) 0%) no-repeat;">

Angular - adding Cypress data-cy attribute

让人想犯罪 __ 提交于 2020-08-07 05:19:10
问题 I just yesterday started using cypress.io with angular, as the docs say, I'm using the attribute data-cy to specifically target elements <div data-cy="myelement">Hello</div> cy.get("[data-cy]=myelement") The problem is that angular doesn't recognize the data-cy attribute if I want to bind it dinamically <div *ngIf="user$ | async as user" [data-cy]="user.name">Online</div> Do I have to create a personal directive to add that attribute dinamically? Or there is a better way ? 回答1: Angular treats

Angular - adding Cypress data-cy attribute

≯℡__Kan透↙ 提交于 2020-08-07 05:18:32
问题 I just yesterday started using cypress.io with angular, as the docs say, I'm using the attribute data-cy to specifically target elements <div data-cy="myelement">Hello</div> cy.get("[data-cy]=myelement") The problem is that angular doesn't recognize the data-cy attribute if I want to bind it dinamically <div *ngIf="user$ | async as user" [data-cy]="user.name">Online</div> Do I have to create a personal directive to add that attribute dinamically? Or there is a better way ? 回答1: Angular treats

Cypress学习12-父子元素定位

痴心易碎 提交于 2020-08-06 09:28:28
前言 先定位父元素,通过父元素定位子元素 .children() 通过父元素,定位子元素 <ol class="traversal-breadcrumb breadcrumb"> <li><a href="#">Home</a></li> <li><a href="#">Library</a></li> <li class="active">Data</li> </ol> cy.get('.traversal-breadcrumb') .children('.active') .should('contain', 'Data') .closest() 要获取最近的祖先DOM元素,请使用.closest()命令。 <ul class="list-group"> <li class="list-group-item"> <span class="badge">14</span> Events </li> <li class="list-group-item"> <span class="badge traversal-badge">54</span> Friends </li> </ul> cy.get('.traversal-badge') .closest('ul') .should('have.class', 'list-group') .eq() 要在特定索引处获取DOM元素

Cypress web自动化18-cypress.json文件配置baseUrl

大憨熊 提交于 2020-08-05 17:52:02
前言 当我们测试一个web网站的时候,一般最好设置一个baseUrl地址,这样方便维护。 一旦部署环境发生了改变,就不需要去基本里面去查找,秩序更改cypress.json文件即可 cypress.json文件 如果我的web服务部署环境是 http://49.235.x.x:8080 于是在项目的根目录找到cypress.json文件 { "baseUrl": "http://49.235.x.x:8080" } 设置窗口大小 也可以设置浏览器的默认宽和高,如果没设置果,浏览器默认的宽高是 660*1000 可以在 cypress.json 文件中改变这个值 { "baseUrl": "http://49.235.x.x:8080", "viewportWidth": 1280, "viewportHeight": 600 } 后面测试用例如果需要指定特定大小窗口,也可以用cy.viewport()命令去设置 参考前面这篇[https://www.cnblogs.com/yoyoketang/p/12878064.html](https://www.cnblogs.com/yoyoketang/p/12878064.html) 查找测试文件 cypress 默认查找 cypress/integration 下的 js 文件测试用例,查找项目目录也可以自己定义

Cypress学习9-聚焦元素focused,截图screenshot使用

删除回忆录丶 提交于 2020-08-05 17:27:44
前言 在页面上点击输入框时,可以用 cy.focused() 判断当前元素是不是聚焦元素。 屏幕截图,这是web自动化经常用到的功能,可以用cy.screenshot()实现 .end() 结束命令链 // cy.end is useful when you want to end a chain of commands // and force Cypress to re-query from the root element cy.get('.misc-table').within(() => { // ends the current chain and yields null cy.contains('Cheryl').click().end() // queries the entire table again cy.contains('Charles').click() }) cy.exec() 退出系统命令 / execute a system command. // so you can take actions necessary for // your test outside the scope of Cypress. cy.exec('echo Jane Lane') .its('stdout').should('contain', 'Jane Lane')

Cypress学习3- 登录案例脚本

社会主义新天地 提交于 2020-08-05 10:27:26
前言 先从第一个登录页面的案例开始,写一个登陆案例的脚本示例,这里以禅道网站登录为例。 登录脚本 脚本实现功能: 输入用户名,断言输入框输入成功 输入密码,断言输入成功 点登陆按钮 断言1 判断页面重定向跳转到首页 断言2 判断页面包含某个文件 断言3 判断登录成功后,cookie存在 login_web.js脚本参考示例 /** * Created by dell on 2020/5/11. * 作者:上海-悠悠 交流QQ群:939110556 */ describe('登陆web网站案例', function() { beforeEach(() => { cy.visit('http://ip:8080/zentao/user-login.html') }) it("登陆案例", function() { // 输入用户名 cy.get('#account').type('admin') .should('have.value', 'admin') // 输入密码 cy.get('[name="password"]').type('***123456') .should('have.value', '***123456') // 提交表单 cy.get('#submit').click() // 判断页面跳转到 /zentao/my/ cy.url().should(