Skip to content
Merged
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
3 changes: 3 additions & 0 deletions fixtures/userData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports={
validUser: { username: 'standard_user', password: 'secret_sauce'}
}
20 changes: 20 additions & 0 deletions pageObjects/LoginPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class LoginPage{
constructor (page){
this.page = page;
this.usernameInput = 'input[name="user-name"]';
this.passwordInput = 'input[name="password"]';
this.submitButton = '[data-test="login-button"]';
}

async goto(){
await this.page.goto('https://www.saucedemo.com/');
}

async login(username,password){
await this.page.fill(this.usernameInput,username);
await this.page.fill(this.passwordInput,password);
await this.page.click(this.submitButton);
}
}

module.exports ={ LoginPage};
11 changes: 11 additions & 0 deletions tests/login.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

const { test, expect } = require('@playwright/test');
const { LoginPage } = require('../pageObjects/LoginPage');
const { validUser } = require('../fixtures/userData');

test('Valid user should log in successfully', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login(validUser.username, validUser.password);
await expect(page).toHaveURL(/inventory/);
});