Skip to content

Commit

Permalink
Merge pull request #112 from Arquisoft/e2e_laura
Browse files Browse the repository at this point in the history
e2e tests
  • Loading branch information
uo289267 authored Apr 27, 2024
2 parents 67c897f + a65664b commit 2b42701
Show file tree
Hide file tree
Showing 16 changed files with 422 additions and 82 deletions.
6 changes: 6 additions & 0 deletions webapp/e2e/features/addUser.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Register page functionality

Scenario: Register
Given I register a user
Then I am in /menu

9 changes: 9 additions & 0 deletions webapp/e2e/features/competitiveGame.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Game Configurator and Competitive Game functionality
Scenario: Create Competitive Game should go to /questions
Given I am on the game configurator
When I click on new competitive game
Then I am in /questions
Scenario: Create Customized Game should go to /questions
Given I am on the game configurator
When I click on new customized game
Then I am in /questions
3 changes: 1 addition & 2 deletions webapp/e2e/features/home.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ Feature: Home page functionality
Scenario: Closing the text container
Given I am on the home page
When I click on the toggle button to open and then I click it to close
Then The text container should be visible

Then The text container should be visible
9 changes: 9 additions & 0 deletions webapp/e2e/features/instructions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Instructions page functionality

Scenario: Instructions view is well rendered
Given I am on the instructions page
Then The instructions title is rendered
Then The instructions content is rendered



10 changes: 10 additions & 0 deletions webapp/e2e/features/login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Login page functionality

Scenario: Login
Given I login a user
Then I am in /menu
Scenario: Failed login
Given I am on the login page
When I try to login
Then I am in /login

13 changes: 13 additions & 0 deletions webapp/e2e/features/navBar.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feature: NavBar functionality

Scenario: Displaying navbar elements correctly
Given I am on the home page
Then The navbar elements are visible

Scenario: Changing language
Given I am on the home page
When I click on the language button
Then The language options menu should be visible
Then I choose Spanish
Then The navbar should be in Spanish

44 changes: 44 additions & 0 deletions webapp/e2e/steps/addUser.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature } = require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions;

const feature = loadFeature('./features/addUser.feature');

const { register, login, logout } = require("../utils");

let page;
let browser;

const email = "[email protected]";
const username = "testUserAddUser"
const password = "testUserPassword"

defineFeature(feature, test => {

beforeAll(async () => {
browser = await puppeteer.launch({
headless: "new",
slowMo: 40,
defaultViewport: { width: 1920, height: 1080 },
args: ['--window-size=1920,1080']
});

page = await browser.newPage();
setDefaultOptions({ timeout: 30000 });

}, 60000);


test('Register', ({ given,when, then }) => {
given('I register a user', async () => {
await register(page, email, username, password);
});

then('I am in /menu', async () => {
await expect(page).toMatchElement('.divMenu');
});
}, 60000);



});
63 changes: 63 additions & 0 deletions webapp/e2e/steps/competitiveGame.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature } = require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions;

const feature = loadFeature('./features/competitiveGame.feature');

const { register, login, logout } = require("../utils");

let page;
let browser;

const email = "[email protected]";
const username = "testUserCompetitiveGame"
const password = "testUserPassword"

defineFeature(feature, test => {

beforeAll(async () => {
browser = await puppeteer.launch({
headless: "new",
slowMo: 40,
defaultViewport: { width: 1920, height: 1080 },
args: ['--window-size=1920,1080']
});

page = await browser.newPage();
setDefaultOptions({ timeout: 30000 });

await register(page, email, username, password);
});

beforeEach(async () => {
await logout(page);
await login(page, username, password);
})

test('Create Competitive Game should go to /questions', ({ given,when, then }) => {
given('I am on the game configurator', async () => {
await page.goto('http://localhost:3000/configurator');
await page.waitForSelector('.GameConfiguratorDiv');
});
when('I click on new competitive game', async () => {
await page.click('#competitive');
});
then('I am in /questions', async () => {
await expect(page).toMatchElement('.questionContainer');
});
});

test('Create Customized Game should go to /questions', ({ given,when, then }) => {
given('I am on the game configurator', async () => {
await page.goto('http://localhost:3000/configurator');
await page.waitForSelector('.GameConfiguratorDiv');
});
when('I click on new customized game', async () => {
await page.click('.linkButton');
});
then('I am in /questions', async () => {
await expect(page).toMatchElement('.questionContainer');
});
});

});
49 changes: 24 additions & 25 deletions webapp/e2e/steps/home.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ defineFeature(feature, test => {
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });
});

