在Cypress中重复执行

huangapple go评论55阅读模式
英文:

Repeat in cypress

问题

我现在正在进行负载测试,需要创建14000张票来查看应用程序的响应。

我的问题是如何重复简单的自动测试,直到我获得14000张票的注册。

/// <reference types="cypress" />

Cypress._.times(1000, () => {
  const timestamp = new Date().getTime();

  describe('Load', () => {
    it('Loadtest', () => {
      cy.visit('link') // 访问站点
      cy.get('#email').type('name') // 输入用户名
      cy.get('#password').type('password') // 输入密码
      cy.get('._btn_1wzi7_1').click() // 单击登录按钮
      cy.get('.css-19bb58m').type('Microsoft Outlook 2').type('{enter}')
      cy.get('#title').type(`Random Text ${timestamp}`)
      cy.get('#note').type(`Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} 
      Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp}
      Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp}`)
      cy.get('#checkbox').click() // 按下应该被按下的复选框
      cy.get('._btn_1wzi7_1').click()
      cy.get('._title_1jitq_37').should('have.text', '10000') // 这个数字是创建的票的ID,每创建一张票后会递增。
    })
  })
})

现在它将重复这个测试1000次,当我将它设为2000时,它运行得更慢。

我需要在cy.get('._title_1jitq_37').should('have.text', '10000')变成24000时重复执行。

英文:

I am doing load test right now and need to create 14000 tickets to see how app will response.

My question is about how to repeat simple auto test, until I get 14 000 ticket registration.

<!-- language: js -->

/// &lt;reference types=&quot;cypress&quot; /&gt;

Cypress._.times(1000, ()=&gt;{

const timestamp = new Date().getTime();  

describe(&#39;Load&#39;, ()=&gt;{


    it(&#39;Loadtest&#39;, ()=&gt;{
    
    cy.visit(&#39;link&#39;)// visit site
    cy.get(&#39;#email&#39;).type(&#39;name&#39;)//insert username
    cy.get(&#39;#password&#39;).type(&#39;password&#39;)//insert password
    cy.get(&#39;._btn_1wzi7_1&#39;).click() //click login button 
    cy.get(&#39;.css-19bb58m&#39;).type(&#39;Microsoft Outlook 2&#39;).type(&#39;{enter}&#39;)
    cy.get(&#39;#title&#39;).type(`Random Text ${timestamp}`)
    cy.get(&#39;#note&#39;).type(`Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} 
    Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp}
    Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp} Another Random Text ${timestamp}`)
    cy.get(&#39;#checkbox&#39;).click() //press check box which should be pressed
    cy.get(&#39;._btn_1wzi7_1&#39;).click()//
    cy.get(&#39;._title_1jitq_37&#39;).should(&#39;have.text&#39;, &#39;10000&#39;) //this number is the id of created ticket and it increments after each created ticket.       

   
    })
      
})

})`

Right now it repeats that test 1000 times and when I make it 2000 it works slower.

I need it repeated when this cy.get(&#39;._title_1jitq_37&#39;).should(&#39;have.text&#39;, &#39;10000&#39;) become to 24000.

答案1

得分: 2

不要翻译的内容:Rather than looping 14_000 times in your test, try it with cypress-grep burn parameter.

For example

npx cypress run --env burn=5 --spec cypress/integration/A.js

I haven't tried it with that many iterations, so can't say it will be quicker, but the way you have tried generates a very large spec that must be parsed into a queue and stored in memory.

As I understand it, cypress-grep controls the burn from the Cypress node (background) process so the memory footprint is likely to be smaller.

Ref: Current home page with install instructions and usage details.

英文:

Rather than looping 14_000 times in your test, try it with cypress-grep burn parameter.

For example

npx cypress run --env burn=5 --spec cypress/integration/A.js

I haven't tried it with that many iterations, so can't say it will be quicker, but the way you have tried generates a very large spec that must be parsed into a queue and stored in memory.

As I understand it, cypress-grep controls the burn from the Cypress node (background) process so the memory footprint is likely to be smaller.

Ref: Current home page with install instructions and usage details.

huangapple
  • 本文由 发表于 2023年2月24日 16:03:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553967.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定