English 中文(简体)
Cypress - Fixtures
  • 时间:2024-03-24 09:05:35

Cypress - Fixtures

Previous Page Next Page  

添加气压装置,以保持和掌握自动化测试数据。 固定装置在Cypress项目夹(Example.json文档)内。 基本上,它帮助我们从外部档案中获得数据投入。

Features

气压固定装置的夹可有JSON或其他格式的文档,数据则以“钥匙:价值”制成。

所有测试数据都可以通过一次以上的测试加以利用。 所有固定装置数据必须在前栏目中公布。

Syntax

The syntax for Cypress data Drive test is as follows -


cy.fixture(path of test data)
cy.fixture(path of test data, encoding type)
cy.fixture(path of test data, opts)
cy.fixture(path of test data, encoding type, options)

这里

    编码类型——编码类型(tf-8, asci,等等)用于读文档。

    Opts − Modifies the timeout for response. The default value is 30000ms. The wait time for cy.fixture(), prior throws an exception.

Implementation in example.json

下面是用example.json在Cypress进行数据驱动检测。


{
   "fullName": "Robert",
   "number": "789456123"
}

Implementation of Actual Test

在Cypress实施实际数据驱动测试如下:


describe( Tutorialspoint Test , function () {
   //part of before hook
   before(function(){
      //access fixture data
      cy.fixture( example ).then(function(regdata){
         this.regdata=regdata
      })
   })
   // test case
   it( Test Case1 , function (){
      // launch URL
      cy.visit("https://register.rediff.com/register/register.php")
      //data driven from fixture
      cy.get( :nth-child(3) > [width="185"] > input )
      .type(this.regdata.fullName)
      cy.get( #mobno ).type(this.regdata.number)
   });
});

产出如下:

Data Driven Testing in Cypress

产出记录显示,将罗伯特和789456123的数值分别输入全称和移动区。 这些数据已经通过固定装置进行测试。

Advertisements