話說 Cypress is a next generation front end testing tool built for the modern web. And Cypress can test anything that runs in a browser.Cypress consists of a free, open source, locally installed Test Runner and a Dashboard Service for recording your tests.
吹的挺好哈,那咱也來嘗試玩玩,試試,哈哈!
1、在Windows 7以上的環境中,可以直接下載壓縮包后,解壓使用。
解壓后:
2、Cypress.exe便是該框架的主運行程序,雙擊 打開-->運行:
3、如我已經提前新建好一個 自己的Web UI 測試項目 文件夾,命名為“CypressTestPro”,選擇此文件夾:
4、選擇后,選擇 "get got it" 便可以看到很多示例的寫好的js文件:
5、點擊任意一個,即可運行:
6、可將以上示例js文件刪除,也可以自己按照Cypress的語法,也即示例的js建造自己的第一個前端測試Web UI 自動化程序,如個人新建
里面包含文件
7、切換至Cypress運行界面,便可看到對應變化:
8、雙擊運行此sample_spec.js便完成自己的第一個Web UI 使用Cypress的測試程序:(備注:一定要找對應的前端開發人員,去掉輸入驗證碼的驗證)
9、附帶上 sample_spec.js 的代碼片段為:

1 //describe('My First Test', function() { 2 // it('Does not do much!', function() { 3 // expect(true).to.equal(true) 4 // }) 5 //}) 6 7 describe('Cypress Web UI自動化登錄實踐Test', function () { 8 it('SOAM', function () { 9 cy.visit("http://10.12.2.137:3000"); 10 cy.contains('用戶名') 11 cy.get('.box').within(() => { 12 cy.get('input#username').should('have.attr', 'placeholder', '請輸入賬號或是用戶名') 13 cy.get('input#password').should('have.attr', 'placeholder', '請輸入密碼') 14 cy.get('input#captcha').should('have.attr', 'placeholder', '請輸入驗證碼') 15 }) 16 cy.contains('密碼') 17 cy.contains('驗證碼') 18 cy.contains('移動端APP下載') 19 20 //cy.url().should('include', '/portal/monitor/data') 21 cy.get('input#username') 22 .type('1005') 23 .should('have.value', '1005') 24 cy.get('input#password') 25 .type('1') 26 .should('have.value', '1') 27 28 cy.get('#log').click(); 29 30 }) 31 })
10、小技巧:修改此項目中的cypress.json文件,可以改變針對該測試項目的基礎配置
如原始cypress.json打開為: 【{}】,即內容為空;
將大括號內寫入如下代碼,標識 設置展示的屏幕寬窄為 1920 * 1080像素,若是其它手機屏幕之類,也可對應進行設置,查看效果。

1 { 2 "viewportWidth": 1920, 3 "viewportHeight": 1080 4 }