Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
game-mode feature
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-Manuel committed Apr 25, 2024
1 parent 37a16ee commit c7fb62a
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 60 deletions.
14 changes: 14 additions & 0 deletions webapp/e2e/features/game-mode.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Playing game modes

Scenario: Starts a new classic game
Given A logged user in home view
When I press classic play
Then The game ends after 10 questions
Scenario: Starts a new suddendeath game
Given A logged user in home view
When I press suddendeath game
Then The game ends when time runs out
Scenario: Starts a new againstClock game
Given A logged user in home view
When I press againstClock game
Then The game doesn´t finish after 10 questions
94 changes: 94 additions & 0 deletions webapp/e2e/steps/game-mode.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/game-mode.feature');
const {textVerifyByXpath}=require('../steps_testUtils');

let page;
let browser;

defineFeature(feature, test => {
const username = "testUser_wrmetuemsdadgadb"
const password = "aebttrbss"
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 1 });
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 })
//Creamos nuevo usuario para los tests
await page
.goto("http://localhost:3000/register", {
waitUntil: "networkidle0",
})
.catch(() => {});
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toFill('input[name="confirmPassword"]', password);
await expect(page).toClick('button', { text: 'Registrarme' });
await page.waitForNavigation();
});
beforeEach(async()=>{
await page
.goto("http://localhost:3000/Home", {
waitUntil: "networkidle0",
})
.catch(() => {});
});
afterAll(async ()=>{
browser.close();
});
test('Starts a new classic game', ({given,when,then}) => {
let beforeNewGame;
given('A logged user in home view', async () => {
const xpath = '/html/body/div[1]/div/main/main/div/div[1]/h2';
await textVerifyByXpath(page, xpath,"Home")
});

when('I press classic play', async () => {
await expect(page).toClick('button', { text: 'JUGAR CLÁSICO' });
});
then('The game ends after 10 questions', async () => {
for(let i = 0; i<=10; i++){
await page.waitForTimeout(2000);
await expect(page).toClick('[data-buton="btn"]:first-of-type')
}
await expect(page).toMatchElement("h2",{text:"El juego ha finalizado!"})
});
});
test('Starts a new suddendeath game', ({given,when,then}) => {
given('A logged user in home view', async () => {
const xpath = '/html/body/div[1]/div/main/main/div/div[1]/h2';
await textVerifyByXpath(page, xpath,"Home")
});
when('I press suddendeath game', async () => {
await expect(page).toClick('button', { text: 'JUGAR MUERTE SÚBITA' });
});
then('The game ends when time runs out', async () => {
await page.waitForTimeout(12000);
await expect(page).toMatchElement("h2",{text:"El juego ha finalizado!"})
});
});
test('Starts a new againstClock game',({given,when,then})=>{
let text;
given('A logged user in home view',async()=>{
const xpath = '/html/body/div[1]/div/main/main/div/div[1]/h2';
await textVerifyByXpath(page, xpath,"Home")
});
when('I press againstClock game',async()=>{
//await expect(page).toClick('button', { text: "JUGAR Contrareloj"});
await page
.goto("http://localhost:3000/againstClock", {
waitUntil: "networkidle0",
})
.catch(() => {});
});
then('The game doesn´t finish after 10 questions',async()=> {
for (let i = 0; i < 11; i++) {
await page.waitForTimeout(3000);
await expect(page).toClick('[data-buton="btn"]:first-of-type')
}
await expect(page).not.toMatchElement("h2", {text: "El juego ha finalizado!"})
});
});
});
1 change: 1 addition & 0 deletions webapp/e2e/steps/register-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/register-form.feature');


let page;
let browser;

Expand Down
9 changes: 9 additions & 0 deletions webapp/e2e/steps_testUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
async function textVerifyByXpath(page, xpath, expectedText) {
const element = await page.waitForXPath(xpath, { visible: true });
const text = await page.evaluate(e => e.innerText, element);
expect(text).toBe(expectedText);
}

module.exports = {
textVerifyByXpath
};
60 changes: 0 additions & 60 deletions webapp/package-lock.json

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

0 comments on commit c7fb62a

Please sign in to comment.