Web automated testing - cypress testing framework

1. Introduction to cypress

  • JavaScript-based front-end testing tool
  • Enables fast, easy, reliable testing of anything running in the browser
  • Support review for every step of operation
  • Covers all test types of the test pyramid model [interface testing, integration testing, unit testing]
  • The underlying protocol does not use WebDriver > Cypress official website: https://www.cypress.io/

2. Comparison between cypress and selenium

project Cypress Selenium
Supported languages Javascript Java, Python, Javascript, Ruby, C#等
Support browser Chrome、Electron Various major browsers
main user front-end developer QA
Test framework used Mocha Unlimited
Do you need a browser driver? no need
Test speed quick Slightly slower
Record test videos and snapshots support Supported, but requires writing code
community support slightly weak powerful

3. Cypress environment deployment

  • Install node.js official website address: https://nodejs.org/zh-cn/
  • Install cypress
    • Initialize the project: npm init
    • Configure Taobao mirror: npm config set registry  http://registry.npm.taobao.org/
    • Install cypress: npm install cypress –save-dev
  • Open cypress
    • npx cypress open

4. Basic usage of cypress framework

Basic usage of cypress

  • describe declares a collection of test cases
  • beforeEach test case pre-operation, equivalent to setup
  • it declares a test case
  • cy.get locates elements and uses css to position them
  • type input text
  • click click operation
  • should assert
describe('搜索功能', ()=>{
    beforeEach(()=>{
        // 打开网页
        cy.visit("https://ceshiren.com/")
    })

    it('输入搜索内容,正确返回搜索结果', () => {
        // 点击输入框
        cy.get('#search-button').click()
        // 输入测试开发
        cy.get('#search-term').type('测试开发')
        // 点击enter键
        cy.get('#search-term').type('{enter}')
        // 断言结果
        cy.get('#ember21').should('contain', '测试');
    })
})

Finally, I would like to thank everyone who has read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.
 

Insert image description here

Guess you like

Origin blog.csdn.net/m0_58026506/article/details/133047871