Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment Complete #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions test/features/login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Login

Scenario Outline: Error Messages
Given I am on the studentbeans homepage
And I accept cookies
And I click the Login link
When I enter '<Username>' and '<Password>' in the login form
# Note: Below step fails as manual recaptch validation is required:
Then I see the '<Error>'
Examples:
| Username | Password | Error |
| [email protected] | testingStuff | The password you entered is incorrect. Please try again. |
12 changes: 6 additions & 6 deletions test/features/simpleSearch.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Feature: Simple Search

Scenario: As a user I want to search for a brand on studentbeans.com so that I can see if I can get a discount on that brand
Given I am on the studentbeans homepage
And I open the search bar
When I enter "Samsung"
Then I should select the 4th "Samsung" search listing

Scenario: As a user I want to search for a brand on studentbeans.com so that I can see if I can get a discount on that brand
Given I am on the studentbeans homepage
And I open the search bar
When I enter "Samsung"
# Note: There were only 3 "Samsung" listings returned, so I selected the 3rd listing:
Then I should select the 3rd "Samsung" search listing
7 changes: 7 additions & 0 deletions test/features/trendingNow.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Trending Now

Scenario: As a user I want to open the 6th discount within the Trending Now offers list
Given I am on the studentbeans homepage
And I accept cookies
When I click the 'Trending Now' offers link
Then I open the 6th discount
50 changes: 50 additions & 0 deletions test/pageObjects/loginPageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const ParentPageObject = require('./parentPageObject');

class LoginPageObject extends ParentPageObject {
get loginLink() {
return $('[data-testid="nav-login"]');
}

get emailInput() {
return $('#email');
}

get passwordInput() {
return $('#password');
}

get recaptchaCheckbox() {
return $('.recaptcha-checkbox-border');
}

get loginBtns() {
return $$('button=Log in');
}

async clickCaptcha() {
await browser.switchToFrame(await $('iframe[title="reCAPTCHA"]'));
await this.recaptchaCheckbox.click();
}

async enterLoginDetails(user, pass) {
await browser.switchToFrame(null);
await this.emailInput.setValue(user);
await this.passwordInput.setValue(pass);

await this.loginBtns[1].click(); // Click the 'Login' button - second button (0-based index). This is required cause there are 2 buttons on the page with 'Log in' text
await browser.pause(5000);
}

async clickLoginLink() {
await this.loginLink.click();
}

async verifyInputError() {
await this.isElementEqualToExpected(
$('[data-testid="input-alert"]'),
'The password you entered is incorrect. Please try again.'
);
}
}

module.exports = LoginPageObject;
12 changes: 7 additions & 5 deletions test/pageObjects/parentPageObject.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { assert } = require('chai')
const { assert } = require('chai');

