From 7b7d3fd5d30c7fb2a749757513b3468d2b8c8415 Mon Sep 17 00:00:00 2001 From: lauratbg Date: Fri, 26 Apr 2024 16:01:20 +0200 Subject: [PATCH] AddUser added --- webapp/e2e/features/addUser.feature | 7 ++++ webapp/e2e/features/login.feature | 8 +++-- webapp/e2e/steps/addUser.steps.js | 51 +++++++++++++++++++++++++++++ webapp/e2e/steps/login.steps.js | 13 ++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 webapp/e2e/features/addUser.feature create mode 100644 webapp/e2e/steps/addUser.steps.js diff --git a/webapp/e2e/features/addUser.feature b/webapp/e2e/features/addUser.feature new file mode 100644 index 0000000..9c6d6e8 --- /dev/null +++ b/webapp/e2e/features/addUser.feature @@ -0,0 +1,7 @@ +Feature: Login page functionality + + Scenario: Register + Given I am on the add user page + When I register a user + Then I am in /menu + diff --git a/webapp/e2e/features/login.feature b/webapp/e2e/features/login.feature index c81a54d..8194d17 100644 --- a/webapp/e2e/features/login.feature +++ b/webapp/e2e/features/login.feature @@ -2,5 +2,9 @@ Feature: Login page functionality Scenario: Login Given I am on the login page - I login as user - I am in /menu + When I login as 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 diff --git a/webapp/e2e/steps/addUser.steps.js b/webapp/e2e/steps/addUser.steps.js new file mode 100644 index 0000000..1df161f --- /dev/null +++ b/webapp/e2e/steps/addUser.steps.js @@ -0,0 +1,51 @@ +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 = "testUser1@example.com"; +const username = "testUser1" +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 }); + + }); + + beforeEach(async () => { + await logout(page); + await login(page, username, password); + }) + + test('Register', ({ given,when, then }) => { + given('I am on the add user page', async () => { + await page.goto('http://localhost:3000/addUser'); + await page.waitForSelector('.general'); + }); + when('I register a user', async () => { + await register(page, email, username, password); + }); + then('I am in /menu', async () => { + await expect(page).toMatchElement('.divMenu'); + }); + }); + + + +}); \ No newline at end of file diff --git a/webapp/e2e/steps/login.steps.js b/webapp/e2e/steps/login.steps.js index 3b2b036..9e3b4da 100644 --- a/webapp/e2e/steps/login.steps.js +++ b/webapp/e2e/steps/login.steps.js @@ -46,6 +46,19 @@ defineFeature(feature, test => { await expect(page).toMatchElement('.divMenu'); }); }); + + test('Failed login', ({ given,when, then }) => { + given('I am on the login page', async () => { + await page.goto('http://localhost:3000/login'); + await page.waitForSelector('.general'); + }); + when('I try to login', async () => { + await login(page, email, "lau", "123"); + }); + then('I am in /login', async () => { + await expect(page).toMatchElement('.general'); + }); + });