Skip to content

Commit

Permalink
Spec User Register
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 10, 2024
1 parent b01ae51 commit 391227c
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { defineConfig } = require("cypress");
const baseUrl = process.env.BASE_URL || "https://opensource-demo.orangehrmlive.com/web/index.php/auth/"
const apiURL = process.env.API_URL || "https://opensource-demo.orangehrmlive.com/web/index.php/auth/"
const baseUrl = process.env.BASE_URL || "https://opensource-demo.orangehrmlive.com/web/index.php/"
const apiURL = process.env.API_URL || "https://opensource-demo.orangehrmlive.com/web/index.php/api/v2/"
// const dbHost = process.env.DBHOST || "localhost"
// const dbPassword = process.env.DBPASSWORD || "password"

Expand Down
25 changes: 25 additions & 0 deletions cypress/e2e/users.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import { Faker, Randomizer } from '@faker-js/faker';
import loginData from '../fixtures/login.json'
import staticDropdowns from '../support/utils/static-dropdowns';


describe('Login Functionality', () => {
beforeEach(() => {
Cypress.on("uncaught:exception", () => {
return false;
})
cy.login(loginData.user.userName, loginData.user.password)
})


context('User register', () => {
it('Should register an new user sucessfully', () => {
cy.goToPage('admin/viewSystemUsers', 'System Users')
cy.get('button.oxd-button').contains('Add').click()
staticDropdowns.selectDropdownsElement('div.oxd-select-text-input', '0')
staticDropdowns.selectDropdownsElement('div.oxd-select-text-input', '1')
})
})

})
15 changes: 9 additions & 6 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ Cypress.Commands.add("loginSession", (userName, password) => {
})
})

Cypress.Commands.add("login", (userName, password, noWait) => {
//cy.intercept("POST", "/auth/validate").as('postLogin')
Cypress.Commands.add("login", (userName, password) => {
cy.clearCookies();
cy.clearLocalStorage();
cy.visit('/login', { failOnStatusCode: false })
cy.visit('auth/login', { failOnStatusCode: false })
cy.get('input[name="username"]')
.should('be.visible')
.type(userName)
Expand All @@ -27,9 +26,6 @@ Cypress.Commands.add("login", (userName, password, noWait) => {
cy.get('button[type="submit"]')
.contains('Login')
.click()
// if (!noWait) {
// return cy.wait('@postLogin')
// }
})


Expand All @@ -53,3 +49,10 @@ Cypress.Commands.add('getUserToken', () => {
return cy.wrap(userToken)
});
});


Cypress.Commands.add('goToPage', (url , namePage) => {
cy.visit(url, { failOnStatusCode: false })
cy.get('div.oxd-table-filter-header-title')
.should('have.text', namePage)
})
8 changes: 0 additions & 8 deletions cypress/support/pages/login.js

This file was deleted.

23 changes: 23 additions & 0 deletions cypress/support/utils/dynamic-dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class DynamicDropdown {
selectOptionDropdownElements(selector, option) {
cy.intercept('GET', '**/pim/**').as('autocomplete');
cy.get(selector, { timeout: timeout })
.clear({ force: true })
.click()
.wait('@autocomplete')
.get('li[role="option"]', { timeout: timeout }).then(($ele) => {
const elementFound = Array.from($ele).some(($el) => {
if ($el.textContent.includes(option)) {
cy.wrap($el).click();
return true
}
return false
})
if (!elementFound) {
throw new Error(`The text "${option}" was not found in list`)
}
})
}
}

export default new DynamicDropdown()
14 changes: 14 additions & 0 deletions cypress/support/utils/static-dropdowns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class StaticDropdown {

selectDropdownsElement(selector, index) {
if (index) {
cy.get(selector, { timeout: 6000 }).eq(index).click()
} else {
cy.get(selector, { timeout: 6000 }).click()
}

}

}

export default new StaticDropdown()
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"devDependencies": {
"@cypress/code-coverage": "^3.12.19",
"@faker-js/faker": "^8.2.0",
"@faker-js/faker": "^8.4.1",
"cypress": "^13.15.0",
"cypress-postgres-10v-compatibility": "^1.0.0"
},
Expand Down

0 comments on commit 391227c

Please sign in to comment.