test: add test case for login and register
This commit is contained in:
parent
782d571221
commit
2efb929a0b
|
|
@ -1,5 +1,7 @@
|
||||||
{
|
{
|
||||||
"baseUrl": "http://localhost:3000",
|
"baseUrl": "https://mutoe.github.io/vue3-realworld-example-app",
|
||||||
"experimentalNetworkStubbing": true,
|
"experimentalNetworkStubbing": true,
|
||||||
"chromeWebSecurity": false
|
"chromeWebSecurity": false
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"user": {
|
||||||
|
"id": 122907,
|
||||||
|
"email": "plumrx@qq.com",
|
||||||
|
"createdAt": "2020-11-04T14:43:31.622Z",
|
||||||
|
"updatedAt": "2020-11-04T14:43:31.628Z",
|
||||||
|
"username": "plumrx",
|
||||||
|
"bio": null,
|
||||||
|
"image": null,
|
||||||
|
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTIyOTA3LCJ1c2VybmFtZSI6InBsdW1yeDIiLCJleHAiOjE2MDk2ODUwMTF9.A-gAjGYC9u7_mwjNK61HqeR3jwrFPN-UDvUnMjyJfBo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"loginPass": {
|
||||||
|
"username": "plumrx1",
|
||||||
|
"email": "plumrx1@qq.com",
|
||||||
|
"password": "12345678"
|
||||||
|
},
|
||||||
|
"loginFailed": {
|
||||||
|
"username": "plumrx2",
|
||||||
|
"email": "plumrx2@qq.com",
|
||||||
|
"password": "12345678"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
describe('test for like-follow mode', () => {
|
describe('test for like-follow', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.server()
|
cy.server()
|
||||||
cy.route2('GET', /articles\?tag=butt/, { fixture: 'article_of_tag' }).as('article_of_tag')
|
cy.route2('GET', /articles\?tag=butt/, { fixture: 'article_of_tag' }).as('article_of_tag')
|
||||||
|
|
@ -20,7 +20,7 @@ describe('test for like-follow mode', () => {
|
||||||
.should('contain.text', ' Sign in ')
|
.should('contain.text', ' Sign in ')
|
||||||
})
|
})
|
||||||
|
|
||||||
it.only('no-login:follow author', () => {
|
it('no-login:follow author', () => {
|
||||||
cy.get('.article-preview:first')
|
cy.get('.article-preview:first')
|
||||||
.click()
|
.click()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
describe('test for login', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.server()
|
||||||
|
cy.route2('GET', /articles\?tag=butt/, { fixture: 'article_of_tag' }).as('article_of_tag')
|
||||||
|
cy.route2('GET', /articles\?/, { fixture: 'articles.json' }).as('getArticles')
|
||||||
|
cy.route2('GET', /articles\//, { fixture: 'article.json' }).as('getArticle')
|
||||||
|
cy.route2('GET', /tags/, { fixture: 'tags.json' }).as('getTags')
|
||||||
|
|
||||||
|
cy.visit('/')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('login in home page', () => {
|
||||||
|
// const usrname = 'plumrx1'
|
||||||
|
// const email = 'plumrx1@qq.com'
|
||||||
|
// const password = '12345678'
|
||||||
|
|
||||||
|
cy.fixture('users.json').then(users => {
|
||||||
|
cy.login(users.loginPass)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
describe('test for register', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.server()
|
||||||
|
cy.route2('POST', /users/, { fixture: 'register.json' }).as('register')
|
||||||
|
cy.route2('GET', /articles\?tag=butt/, { fixture: 'article_of_tag' }).as('article_of_tag')
|
||||||
|
cy.route2('GET', /articles\?/, { fixture: 'articles.json' }).as('getArticles')
|
||||||
|
cy.route2('GET', /articles\//, { fixture: 'article.json' }).as('getArticle')
|
||||||
|
cy.route2('GET', /tags/, { fixture: 'tags.json' }).as('getTags')
|
||||||
|
|
||||||
|
cy.visit('/')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ligin in home page', () => {
|
||||||
|
// click logup button in home page
|
||||||
|
const usrname = 'plumrx'
|
||||||
|
const email = 'plumrx@qq.com'
|
||||||
|
const password = '12345678'
|
||||||
|
cy.register(usrname, email, password)
|
||||||
|
|
||||||
|
cy.get('.navbar')
|
||||||
|
.should('contain', usrname)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
describe('test for tag mode', () => {
|
describe('test for tag', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.server()
|
cy.server()
|
||||||
cy.route2('GET', /articles\?tag=butt/, { fixture: 'article_of_tag' }).as('article_of_tag')
|
cy.route2('GET', /articles\?tag=butt/, { fixture: 'article_of_tag' }).as('article_of_tag')
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,39 @@
|
||||||
//
|
//
|
||||||
// -- This will overwrite an existing command --
|
// -- This will overwrite an existing command --
|
||||||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
||||||
|
|
||||||
|
Cypress.Commands.add('login', (user) => {
|
||||||
|
// click sign in button in home page
|
||||||
|
cy.get('li.nav-item a.nav-link')
|
||||||
|
.contains(' Sign in')
|
||||||
|
.click()
|
||||||
|
|
||||||
|
cy.get('[type="email"]')
|
||||||
|
.type(user.email)
|
||||||
|
cy.get('[type="password"]')
|
||||||
|
.type(user.password)
|
||||||
|
cy.get('[type="submit"]')
|
||||||
|
.contains(' Sign in ')
|
||||||
|
.click()
|
||||||
|
|
||||||
|
cy.get('h1.logo-font')
|
||||||
|
.should('contain', ' conduit ')
|
||||||
|
cy.get('li.nav-item:last')
|
||||||
|
.should('contain.text', user.username)
|
||||||
|
})
|
||||||
|
|
||||||
|
Cypress.Commands.add('register', (usrname, email, password) => {
|
||||||
|
// click sign up button in home page
|
||||||
|
cy.get('li.nav-item a.nav-link')
|
||||||
|
.contains(' Sign up')
|
||||||
|
.click()
|
||||||
|
// []属性选择器
|
||||||
|
cy.get('[placeholder="Your Name"]')
|
||||||
|
.type(usrname)
|
||||||
|
cy.get('[placeholder="Email"]')
|
||||||
|
.type(email)
|
||||||
|
cy.get('[placeholder="Password"]')
|
||||||
|
.type(password)
|
||||||
|
cy.get('[type="submit"]')
|
||||||
|
.click()
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue