Skip to content

Commit

Permalink
Merge pull request #4 from jueluddinsf/feature/343857-added-new-test
Browse files Browse the repository at this point in the history
cucumber test cases
  • Loading branch information
PrinceSoni83 authored Mar 11, 2024
2 parents 14561c8 + 527a393 commit 99a9df4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
22 changes: 22 additions & 0 deletions features/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,25 @@ Feature: Login Page
Given I am on the login screen
When I fill the login form with valid credentials
Then I should be able to see the home screen


Scenario: login using invaild credentials
Given I am on the login screen
When I fill the login form with invalid credentials
Then I should see error "Epic sadface: Username and password do not match any user in this service"

Scenario: login using empty credentials
Given I am on the login screen
When I fill the login form with empty credentials
Then I should see error "Epic sadface: Username and password do not match any user in this service"

Scenario: login using vaild user but invaild password credentials
Given I am on the login screen
When I fill the login form with vaild user but invaild password credentials
Then I should see error "Epic sadface: Username and password do not match any user in this service"

Scenario: login using invaild user but vaild password credentials
Given I am on the login screen
When I fill the login form with invaild user but vaild password credentials
Then I should see error "Epic sadface: Username and password do not match any user in this service"

46 changes: 45 additions & 1 deletion page-objects/login-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"username_input": "#user-name",
"password_input": "#password",
"login_button": "#login-button",
"inventory_container": "#inventory_container"
"inventory_container": "#inventory_container",
"error" : "[data-test=\"error\"]"
}

class LoginPage {
Expand All @@ -22,11 +23,54 @@
await page.click(locators.login_button);
}


async submitLoginFormWrongUserCred() {
const element = await page.waitForSelector(locators.username_input);
await page.fill(locators.username_input,'7656787654');
await page.fill(locators.password_input,'76545678876');
await page.click(locators.login_button);
}

async submitLoginFormUsingEmptyCred() {
const element = await page.waitForSelector(locators.username_input);
await page.fill(locators.username_input,'');
await page.fill(locators.password_input,'');
await page.click(locators.login_button);
}

async submitLoginFormUsingVaildUserButWrongPassword() {
const element = await page.waitForSelector(locators.username_input);
await page.fill(locators.username_input,'standard_user');
await page.fill(locators.password_input,'weverve');
await page.click(locators.login_button);
}

async submitLoginFormUsingWrongUserVaildPassword() {
const element = await page.waitForSelector(locators.username_input);
await page.fill(locators.username_input,'frebrerb43');
await page.fill(locators.password_input,'secret_sauce');
await page.click(locators.login_button);
}

async verifyAfterLoginPage() {
await page.waitForSelector(locators.inventory_container);
const visible = await page.isVisible(locators.inventory_container);
return expect(visible).to.equal(true);
}

async verifyErrorMsg(error) {
await page.waitForSelector(locators.error);
const errorMsg = await page.locator(locators.error).innerText();
return expect(errorMsg.includes(error)).to.equal(true, `was looking text : ${error} but did not find it. found text ${errorMsg}`);



}




}


module.exports = { LoginPage };
36 changes: 35 additions & 1 deletion step-definitions/login-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@ When('I fill the login form with valid credentials', async function() {
await loginPage.submitLoginForm();
});

When('I fill the login form with invalid credentials', async function() {
await loginPage.submitLoginFormWrongUserCred();
});

When('I fill the login form with empty credentials', async function() {
await loginPage.submitLoginFormUsingEmptyCred();
});

When('I fill the login form with vaild user but invaild password credentials', async function() {
await loginPage.submitLoginFormUsingVaildUserButWrongPassword();
});

When('I fill the login form with invaild user but vaild password credentials', async function() {
await loginPage.submitLoginFormUsingWrongUserVaildPassword();
});


Then('I should be able to see the home screen', async function() {
await loginPage.verifyAfterLoginPage();
});
});

Then('I should see error {string}', async function(errorMsg) {
await loginPage.verifyErrorMsg(errorMsg);});

Then('I should see error {string}', async function(errorMsg) {
await loginPage.verifyErrorMsg(errorMsg);});

Then('I should see error {string}', async function(errorMsg) {
await loginPage.verifyErrorMsg(errorMsg); });

Then('I should see error {string}', async function(errorMsg) {
await loginPage.verifyErrorMsg(errorMsg); });





0 comments on commit 99a9df4

Please sign in to comment.