forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Feature: Playing classic game with default settings | ||
|
||
Scenario: The user plays a game with default settings | ||
Given A logged user | ||
When I play with configured settings(2 questions 2 answers) | ||
Then 2 questions with 2 answers are asked |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
testMatch: ["**/steps/*.js"], | ||
testTimeout: 30000, | ||
testTimeout: 40000, | ||
setupFilesAfterEnv: ["expect-puppeteer"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const puppeteer = require('puppeteer'); | ||
const { defineFeature, loadFeature }=require('jest-cucumber'); | ||
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions | ||
const feature = loadFeature('./features/playGame.feature'); | ||
|
||
let page; | ||
let browser; | ||
|
||
defineFeature(feature, test => { | ||
|
||
beforeAll(async () => { | ||
browser = process.env.GITHUB_ACTIONS | ||
? await puppeteer.launch() | ||
: await puppeteer.launch({ headless: false, slowMo: 100 }); | ||
page = await browser.newPage(); | ||
//Way of setting up the timeout | ||
setDefaultOptions({ timeout: 10000 }) | ||
|
||
await page | ||
.goto("http://localhost:3000", { | ||
waitUntil: "networkidle0", | ||
}) | ||
.catch(() => {}); | ||
}); | ||
|
||
test('The user plays a game with default settings', ({given,when,then}) => { | ||
|
||
given('A logged user', async () => { | ||
await login(page); | ||
}); | ||
|
||
when('I play with configured settings(2 questions 2 answers)', async () => { | ||
await expect(page).toClick('button', { text: 'Clásico' }) | ||
//await expect(page).toClick('button', {text: "-"}) | ||
for(let i = 0; i < 7; i++){ | ||
const button = await page.$(`#questionsSpinner-`); | ||
button.click(); | ||
//await expect(page).toClick('button', { id: 'questionsSpinner-' }) | ||
} | ||
|
||
const button = await page.$(`#questionsSpinner-`); | ||
await button.click(); | ||
|
||
await expect(page).toClick('button', { text: 'Comenzar Juego' }) | ||
}); | ||
|
||
then('2 questions with 2 answers are asked', async () => { | ||
for(let i = 0; i < 2; i++){//Dos preguntas | ||
await expect(page).toMatchElement("div", { class: "questionStructure" });//Comprobamos que existe el div de la pregunta | ||
|
||
const button = await page.$(`#option-1`);//Comprobamos que existe la segunda opción | ||
expect(button).not.toBeNull(); | ||
|
||
const noButton = await page.$(`#option-2`);//Comprobamos que no existe una tercera opción | ||
expect(noButton).toBeNull(); | ||
button.click();//Respondemos la segunda opción | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 2100)); //Esperar a que se muestre la pregunta | ||
} | ||
|
||
await expect(page).toMatchElement("h2", { text: "Modos de juego:" });//Volvemos al menú*/ | ||
}); | ||
}) | ||
|
||
afterAll(async ()=>{ | ||
browser.close() | ||
}) | ||
|
||
}); | ||
|
||
async function login(page) { | ||
username = "pablo" | ||
password = "pabloasw" | ||
await expect(page).toFill('input[name="username"]', username); | ||
await expect(page).toFill('input[name="password"]', password); | ||
await expect(page).toClick('button', { text: 'Iniciar sesión' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
async function login(page) { | ||
username = "pablo" | ||
password = "pabloasw" | ||
await expect(page).toFill('input[name="username"]', username); | ||
await expect(page).toFill('input[name="password"]', password); | ||
await expect(page).toClick('button', { text: 'Iniciar sesión' }) | ||
} | ||
|
||
export default {login}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,4 +101,8 @@ | |
|
||
#numPreguntas{ | ||
width: 2rem; | ||
} | ||
|
||
#config .border{ | ||
margin-bottom: 10rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters