[英]How are tests organised in cypress
We are currently looking at swapping from selenium to cypress for our automated End to End tests as it looks as if it could stop some of the wait headaches caused by selenium. 我们目前正在考虑从硒换成柏树以进行自动化的“端到端”测试,因为这似乎可以阻止硒引起的一些令人头疼的麻烦。
As the login time can take a while we use a [OneTimeSetUp] at the start of a test class in NUnit to to do our initial log in then we run our tests from there. 由于登录时间可能需要一段时间,因此我们在NUnit中的测试类的开头使用[OneTimeSetUp]进行初始登录,然后从此处运行测试。
So my question is how are tests organised in cypress? 所以我的问题是赛普拉斯如何组织测试? and can we run multiple tests on the same instance? 我们可以在同一个实例上运行多个测试吗?
Cypress uses mocha for the structure of the tests. 赛普拉斯使用摩卡咖啡进行测试的结构。
describe() block in mocha groups the tests. 摩卡咖啡中的describe()块将测试分组。
it() block tells that this is a test. it()块表明这是一个测试。
eg 例如
describe('Login Functionality', function() {
it('Check Login with Correct Credentials', function() {
//Your code
})
it('Check Login with Incorrect Username', function() {
//Your code
})
it('Check Login with Incorrect Password', function() {
//Your code
})
})
Everything you need is in the official documentation : https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Hooks 您需要的所有内容都在官方文档中: https : //docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Hooks
Enjoy Cypress! 享受赛普拉斯!
Sample : 样品:
beforeEach(function () {
cy.visit('/users/new')
cy.get('#first').type('Johnny')
cy.get('#last').type('Appleseed')
})
it('displays form validation', function () {
cy.get('#first').clear() // clear out first name
cy.get('form').submit()
cy.get('#errors').should('contain', 'First name is required')
})
it('can submit a valid form', function () {
cy.get('form').submit()
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.