English 中文(简体)
Cypress - Assertions
  • 时间:2024-03-24 11:11:26

Cypress - Assertions

Previous Page Next Page  

飓风从Mocha、Chai等各种图书馆获得的不止一种说法。 这种说法是明确和暗含的。

Imppcit Assertions

如果断言适用于从母公司在链条下获得的物体,则称为默示主张。 民众的含蓄说法包括......和/或应当。

这些指挥不能单独使用。 一般来说,当我们必须核实对某一物体的多次检查时,就使用了这些检查。

让我们以以下实例说明默示的断言:


// test suite
describe( Tutorialspoint , function () {
   it( Scenario 1 , function (){
      // test step to launch a URL
      cy.visit("https://www.tutorialspoint.com/videotutorials/index.php")
		// assertion to vapdate count of sub-elements and class attribute value
		cy.get( .toc chapters ).find( p ).should( have.length ,5)
		.and( have.class ,  dropdown )
   });
});

产出如下:

Imppcit Assertions

产出记录显示,有两种说法,有线索和指挥。

Exppcit Assertions

如果主张直接适用于物体,则称为明确主张。 民众的明确主张包括主张/怀疑。

明确声称的指挥如下:


// test suite
describe( Tutorialspoint , function () {
// it function to identify test
   it( Scenario 1 , function (){
      // test step to launch a URL
      cy.visit("https://accounts.google.com")
		// identify element
      cy.get( h1#headingText ).find( span ).then(function(e){
         const t = e.text()
         // assertion expect
         expect(t).to.contains( Sign )
      })
   })
})

产出如下:

Exppcit Assertions

产出记录显示,直接适用于预期指挥的物体。

Cypress has Default Assertions which are internally handled and do not require to be invoked specifically.

实例很少:

    cy.visit () - Expects the page to show the content with 200 status Code.

    cy.request () - Expects that the small services to be available and sent a response.

    cy.contains () - Expects the web elements with its nature to be available in DOM.

    cy.get () - Expects the web elements to be available in DOM.

    .find () - Expects the web elements to be available in DOM.

    类型()——要求网络要素转向一个有能力的国家。

    .cpck () - Expects the web elements to goable state.

    . . . . . . . . - 现有专题的网络要素财产的前景。

Other Cypress assertions

其他的“旋风”说法如下:

length

它检查了从前线指挥中获取的内容。

例如,


cy.get( #txt-fld ).should( have.length ,5)

value

它检查了网站内容是否具有一定价值。

例如,


cy.get( #txt-fld ).should( have.length ,5)

value

它检查了网站内容是否具有一定价值。

例如,


cy.get(  #txt-fld ).should( have.value ,  Cypress )

class

它检查网站内容是否具有某种类别。

例如,


cy.get( #txt-fld  ).should( have.class ,  txt )

contain

它检查了网站内容是否具有某种文本。

例如,


cy.get( #txt-fld  ).should( contain ,  Cypress )

visible

它检查网站内容是否明显。

例如,


cy.get( #txt-fld  ).should( be.visible )

exist

它检查网站内容是否可在文件目标模型中查阅。

例如,


cy.get( #txt-fld  ).should( not.exist );

css

它检查网络元素是否拥有某种财产。

例如,


cy.get( #txt-fld  ).should( have.css ,  display ,  block );
Advertisements