想要执行所有测试用例n次?

问题描述 投票:0回答:1

我是 Cypress 的初学者。我使用 Cypress 和 javascript 来执行自动化测试。

问题:如何将所有块迭代n次?

描述: 在 JSON 文件中,一个键有一个包含不同配置文件名称的数组。我有一个规范文件,其中有多个

it()
块。现在我想为密钥中可用的所有配置文件运行我的规范文件。

为此,我尝试了以下解决方案:

测试数据.JSON

{
"test": {
    "customerAccountName": "RD test R97 01 new",
    "userRole": "Customer Admin",
    "profiles": ["Generic SIP Service", "Genesys PureCloud"],
    "profile": "",
    "serviceCarrier": "",
    "isCarriage": "",
    "type": "",
    "blockSize": ""
}
"stage": {
    "customerAccountName": "RD test R97 01 new",
    "userRole": "Customer Admin",
    "profiles": ["Generic SIP Service", "Genesys PureCloud"],
    "profile": "",
    "serviceCarrier": "",
    "isCarriage": "",
    "type": "",
    "blockSize": ""
}

TestSpec.js

describe("Create, edit, pause, resume and delete Generic SIP Service", function () {

let siteTestData, credentials, SIPServiceTestData, profiles;
before(function () {

cy.fixture('credentials').then(function (testdata) {
  credentials = testdata[window.environment]

  //Login to a portal if require
  if (isLoginRequire(credentials.sausername, credentials.sapassword)) {
    cy.loginAs(credentials.url, credentials.sausername, credentials.sapassword)
  }
})

//Get test data from 'genericSIPServiceTestData' file
cy.fixture('SIPServiceTestData').then((testData) => {
  SIPServiceTestData = testData[window.environment]
  profiles = SIPServiceTestData.profiles
})

//Get test data from 'siteTestData' file
cy.fixture('siteTestData').then(function (testdata) {
  siteTestData = testdata[window.environment]
  //If siteName is empty, add site name
  if (siteTestData.siteName == '') {
    siteTestData.siteName = 'Automation site ' + getUTCTime()
  }
  //If siteEmail is empty, add site email
  if (siteTestData.siteEmail == '') {
    siteTestData.siteEmail = 'automationtestsite' + getUTCTime() + '@gmail.com'
  }
  //If updateSiteName is empty, add site name to update
  if (siteTestData.updateSiteName == '') {
    siteTestData.updateSiteName = 'Update ' + siteTestData.siteName
  }
})
})




it("Load test profiles", function () {

Array.from(profiles).forEach($profile => {


  describe('test json loop', function () {

    beforeEach(() => {
      SIPServiceTestData.profile = $profile
    })

    after(() => {
      console.log('inside after')
      // Only log out if require
      if (isLoginRequire(credentials.sausername, credentials.sapassword)) {
        cy.logout();
      }
    });

    it("Navigate to Customer account", function () {
      //Navigate to customer account
      clickCustomer(SIPServiceTestData.customerAccountName)
      //Verify services header on services page
      verifyServicesHeader()
    })

    it("Verify either account is existing or new", function () {
      isAccountNew(siteTestData)
    })

    it("Click on 'Add new service' button, select SIP service and Navigate to 'Select numbers' page", function () {
      //Click on services tab
      clickServicesTab();
      //Add service button should be enable on services page
      getAddServiceButton().should('be.visible').and('be.enabled').and('have.text', 'Add New Service').click();
      //Select profile and carrier, and navigate to select numbers page
      selectProfileAndCarrier(SIPServiceTestData);
      //Verify sub header
      getAccountName().should('be.visible').and('have.text', SIPServiceTestData.customerAccountName)
      //Verify header section and search field on select numbers page
      verifyHeaderOnSelectNumberPage(SIPServiceTestData)
      //Verify tooltip text on hover of inventory number on select number page
      verifyTooltipOnSelectNumberPage()
      //Select number
      selectNumberForServices()
      //Set details of selected number into json
      setSelectedNumberDetails(SIPServiceTestData)
    })
  })
})
});
})

当我运行上面的代码时,它工作正常。但 Cypress chrome 窗口并未在其 UI 中显示所有块。

enter image description here

这个问题有什么解决办法吗?如果不... 有没有其他解决方案可以多次迭代它并正常工作?

javascript cypress
1个回答
0
投票

读取规范文件顶部的测试数据,然后循环遍历各个部分。

类似的东西

const testData = require('../fixtures/testdata.json') // assume spec is in cypress/e2e

Object.entries(testData).forEach(([key, data]) => {

  it('test1', ...

  it('test2', ...


})
© www.soinside.com 2019 - 2024. All rights reserved.