class ParentPageObject {
async isElementEqualToExpected (element, expectedText) {
const rrorMessage = 'Actual does not match expected'
assert(await expect(await element.getText(), errorMessage).to.equal(expectedText))
async isElementEqualToExpected(element, expectedText) {
const errorMessage = 'Actual does not match expected';
assert(
await expect(await element.getText(), errorMessage).to.equal(expectedText)
);
}
}

module.exports = ParentPageObject
module.exports = ParentPageObject;
64 changes: 57 additions & 7 deletions test/pageObjects/simpleSearchPageObject.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,64 @@
const ParentPageObject = require('./parentPageObject')
const ParentPageObject = require('./parentPageObject');

class SimpleSearchPageObject extends ParentPageObject {
async goToHomePage () {
// the below url call is relative to the base url in the wdio.conf.js so the below call will actually just result in going straight to the base url
await browser.url('')
async goToHomePage() {
await browser.url('');
}

async verifyHomePage () {
await this.isElementEqualToExpected($('h2=Recommended For You'), 'Recommended For You')
async verifyHomePage() {
await this.isElementEqualToExpected(
$('h2=Recommended For You'),
'Recommended For You'
);
}

get acceptButton() {
return $('#onetrust-accept-btn-handler');
}

get searchButton() {
return $('[data-testid="nav-search-desktop"]');
}

get searchInput() {
return $('[data-testid="search-input"]');
}

async openSearchBar() {
this.acceptCookies();
this.searchButton.click();
}

async enterTextInSearchBar(txt) {
this.searchInput.setValue(txt);
}

async selectThirdSearchListing(txt) {
await browser.pause(5000);
const elementIndex = 2; // Index 2 corresponds to the 3rd element (0-based index)
const selectedElement = await this.selectElementByTextAndIndex(
'span',
txt,
elementIndex
);

if (selectedElement) {
selectedElement.click();
} else {
console.log(`No 3rd element with the text "${txt}" found.`);
}
}

async selectElementByTextAndIndex(tag, text, index) {
const xpathSelector = `//${tag}[text()="${text}"]`;
const elements = $$(xpathSelector);

return elements[index];
}

async acceptCookies() {
this.acceptButton.click();
}
}

module.exports = SimpleSearchPageObject
module.exports = SimpleSearchPageObject;
24 changes: 24 additions & 0 deletions test/pageObjects/trendingNowPageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const ParentPageObject = require('./parentPageObject');

class TrendingNowPageObject extends ParentPageObject {
get acceptButton() {
return $('#onetrust-accept-btn-handler');
}

clickLinkByText(txt) {
const link = $(`//a[text()="${txt}"]`);
link.click();
}

async acceptCookies() {
this.acceptButton.click();
}

async selectSixthListing() {
await browser.pause(5000);
const elementsWithTestId = $$('[data-testid="offer-tile-title-container"]');
elementsWithTestId[5].click(); // Click the 6th element (0-based index)
}
}

module.exports = TrendingNowPageObject;
17 changes: 17 additions & 0 deletions test/stepDefs/loginStepDef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { Given, When, Then } = require('@cucumber/cucumber');
const LoginPageObject = require('../pageObjects/loginPageObject');

const loginPageObject = new LoginPageObject();

Given('I click the Login link', async () => {
await loginPageObject.clickLoginLink();
});

When('I enter {string} and {string} in the login form', async (user, pass) => {
await loginPageObject.clickCaptcha();
await loginPageObject.enterLoginDetails(user, pass);
});

Then('I see the {string}', async (txt) => {
await loginPageObject.verifyInputError();
});
24 changes: 18 additions & 6 deletions test/stepDefs/simpleSearchStepDef.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
const { Given } = require('@cucumber/cucumber')
const SimpleSearchPageObject = require('../pageObjects/simpleSearchPageObject')
const { Given, When, Then } = require('@cucumber/cucumber');
const SimpleSearchPageObject = require('../pageObjects/simpleSearchPageObject');

const simpleSearchPageObject = new SimpleSearchPageObject()
const simpleSearchPageObject = new SimpleSearchPageObject();

Given('I am on the studentbeans homepage', async () => {
await simpleSearchPageObject.goToHomePage()
await simpleSearchPageObject.verifyHomePage()
})
await simpleSearchPageObject.goToHomePage();
await simpleSearchPageObject.verifyHomePage();
});

Given('I open the search bar', async () => {
await simpleSearchPageObject.openSearchBar();
});

When('I enter {string}', async (txt) => {
await simpleSearchPageObject.enterTextInSearchBar(txt);
});

Then('I should select the 3rd {string} search listing', async (txt) => {
await simpleSearchPageObject.selectThirdSearchListing(txt);
});
16 changes: 16 additions & 0 deletions test/stepDefs/trendingNowStepDef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { Given, When, Then } = require('@cucumber/cucumber');
const TrendingNowPageObject = require('../pageObjects/trendingNowPageObject');

const trendingNowPageObject = new TrendingNowPageObject();

Given('I accept cookies', async () => {
await trendingNowPageObject.acceptCookies();
});

When('I click the {string} offers link', async (txt) => {
await trendingNowPageObject.clickLinkByText(txt);
});

Then('I open the 6th discount', async () => {
await trendingNowPageObject.selectSixthListing();
});