Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #152

Merged
merged 2 commits into from
May 7, 2024
Merged

Dev #152

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions webapp/e2e/features/singlePlayer.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Playing a full game in single player mode

Scenario: The user plays a game
Given A registered user
When I login into the game and start a game in single player mode
Then The answers and questions should appear the expected number of rounds
73 changes: 73 additions & 0 deletions webapp/e2e/steps/singlePlayer.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const feature = loadFeature('./features/singlePlayer.feature');


function delay(time) {
return new Promise(function(resolve) {
setTimeout(resolve, time)
});
}

defineFeature(feature, test => {

let page;
let browser;

beforeAll(async () => {

browser = await puppeteer.launch({ headless: false });
page = await browser.newPage();
const timeout = 5000;

page.setDefaultTimeout(timeout);

await page.goto('http://localhost:80/');

});

test('The user plays a game', ({given,when,then}) => {
jest.setTimeout(5 * 60 * 1000);
given('A registered user', async() => {
username = "pabloS"
password = "pabloPassword"
await page.waitForSelector('button')
await page.click("button", {text: "REGISTRARSE"});
await page.type('input[name="username"]', username,{ delay: 100 });
await page.type('input[name="password"]', password,{ delay: 100 });
await page.waitForSelector('button')
await page.click('button', { text: 'REGISTRARSE' })

});
when('I login into the game and start a game in single player mode', async() => {
// Esperar a que aparezca el botón de juego individual y hacer clic en él
await page.waitForSelector('a.game-page-button:nth-child(1)');
await page.click('a.game-page-button:nth-child(1)');

// Esperar a que aparezca el botón "add bot" y hacer clic en él
await page.waitForSelector('.add-bot-button');
await page.click('.add-bot-button');
await delay(6000);
// Esperar a que aparezca el botón "start game" y hacer clic en él
await page.waitForSelector('.start-game-button');
await page.click('.start-game-button');
await delay(1500);
});
then('The answers and questions should appear the expected number of rounds', async() => {
// Selector base para el botón de respuesta
const answerSelector = '.answer-grid > button:nth-child';

// Hacer clic en el botón de respuesta 13 veces utilizando un bucle for
for (let i = 1; i <= 13; i++) {
const fullSelector = `${answerSelector}(${1})`; // Selector completo para cada botón de respuesta
await page.waitForSelector(fullSelector); // Esperar a que aparezca el botón de respuesta actual
await page.click(fullSelector); // Hacer clic en el botón de respuesta actual
console.log('Clicked answer', i); // Imprimir un mensaje en la consola
await delay(5000);
}
});
});
afterAll(async ()=>{
browser.close()
})
});