Skip to content

Commit

Permalink
test: refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed May 5, 2024
1 parent 1bb31cb commit e8ba1e0
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 78 deletions.
37 changes: 27 additions & 10 deletions webapp/e2e/steps/about.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@ defineFeature(feature, test => {

test("A logged user wants to see the about screen of the webpage", ({given,when,and,then}) => {

let username;
let password;
let username = "test";

given("A logged user in the main menu", async () => {
username = "[email protected]"
password = "password"

await expect(page).toClick("button[data-testid='Login'");
await expect(page).toFill("#user", username);
await expect(page).toFill("#password", password);
await expect(page).toClick("button[data-testid='Login'");
await registerUserFromRootDirectory(username,page)
});

when("The user presses the button for deploying the lateral menu", async () => {
Expand All @@ -57,4 +50,28 @@ defineFeature(feature, test => {
afterAll((done) => {
done();
});
});
});

async function registerUserFromRootDirectory(username, page) {
// Credentials for the new user
let email = username + "@email.com"
let password = username + "psw"

// Registering process
await expect(page).toClick("span[class='chakra-link css-1bicqx'");
await expect(page).toFill("input[id='user'", email);
await expect(page).toFill("input[id='username'", username);
await expect(page).toFill("#password", password);
await expect(page).toFill("input[id='field-:r5:']", password);
await expect(page).toClick("button[data-testid='Sign up'");

// Checking for the process to be correct
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "Bienvenid@ " + username || header === "Welcome " + username;
expect(value).toBeTruthy();

return [email, password];
}
70 changes: 45 additions & 25 deletions webapp/e2e/steps/login_positive.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ let browser;

defineFeature(feature, test => {
let username = "t.regis.pos";
let email = username + "@gmail.com";
let password = username + ".psw";
let email = username + "@email.com";
let password = username + "psw";

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
Expand All @@ -24,31 +24,12 @@ defineFeature(feature, test => {
waitUntil: "networkidle0",
})
.catch(() => {});

// Registering process
await expect(page).toClick("span[class='chakra-link css-1bicqx'");
await expect(page).toFill("input[id='user'", email);
await expect(page).toFill("input[id='username'", username);
await expect(page).toFill("#password", password);
await expect(page).toFill("input[id='field-:r5:']", password);
await expect(page).toClick("button[data-testid='Sign up'");

// Checking for the process to be correct
await new Promise(resolve => setTimeout(resolve, 6000));

// Checking user is in main screen
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "Bienvenid@ " + username || header === "Welcome " + username;
expect(value).toBeTruthy();


// Registering the user before the tests
await registerUserFromRootDirectory(username, page);

// Logging it out
await expect(page).toClick("#lateralMenuButton");
await new Promise(resolve => setTimeout(resolve, 6000));
await expect(page).toClick("button[data-testid='LogOut']");
await logOutUser(page)

}, 120000);

Expand Down Expand Up @@ -103,4 +84,43 @@ defineFeature(feature, test => {
done();
browser.close();
});
});
});

async function registerUserFromRootDirectory(username, page) {
// Credentials for the new user
let email = username + "@email.com"
let password = username + "psw"

// Registering process
await expect(page).toClick("span[class='chakra-link css-1bicqx'");
await expect(page).toFill("input[id='user'", email);
await expect(page).toFill("input[id='username'", username);
await expect(page).toFill("#password", password);
await expect(page).toFill("input[id='field-:r5:']", password);
await expect(page).toClick("button[data-testid='Sign up'");

// Checking for the process to be correct
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "Bienvenid@ " + username || header === "Welcome " + username;
expect(value).toBeTruthy();

return [email, password];
}

async function logOutUser(page) {
// Logging out
await expect(page).toClick("#lateralMenuButton");
await expect(page).toClick("button[data-testid='LogOut']");

// Checking for the log out to be sucessful
await new Promise(resolve => setTimeout(resolve, 5000));
let header = await page.$eval("button[data-testid='Login']", (element) => {
return element.innerHTML
})
let value = header === "Login" || "Iniciar sesión";

expect(value).toBeTruthy();
}
64 changes: 21 additions & 43 deletions webapp/e2e/steps/playing_full_game_positive.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ let TEST_TIMEOUT = 300 * 1000; // 5minutes

defineFeature(feature, test => {
let username = "t.playing.pos"
let email = username + "@gmail.com"
let password = username + ".psw"


beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
Expand All @@ -27,33 +24,13 @@ defineFeature(feature, test => {
waitUntil: "networkidle0",
})
.catch(() => {});

// Registering process
await expect(page).toClick("span[class='chakra-link css-1bicqx'");
await expect(page).toFill("input[id='user'", email);
await expect(page).toFill("input[id='username'", username);
await expect(page).toFill("#password", password);
await expect(page).toFill("input[id='field-:r5:']", password);
await expect(page).toClick("button[data-testid='Sign up'");

// Checking for the process to be correct
await new Promise(resolve => setTimeout(resolve, 6000));

},120000);

test("A logged user wants to play an entire game (Kiwi Quest gamemode)", ({given,when,and,then}) => {

given('A logged user in the main menu', async () => {
await new Promise(resolve => setTimeout(resolve, 6000));

// Checking user is in main screen
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "Bienvenid@ " + username || header === "Welcome " + username;
console.log(header)
expect(value).toBeTruthy();

await registerUserFromRootDirectory(username,page)
});

when('Clicking the button to start a new game (Kiwi Quest gamemode)', async() => {
Expand Down Expand Up @@ -347,25 +324,6 @@ async function waitForPageToLoad(timeout_ms = 5000) {

}

async function loginUserFromRootDirectory(username, email = username + "@gmail.com", password = username + ".ps", page) {

// login process
await expect(page).toClick("button[data-testid='Login'");
await expect(page).toFill("#user", email);
await expect(page).toFill("#password", password);
await expect(page).toClick("button[data-testid='Login'");

// Checking for the process to be correct
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "Bienvenid@ " + username || header === "Welcome " + username;
expect(value).toBeTruthy();

}


async function registerUserFromRootDirectory(username, page) {
// Credentials for the new user
let email = username + "@email.com"
Expand All @@ -390,6 +348,26 @@ async function registerUserFromRootDirectory(username, page) {
return [email, password];
}

async function loginUserFromRootDirectory(username, page) {
// Credentials for the new user
let email = username + "@email.com"
let password = username + "psw"

// login process
await expect(page).toClick("button[data-testid='Login'");
await expect(page).toFill("#user", email);
await expect(page).toFill("#password", password);
await expect(page).toClick("button[data-testid='Login'");

// Checking for the process to be correct
await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load
let header = await page.$eval("h2", (element) => {
return element.innerHTML
})
let value = header === "Bienvenid@ " + username || header === "Welcome " + username;
expect(value).toBeTruthy();

}
async function logOutUser(page) {
// Logging out
await expect(page).toClick("#lateralMenuButton");
Expand Down

0 comments on commit e8ba1e0

Please sign in to comment.