Skip to content

Commit

Permalink
BDD de Home con usuario logeado
Browse files Browse the repository at this point in the history
  • Loading branch information
uo276026 committed Apr 8, 2024
1 parent 5659d78 commit b7a55a0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions webapp/e2e/features/home.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Access the app

Scenario: A registered user enters the app
Given An existing user
When I navigate to the Home page
Then I should be able to interact with the app
57 changes: 57 additions & 0 deletions webapp/e2e/steps/home.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('../features/home.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('A registered user enters the app', ({given,when,then}) => {

let username;
let password;

given('An existing user', async () => {
username = "pablo"
password = "pabloasw"
await expect(page).toClick("button", { text: "INICIA SESIÓN" });
});

when('I navigate to the Home page', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Login' })

await expect(page).toClick('a[href="/"]', { text: 'WIQ 5A' });
await page.waitForNavigation();

});

then('I should be able to interact with the app', async () => {
await expect(page).toMatchElement("button", { text: "JUGAR" });
await expect(page).toMatchElement("button", { text: "ESTADÍSTICAS" });
});
})

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

});

0 comments on commit b7a55a0

Please sign in to comment.