Skip to content

Commit

Permalink
user progule e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
uo287841 committed Apr 27, 2024
1 parent 40616ea commit e85433a
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 1 deletion.
12 changes: 11 additions & 1 deletion webapp/e2e/features/login-form.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@ Feature: Login a registered user
Scenario: The user is registered in the site
Given An registered user
When I fill the data in the form to log in
Then is taken to the home page
Then is taken to the home page

Scenario: User logs in with invalid credentials
Given a registered user with username "testUser" and password "testpass"
When I fill the login form with username "testUser" and incorrect password "wrongpass"
And I remain on the login page

Scenario: User attempts to login without entering credentials
Given a registered user with username "testUser" and password "testpass"
When I attempt to log in without entering any credentials
And I remain on the login page
17 changes: 17 additions & 0 deletions webapp/e2e/features/userprofile-form.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: View and Change User Quiz Rankings

Scenario: Viewing Global Rankings
Given the user navigates to their profile
When they select the "Global" category
Then they see their performance statistics for global quizzes

Scenario: Switching Category to Flags
Given the user is on their profile page
When they click on the "Flags" category
Then they view their performance metrics for flag-related quizzes

Scenario: Switching Category to Food
Given the user is on their profile page
When they click on the "Food" category
Then they view their performance metrics for food-related quizzes

35 changes: 35 additions & 0 deletions webapp/e2e/steps/login-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,45 @@ defineFeature(feature, test => {
then('is taken to the home page', async () => {
await page.waitForNavigation({ waitUntil: "networkidle0" });
await expect(page).toMatchElement("h1", { text: "Welcome back, " + username + "!" });
await expect(page).toClick("button", { text: "Log out" });
});

});

test('User logs in with invalid credentials', ({ given, when, then }) => {
given('a registered user with username "testUser" and password "testpass"', async () => {
// No specific action needed since the user is already registered
});

when('I fill the login form with username "testUser" and incorrect password "wrongpass"', async () => {
await expect(page).toFill('input[name="username"]', 'testUser');
await expect(page).toFill('input[name="password"]', 'wrongpass');
await expect(page).toClick("button", { text: "Log In" });
});


then('I remain on the login page', async () => {
await expect(page).toMatchElement("h1", { text: "Access WIQ" });
});
});

test('User attempts to login without entering credentials', ({ given, when, then }) => {
given('a registered user with username "testUser" and password "testpass"', async () => {
// No specific action needed since the user is already registered
});

when('I attempt to log in without entering any credentials', async () => {
await expect(page).toFill('input[name="username"]', '');
await expect(page).toFill('input[name="password"]', '');
await expect(page).toClick("button", { text: "Log In" });
});


then('I remain on the login page', async () => {
await expect(page).toMatchElement("h1", { text: "Access WIQ" });
});
});

afterAll(async ()=>{
browser.close()
})
Expand Down
107 changes: 107 additions & 0 deletions webapp/e2e/steps/userprofile-form.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/userprofile-form.feature');


let page;
let browser;

defineFeature(feature, test => {

beforeAll(async () => {

browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 20 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })

await page
.goto("http://localhost:3000/login", {
waitUntil: "networkidle0",
})
.catch(() => {});
});

test('Viewing Global Rankings', ({given,when,then}) => {

let username;
let password;

given('the user navigates to their profile', async () => {
username = "testUser"
password = "testpass";
await expect(page).toClick("a", { text: "Log In" });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick("button", { text: "Log In" });
await expect(page).toClick("button", { text: "My stats" });
});

when('they select the "Global" category', async () => {

await expect(page).toMatchElement("h2", { text: "Username: " + username });
await expect(page).toClick("button", { text: "Flags" });
await expect(page).toClick("button", { text: "Global" });
});

then('they see their performance statistics for global quizzes', async () => {
await expect(page).toMatchElement('.ranking h3', { text: "global Ranking" });
await expect(page).toMatchElement(".ranking p:nth-child(1)", { text: "Total Answered Questions: " + 1 });
});

});

test('Switching Category to Flags', ({given,when,then}) => {

let username;
let password;

given('the user is on their profile page', async () => {
username = "testUser"
password = "testpass";
await expect(page).toMatchElement("h2", { text: "Username: " + username });
});

when('they click on the "Flags" category', async () => {

await expect(page).toClick("button", { text: "Flags" });
});

then('they view their performance metrics for flag-related quizzes', async () => {
await expect(page).toMatchElement('.ranking h3', { text: "flags Ranking" });
await expect(page).toMatchElement(".ranking p:nth-child(1)", { text: "Total Answered Questions: " + 1 });
});

});

test('Switching Category to Food', ({given,when,then}) => {

let username;
let password;

given('the user is on their profile page', async () => {
username = "testUser"
password = "testpass";
await expect(page).toMatchElement("h2", { text: "Username: " + username });
});

when('they click on the "Food" category', async () => {

await expect(page).toClick("button", { text: "Food" });
});

then('they view their performance metrics for food-related quizzes', async () => {
await expect(page).toMatchElement('.ranking h3', { text: "foods Ranking" });
await expect(page).toMatchElement(".ranking p:nth-child(1)", { text: "Total Answered Questions: " + 0 });
});

});

afterAll(async ()=>{
browser.close()
})

});
7 changes: 7 additions & 0 deletions webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ async function startServer() {
email: email,
password: password
});

const pints = await axios.post('http://localhost:8001/addpoints', {
username: username,
category: "flags",
correct: "true"
});

} catch (error) {
console.error('Error adding user:', error.response.data);
}
Expand Down

0 comments on commit e85433a

Please sign in to comment.