tainacan/cypress/support/commands.js

87 lines
2.2 KiB
JavaScript
Raw Normal View History

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
2018-03-07 14:58:57 +00:00
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
2018-03-07 14:58:57 +00:00
Cypress.Commands.add('loginByForm', (username, password) => {
Cypress.log({
2018-03-08 20:21:22 +00:00
name: 'loginByRequest',
2018-03-07 14:58:57 +00:00
message: username + ' | ' + password
})
2018-03-08 20:21:22 +00:00
cy.request('/wp-admin')
cy.get('title').should('contain', 'Log In Test — WordPress')
2018-03-07 14:58:57 +00:00
cy.request({
2018-03-07 15:43:16 +00:00
method: 'POST',
2018-03-08 20:21:22 +00:00
url: '/wp-login.php',
2018-03-07 15:43:16 +00:00
form: true,
body: {
log: username,
pwd: password
}
})
2018-03-08 20:21:22 +00:00
cy.get('h1').should('contain', 'Dashboard')
cy.getCookie('cypress-session-cookie').should('exist')
})
Cypress.Commands.add('loginByRequest', () => {
Cypress.log({
name: 'loginByRequest',
message: 'admin' + ' | ' + 'admin'
})
cy.request({
method: 'POST',
url: '/login',
form: true,
body: {
log: 'admin',
pwd: 'admin'
}
})
2018-03-07 15:43:16 +00:00
// we should be redirected to /wp-admin
cy.url().should('include', '/wp-admin')
cy.get('h1').should('contain', 'Dashboard')
2018-03-08 20:21:22 +00:00
cy.getCookie('cypress-session-cookie').should('exist')
2018-03-07 14:58:57 +00:00
})
2018-03-08 20:21:22 +00:00
Cypress.Commands.add('loginByUI', () => {
cy.visit('/wp-admin')
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')
})
2018-03-22 15:23:54 +00:00
Cypress.Commands.add('clearDB', () => {
cy.request('POST', '/wp-json/tainacan/v2/database')
})