[skip-ci] Cypress permormance improvement

This commit is contained in:
Matteo Gheza 2020-09-23 20:38:02 +02:00
parent 07f6de3c96
commit 73507e9627
5 changed files with 85 additions and 48 deletions

View File

@ -2,7 +2,6 @@ describe("Installation", () => {
before(() => {
cy.exec("rm config.old.php", {failOnNonZeroExit: false});
cy.exec("mv config.php config.old.php", {failOnNonZeroExit: false});
cy.exec("touch install/runInstall.php", {failOnNonZeroExit: false});
cy.visit("/");
cy.get(".button").click();
})
@ -104,6 +103,7 @@ describe("Installation", () => {
cy.get(".button").click();
cy.contains("Great job, man!");
cy.exec("touch install/runInstall.php", {failOnNonZeroExit: false});
cy.get(".login").click();
cy.contains("Login");
cy.get(".acceptcookies").should('be.visible');

View File

@ -8,7 +8,7 @@ describe("Availability", () => {
expect(txt).to.contains('Thanks, admin, you have given your availability in case of alert.');
})
cy.get(".fa-check").should('be.visible')
cy.contains("Logs").click()
cy.visit("/log.php")
cy.contains("Attivazione disponibilita'")
cy.visit("/")
})
@ -19,7 +19,7 @@ describe("Availability", () => {
expect(txt).to.contains('Thanks, admin, you have removed your availability in case of alert.');
})
cy.get(".fa-times").should('be.visible')
cy.contains("Logs").click()
cy.visit("/log.php")
cy.contains("Rimozione disponibilita'")
cy.visit("/")
})

View File

@ -7,42 +7,77 @@ describe("User management", () => {
it('Create users', () => {
cy.get('@users')
.then((users) => {
users.forEach(user => {
name = user.name
console.log(user)
cy.wait(1000)
cy.contains("Add user").click()
cy.get("input[name='mail']")
.clear()
.type(user.email)
.should('have.value', user.email)
cy.get("input[name='name']")
.clear()
.type(user.name)
.should('have.value', user.name)
cy.get("input[name='username']")
.clear()
.type(user.username)
.should('have.value', user.username)
cy.get("input[name='password']")
.clear()
.type(user.password)
.should('have.value', user.password)
cy.get("input[name='birthday']")
.clear()
.type(user.birthday)
.should('have.value', user.birthday)
if(user.foreman){
cy.get("input[name='capo']")
.check({force: true})
}
if(user.driver){
cy.get("input[name='autista']")
.check({force: true})
}
cy.contains("Submit").click()
cy.contains(user.name)
})
cy.getApiKey().then((apiKey) => {
var i = 1
users.forEach(user => {
console.log("User '"+user.name+"' number "+i);
if(i == 1){
console.log("Adding user via gui...");
name = user.name
console.log(user)
cy.wait(1000)
cy.contains("Add user").click()
cy.get("input[name='mail']")
.clear()
.type(user.email)
.should('have.value', user.email)
cy.get("input[name='name']")
.clear()
.type(user.name)
.should('have.value', user.name)
cy.get("input[name='username']")
.clear()
.type(user.username)
.should('have.value', user.username)
cy.get("input[name='password']")
.clear()
.type(user.password)
.should('have.value', user.password)
cy.get("input[name='birthday']")
.clear()
.type(user.birthday)
.should('have.value', user.birthday)
if(user.foreman){
cy.get("input[name='capo']")
.check({force: true})
}
if(user.driver){
cy.get("input[name='autista']")
.check({force: true})
}
cy.contains("Submit").click()
cy.contains(user.name)
cy.visit("/log.php")
cy.contains("User created")
cy.contains(user.name)
cy.visit("/")
} else {
console.log("Adding user via api...");
cy.request({ method: 'POST', url: '/api.php/user', form: true,
body: {
apiKey: apiKey,
mail: user.email,
name: user.name,
username: user.username,
password: user.password,
birthday: user.birthday,
capo: user.foreman | 0,
autista: user.driver | 0,
hidden: 0,
disabled: 0
}})
.then((response) => {
console.log(response.body)
expect(response.status).to.eq(200)
expect(response.body).to.have.property('userId')
cy.visit("/log.php")
cy.contains("User created")
cy.contains(user.name)
})
}
i+=1;
})
});
})
});
})

View File

@ -28,6 +28,16 @@ Cypress.Commands.add("login", (username="admin", password="correcthorsebatteryst
cy.get("input[name='login']").click()
})
Cypress.Commands.add("getApiKey", (username="admin", password="correcthorsebatterystaple") => {
cy.request({ method: 'POST', url: '/api.php/login', form: true, body: { username: username, password: password }})
.then((response) => {
expect(response.status).to.eq(200)
expect(response.body).to.have.property('apiKey')
console.log(response.body)
return response.body.apiKey
})
})
//
//
// -- This is a child command --

View File

@ -17,12 +17,4 @@
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')
/*
cy.server({
onAnyRequest: (route, proxy) => {
proxy.xhr.setRequestHeader('CUSTOM-HEADER', 'Header value')
}
})
*/
// require('./commands')