Cypress学习7-连接器connectors

Posted yoyoketang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cypress学习7-连接器connectors相关的知识,希望对你有一定的参考价值。

前言

关于web页面上的选项,通常我们需要断言选项的个数,遍历每个选项的内容.

.each()

<ul class="connectors-each-ul">
              <li data-cypress-el="true">Lara Williams</li>
              <li data-cypress-el="true">William Grey</li>
              <li data-cypress-el="true">Monica Pharrel</li>
            </ul>

技术图片

cy.get(‘.connectors-each-ul>li‘)
  .each(function($el, index, $list){
    console.log($el, index, $list)
  })

.its()

判断选项里面元素个数

<ul class="connectors-its-ul">
              <li>Chai</li>
              <li>Chai-jQuery</li>
              <li>Chai-Sinon</li>
            </ul>

技术图片

cy.get(‘.connectors-its-ul>li‘)
  // calls the ‘length‘ property returning that value
  .its(‘length‘)
  .should(‘be.gt‘, 2)

.invoke()

隐藏元素判断

<div class="well">
            <div class="connectors-div" style="display: none;">
              This is a div
            </div>
          </div>

定位隐藏元素,对异常隐藏的判断

cy.get(‘.connectors-div‘).should(‘be.hidden‘)
  // call the jquery method ‘show‘ on the ‘div.container‘
  .invoke(‘show‘)
  .should(‘be.visible‘)

.spread()

遍历 arr 依次断言

const arr = [‘foo‘, ‘bar‘, ‘baz‘]

cy.wrap(arr).spread(function(foo, bar, baz){
  expect(foo).to.eq(‘foo‘)
  expect(bar).to.eq(‘bar‘)
  expect(baz).to.eq(‘baz‘)
})

.then()

To invoke a callback function with the current subject, use the .then() command.
技术图片

cy.get(‘.connectors-list>li‘).then(function($lis){
  expect($lis).to.have.length(3)
  expect($lis.eq(0)).to.contain(‘Walk the dog‘)
  expect($lis.eq(1)).to.contain(‘Feed the cat‘)
  expect($lis.eq(2)).to.contain(‘Write javascript‘)
})

If the callback function returns a value, it is yielded to the next callback, just like in a Promise callback.

cy.wrap(1)
  .then((num) => {
    expect(num).to.equal(1)

    return 2
  })
  .then((num) => {
    expect(num).to.equal(2)
  })

But unlike a Promise, if undefined is returned, then the original value passed into the .then(cb) is yielded to the next callback.

cy.wrap(1)
  .then((num) => {
    expect(num).to.equal(1)
    // note that nothing is returned from this callback
  })
  .then((num) => {
    // this callback receives the original unchanged value 1
    expect(num).to.equal(1)
  })

If there are Cypress commands in the .then(cb) callback, then the value yielded by the last command will be passed to the next callback.

cy.wrap(1)
  .then((num) => {
    expect(num).to.equal(1)
    // note how we run a Cypress command
    // the result yielded by this Cypress command
    // will be passed to the second ".then"
    cy.wrap(2)
  })
  .then((num) => {
    // this callback receives the value yielded by "cy.wrap(2)"
    expect(num).to.equal(2)
  })

以上是关于Cypress学习7-连接器connectors的主要内容,如果未能解决你的问题,请参考以下文章

JDK1.7下测试Connector_J连接MySQL8.0

搭建Hadoop2.7.3+Hive2.1.1及MySQL(配置Hive+MySQL+Connector)

python 2.7.11 + windows 10 连接 mysql学习记录

python 2.7.11 + windows 10 连接 mysql学习记录

MySQL数据库原理Python3.7 中连接 MySQL 数据库

Python学习记录-连接mysql