login test and active tainacan plugin

This commit is contained in:
juliannyas 2018-03-07 11:58:57 -03:00
parent a56e677d98
commit 312ef3e2ce
5 changed files with 116 additions and 19 deletions

View File

@ -1,3 +1,4 @@
{
"projectId": "tubzok"
"projectId": "tubzok",
"videoRecording": false
}

View File

@ -0,0 +1,80 @@
context('HTML form submission', function(){
beforeEach(function(){
cy.visit('/login')
})
it('displays errors on login', function(){
cy.get('input[name=log]').type('admin')
cy.get('input[name=pwd]').type('senhaerrada{enter}')
// and still be on the same URL
cy.url().should('include', '/wp-login.php')
})
it('redirects to /dashboard on success', function(){
cy.get('input[name=log]').type('admin')
cy.get('input[name=pwd]').type('admin{enter}')
// we should be redirected to /wp-admin
cy.url().should('include', '/wp-admin')
cy.get('h1').should('contain', 'Dashboard')
})
})
context('HTML form submission with cy.request', function(){
it('can bypass the UI and yet still test log in', function(){
// oftentimes once we have a proper e2e test around logging in
// there is NO more reason to actually use our UI to log in users
// doing so wastes is slow because our entire page has to load,
// all associated resources have to load, we have to fill in the
// form, wait for the form submission and redirection process
//
// with cy.request we can bypass this because it automatically gets
// and sets cookies under the hood. This acts exactly as if the requests
// came from the browser
cy.request({
method: 'POST',
url: '/login', // baseUrl will be prepended to this url
form: true, // indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers
body: {
log: 'admin',
pwd: 'admin'
}
})
// just to prove we have a session
cy.getCookie('cypress-session-cookie').should('null')
})
})
context('Reusable "login" custom command', function(){
// typically we'd put this in cypress/support/commands.js
// but because this custom command is specific to this example
// we'll keep it here
Cypress.Commands.add('loginByForm', (username, password) => {
Cypress.log({
name: 'loginByForm',
message: username + ' | ' + password
})
return cy.request({
method: 'POST',
url: '/login',
form: true,
body: {
log: username,
pwd: password
}
})
// we should be redirected to /wp-admin
cy.url().should('include', '/wp-admin')
cy.get('h1').should('contain', 'Dashboard')
})
it('test loginByForm', function() {
// login before each test
cy.loginByForm('admin', 'admin')
})
})

View File

@ -0,0 +1,15 @@
describe('Plugin active Test', function () {
beforeEach(() => {
cy.loginByForm('admin', 'admin')
})
it('Visit users page', function () {
cy.visit('/wp-admin/users.php')
cy.get('h1').should('contain', 'Users')
})
it('plugin active', function () {
cy.contains('Tainacan').click()
cy.get('h1').should('contain', 'Collections Page')
})
})

View File

@ -10,23 +10,7 @@
//
//
// -- This is a parent command --
Cypress.Commands.add("login", (log, pwd) => {
// cy.request({
// method: 'POST'
// url: baseUrl
// body: {
// email: 'admin@admin.com'
// password 'admin'
// }
// })
// .then((resp) => {
// window.localStorage.setItem('jwt', resp.body.user.token)
// })
cy.visit('/wp-login.php')
cy.get('[id=user_login]').type('admin@admin.com')
cy.get('[id=user_pass]').type('admin{enter}')
cy.hash().should('/wp-admin')
})
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
@ -39,3 +23,20 @@
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add('loginByForm', (username, password) => {
Cypress.log({
name: 'loginByForm',
message: username + ' | ' + password
})
cy.request({
method: 'POST',
url: '/wp-login.php', // baseUrl will be prepended to this url
form: true, // indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers
body: {
log: username,
pwd: password
}
})
})

View File

@ -14,7 +14,7 @@
// ***********************************************************
// Import commands.js using ES2015 syntax:
//import './commands'
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')