Skip to content

Commit

Permalink
Refactor sign up and log in util
Browse files Browse the repository at this point in the history
  • Loading branch information
xenosf committed Nov 10, 2024
1 parent a2a0e8a commit d657814
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions test/SignUpLogIn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let { getWebDriver, findButtonContainingText, waitForUrl, click } = require("./u
let { URLS, TEST_USER_1 } = require("./utils/const");
const { By, until } = require("selenium-webdriver");
const { deleteAllUsers } = require("./utils/api");
const { fillLoginForm, fillSignUpForm, signUpAndLogIn, logOut } = require("./utils/utils");
const { fillLoginForm, fillSignUpForm, signUp } = require("./utils/utils");

/**
* SIGN UP LOG IN TEST
Expand Down Expand Up @@ -64,8 +64,7 @@ describe("Sign Up/Log In test", () => {
beforeEach(async () => {
await deleteAllUsers();
// create existing user
await signUpAndLogIn(driver, TEST_USER_1);
await logOut(driver, TEST_USER_1);
await signUp(driver, TEST_USER_1);
});

test("simulate unsuccessful user sign up", async () => {
Expand Down
13 changes: 9 additions & 4 deletions test/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@ const fillLoginForm = async (driver, user) => {
};
module.exports.fillLoginForm = fillLoginForm;

module.exports.signUpAndLogIn = async (driver, user) => {
const signUp = async (driver, user) => {
await driver.get(URLS.signup);
await fillSignUpForm(driver, user);
await waitForUrl(driver, URLS.login);
await fillLoginForm(driver, user);
await driver.wait(until.elementLocated(By.xpath(`//button[contains(text(),'Logout')]`)), 3000);
};
module.exports.signUp = signUp;

module.exports.logIn = async (driver, user) => {
const logIn = async (driver, user) => {
await driver.get(URLS.login);
await fillLoginForm(driver, user);
await driver.wait(until.elementLocated(By.xpath(`//button[contains(text(),'Logout')]`)), 3000);
};
module.exports.logIn = logIn;

module.exports.signUpAndLogIn = async (driver, user) => {
await signUp(driver, user);
await logIn(driver, user);
};

module.exports.logOut = async (driver) => {
await driver.get(URLS.logout);
Expand Down

0 comments on commit d657814

Please sign in to comment.