赵佳乐SMILE 发表于 2020-6-23 10:49:48

【佳乐Cypress】Day-3 发帖,下拉框的处理

之前已经学习了输入框和按钮

这次来学习一下下拉框

选择下拉框之后要加个等待时间

下拉框选第几个目前还没有实现

就先偷个懒选择最后一个



// describe 可以理解成一个 suite
describe('My First Test Suite', () => {
   
    // 每个 it 表示一个测试案例
    it('Verify 51Testing page title', () => {
      // 访问网页, 同 selenium 的 driver.get()
      cy.visit('http://bbs.51testing.com/')
      // should 在此是断言
      cy.title().should('eq', '51Testing软件测试论坛 - Powered by Discuz!')
      
      // 通过id找到用户名和密码
      cy.get('#ls_username')
      .type('赵佳乐SMILE').should('have.value', '赵佳乐SMILE')
      cy.get('#ls_password')
      .type('****').should('have.value', '****')      
      
      //找到登录按钮
      cy.get('#lsform > div > div.y.pns > table > tbody > tr:nth-child(2) > td.fastlg_l > button').click()
      
      //等待1秒
      cy.wait(1000)
      //断言结果包含用户名
      cy.visit('http://bbs.51testing.com/forum.php')
      cy.get('#um > p:nth-child(2) > strong > a').should('contain','赵佳乐SMILE')
   
      //找的测试新手上路版块
      cy.visit('http://bbs.51testing.com/forum-42-1.html')
      //点击发帖按钮
      cy.get('#newspecial > img').click()
      //等待1秒
      cy.wait(1000)
      
      //选择下拉框
      cy.get('#typeid_float_ctrl').click()
         //等待1秒
      cy.wait(1000)   
      cy.get('#typeid_float_ctrl_menu > ul').children().should('have.length', 6)   
      cy.get('#typeid_float_ctrl_menu > ul').children().last().click()
      
      //输入标题
      cy.get('#subject')
      .type('cypress自动发帖01').should('have.value', 'cypress自动发帖01')
      // 输入内容
      cy.get('#postmessage')
      .type('cypress自动发帖内容').should('have.value', 'cypress自动发帖内容')
      //点击发帖按钮
      cy.get('#postsubmit > span').click()

      cy.screenshot()
   
    })   
})


断言ul里面的元素个数:.children().should('have.length', 6)
选择最后一个元素:.children().last().click()


原文地址:https://user.qzone.qq.com/305132437/blog/1592880509
页: [1]
查看完整版本: 【佳乐Cypress】Day-3 发帖,下拉框的处理