[Cypress] Get started with Cypress

Adding Cypress to a project is a simple npm install away. We won’t need any global dependencies beyond node and npm to get started with Cypress. In this lesson we’ll look at our existing application, add Cypress as a dev dependency with npm and fire it up for the first time to have a look around.

 

Github

 

Install:

npm i -D cypress

 

Open cypress:

node_modules/.bin/cpress open

 

In order to test our application, Cypress will need to visit it in the browser. In this lesson we’ll see how we can visit our application with Cypress and how to configure a baseUrl for Cypress to make that even easier.

Open cypress.json:

{
  "baseUrl": "http://localhost:3030"  
}

This tells the root url for the application.

 

Create a new spec file in cypress/integration/form-input.spec.js:

describe('Form input', () => {
  it('should visit the app', () => {  
       cy.visit('/') ; // Visit he root page which has been config in the cypress.json baseUrl
  })
})

 

Create a npm script for running cypress:

"cypress": "cypress open"

 

The Cypress UI is a great way to work through individual tests and while TDD-ing new features, but it isn’t ideal for running large test suites or for running on a CI server. In this lesson, we’ll add an npm script to run all of our tests without the UI and look at the results of a full test run.

"cypress:all": "cypress run"

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值