add tests for login using page object
This commit is contained in:
parent
9aac99cbaf
commit
537ac2b37a
@ -9,7 +9,7 @@ setDefaultTimeout(60000)
|
|||||||
BeforeAll(async function () {
|
BeforeAll(async function () {
|
||||||
global.browser = await chromium.launch({
|
global.browser = await chromium.launch({
|
||||||
headless: false,
|
headless: false,
|
||||||
slowMo: 0,
|
slowMo: 1000,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
25
frontend/tests/acceptance/pageObjects/LoginPage.js
Normal file
25
frontend/tests/acceptance/pageObjects/LoginPage.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
class LoginPage {
|
||||||
|
constructor() {
|
||||||
|
//url
|
||||||
|
this.url = 'http://localhost:8080'
|
||||||
|
this.loginUrl = 'http://localhost:8080/login?redirect=%2Ffiles%2F'
|
||||||
|
this.fileUrl = this.url + '/files/'
|
||||||
|
|
||||||
|
//define selectors
|
||||||
|
this.usernameSelector = '//input[@placeholder="Username"]'
|
||||||
|
this.passwordSelector = '//input[@placeholder="Password"]'
|
||||||
|
this.loginSelector = '//input[@type="submit"]'
|
||||||
|
}
|
||||||
|
|
||||||
|
async goToLoginUrl() {
|
||||||
|
await page.goto(this.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
async login(username, password) {
|
||||||
|
await page.fill(this.usernameSelector, username);
|
||||||
|
await page.fill(this.passwordSelector, password);
|
||||||
|
await page.click(this.loginSelector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = LoginPage
|
||||||
@ -2,27 +2,22 @@ const {Given, When, Then} = require('@cucumber/cucumber')
|
|||||||
// import expect for assertion
|
// import expect for assertion
|
||||||
const { expect } = require("@playwright/test");
|
const { expect } = require("@playwright/test");
|
||||||
|
|
||||||
//launch url
|
//import assert
|
||||||
const url = 'http://localhost:8080'
|
const assert = require("assert")
|
||||||
|
|
||||||
//define selectors
|
//import page
|
||||||
const usernameSelector = '//input[@placeholder="Username"]'
|
const LoginPage = require("../pageObjects/LoginPage.js")
|
||||||
const passwordSelector = '//input[@placeholder="Password"]'
|
const loginPage = new LoginPage;
|
||||||
const loginSelector = '//input[@type="submit"]'
|
|
||||||
const loginUrl = 'http://localhost:8080/login?redirect=%2Ffiles%2F'
|
|
||||||
const fileUrl = 'http://localhost:8080/files/'
|
|
||||||
|
|
||||||
Given('the user has browsed to the login page', async function () {
|
Given('the user has browsed to the login page', async function () {
|
||||||
await page.goto(url);
|
await loginPage.goToLoginUrl();
|
||||||
await expect(page).toHaveURL(loginUrl);
|
await expect(page).toHaveURL(loginPage.loginUrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
When('user logs in with username {string} and password {string}', async function (username, password) {
|
When('user logs in with username {string} and password {string}', async function (username, password) {
|
||||||
await page.fill(usernameSelector, username);
|
await loginPage.login(username,password);
|
||||||
await page.fill(passwordSelector, password);
|
|
||||||
await page.click(loginSelector);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Then('user should redirect to the homepage', async function () {
|
Then('user should redirect to the homepage', async function () {
|
||||||
await expect(page).toHaveURL(fileUrl);
|
await expect(page).toHaveURL(loginPage.fileUrl);
|
||||||
});
|
});
|
||||||
Loading…
Reference in New Issue
Block a user