test('The text container is initially visible', ({ given, then }) => {
given('I am on the home page', async () => {
await page.goto('http://localhost:3000/home');
await page.waitForSelector('.general');
});

test('The text container is initially visible', ({ given, then }) => {
given('I am on the home page', async () => {
await page.goto('http://localhost:3000/home');
await page.waitForSelector('.general');
});

then('The text container should be visible', async () => {
await expect(page).toMatchElement('.text-container.visible');
});
});
then('The text container should be visible', async () => {
await expect(page).toMatchElement('.text-container.visible');
});
});

test('Opening the text container', ({ given, when, then }) => {
given('I am on the home page', async () => {
Expand All @@ -47,26 +47,25 @@ defineFeature(feature, test => {
});
});

test('Closing the text container', ({ given, when, then }) => {
given('I am on the home page', async () => {
await page.goto('http://localhost:3000/home');
await page.waitForSelector('.general');
});

when('I click on the toggle button to open and then I click it to close', async () => {
test('Closing the text container', ({ given, when, then }) => {
given('I am on the home page', async () => {
await page.goto('http://localhost:3000/home');
await page.waitForSelector('.general');
});
when('I click on the toggle button to open and then I click it to close', async () => {

await page.click('label[for="toggleOpen"]');
await page.click('label[for="toggleOpen"]');

// Wait for label to be render, visible : true
await page.waitForSelector(`label[for="toggleClose"]`, {visible: true});
await page.click('label[for="toggleClose"]');
await page.waitForSelector(`label[for="toggleClose"]`, {visible: true});
await page.click('label[for="toggleClose"]');

});
});

then('The text container should be visible', async () => {
await expect(page).toMatchElement('.text-container.visible');
});
});
then('The text container should be visible', async () => {
await expect(page).toMatchElement('.text-container.visible');
});
});

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

const feature = loadFeature('./features/instructions.feature');

let page;
let browser;

defineFeature(feature, test => {

beforeAll(async () => {
browser = await puppeteer.launch({
headless: "new",
slowMo: 20,
defaultViewport: { width: 1920, height: 1080 },
args: ['--window-size=1920,1080']
});

page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });
});

test('Instructions view is well rendered', ({ given, then }) => {
given('I am on the instructions page', async () => {
await page.goto('http://localhost:3000/instructions');
await page.waitForSelector('.instructions_title');
});

then('The instructions title is rendered', async () => {
await expect(page).toMatchElement('.instructions_title');
});

then('The instructions content is rendered', async () => {
await expect(page).toMatchElement('.ins_ul');
});
});

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

const feature = loadFeature('./features/login.feature');

const { register, login, logout } = require("../utils");

let page;
let browser;

const email = "[email protected]";
const username = "testUserLogin"
const password = "testUserPassword"

defineFeature(feature, test => {

beforeAll(async () => {
browser = await puppeteer.launch({
headless: "new",
slowMo: 20,
defaultViewport: { width: 1920, height: 1080 },
args: ['--window-size=1920,1080']
});

page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });
await register(page, email, username, password);
await logout(page);
},60000);


test('Login', ({ given, then }) => {
given('I login a user', async () => {
await login(page, username, password);

});
then('I am in /menu', async () => {
await expect(page).toMatchElement('.divMenu');
await logout(page);
});
}, 60000);

test('Failed login', ({ given,when, then }) => {
given('I am on the login page', async () => {
await page.goto('http://localhost:3000/login');
});
when('I try to login', async () => {
await page.goto('http://localhost:3000/login');
await page.waitForSelector('.general');

await page.type('input[type="text"]', 'lau');
await page.type('input[type="password"]', '123');
await page.click('button[type="submit"]');
});
then('I am in /login', async () => {
await expect(page).toMatchElement('.title-login');
}, 60000);
});



});
Loading

0 comments on commit 2b42701

Please sign in to comment.