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

Fixed a test and added two new tests #25

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
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "automationtests",
"version": "1.0.0",
"description": "",
"description": "The framework has already been set up running asynchronously using a page object model(POM) with a parent page object that other page objects inherit from, this is representative of the set up we use in our tests within Student Beans",
"scripts": {
"tests": "wdio ./wdio.conf.js"
},
Expand All @@ -27,8 +27,15 @@
"@wdio/local-runner": "8.11.2",
"@wdio/spec-reporter": "8.11.2",
"chai": "4.3.7",
"chromedriver": "114.0.2",
"chromedriver": "118.0.5993",
"wdio-chromedriver-service": "8.1.1",
"webdriverio": "8.11.2"
},
"dependencies": {
"cucumber": "^6.0.7"
},
"main": "wdio.conf.js",
"directories": {
"test": "test"
}
}
3 changes: 1 addition & 2 deletions test/features/simpleSearch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Scenario: As a user I want to search for a brand on studentbeans.com so that I c
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

Then I should select the 4th "Samsung" search listing
7 changes: 7 additions & 0 deletions test/features/trendingNowOffers.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Trending Now Offers

Scenario: As a user I want to view the 6th discount within the trending now offer list
Given I am on the studentbeans homepage
And I open the trending now page
When I select the 6th discount on the trending now page
Then I should be on the 6th discount page
11 changes: 11 additions & 0 deletions test/features/userLogin.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: User Login

Scenario Outline: As a user I should get a relevant error message if my login details are incorrect
Given I am on the studentbeans homepage
And I go to the login page
When I enter "<email>" and "<password>"
Then I should get an error message displayed
Examples:
|email|password|
|[email protected]|testingStuff|

52 changes: 52 additions & 0 deletions test/pageObjects/loginPageObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const ParentPageObject = require('./parentPageObject')

class LoginPageObject 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 openLoginPage() {
this.acceptCookie();
const loginLink = $("[data-testid='nav-login']");
await loginLink.click();
}

async inputEmail(email) {
const emailField = $("#email");
await emailField.setValue(email);
}

async inputPassword(password) {
const passwordField = $("#password");
await passwordField.setValue(password);
}

async acceptCaptcha() {
await browser.switchToFrame(await $('iframe[title="reCAPTCHA"]'));
const captcha = $(".recaptcha-checkbox-border");
await captcha.click();
}

async clickLoginButton() {
const login = $$("//*[text()='Log in']");
return login;
}

async enterLoginDetails(email, password) {
await this.acceptCaptcha();
await browser.switchToFrame(null);
await this.inputEmail(email);
await this.inputPassword(password);
await this.clickLoginButton[1].click();
}

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

}

module.exports = LoginPageObject
9 changes: 8 additions & 1 deletion test/pageObjects/parentPageObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ const { assert } = require('chai')

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

async acceptCookie(){
const cookieElement = await $('button#onetrust-accept-btn-handler');
if (cookieElement !=null){
cookieElement.click();
}
}
}

module.exports = ParentPageObject
26 changes: 26 additions & 0 deletions test/pageObjects/simpleSearchPageObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ class SimpleSearchPageObject extends ParentPageObject {
async verifyHomePage () {
await this.isElementEqualToExpected($('h2=Recommended For You'), 'Recommended For You')
}

async openSearchBar() {
this.acceptCookie();
const searchBar = $("[data-testid='home-search-bar']");
await searchBar.click();
}

async inputSearchTerm(searchTerm) {
const searchBarInput = $("[data-testid='search-input']");
await searchBarInput.setValue(searchTerm);
}

async selectSearchResult(listingIndex, searchTerm) {
const searchListing = $$("[data-testid='search-result-offer']");
const selectedListing = searchListing[listingIndex - 1];
const logoAlt = await selectedListing.$("[alt='${searchTerm}']");

if(logoAlt != null)
{
selectedListing.click();
return selectedListing;
}else{
throw new console.error('No result found for ${searchTerm} at index ${listingIndex}');
}

}
}

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

class TrendingNowPageObject 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 selectTrendingNowLink() {
this.acceptCookie();//accept cookie if visible
const trendingNowLink = $("[data-testid='nav-category-trending-now']");
await trendingNowLink.click();
}

async selectTendingNowOffer(itemIndex) {
const offerList = $$("[data-testid='offer-image-container'] img");
const selectedOffer = offerList[itemIndex - 1];
const getImageUrl = selectedOffer.getAttribute('src'); //Get the image url

if(selectedOffer != null)
{
selectedOffer.click();
return getImageUrl;
}else{
throw new console.error('No offer found at index ${itemIndex}');
}
}

async getSelectedOffer(){
const selectedOffer = $$("[itemprop='offers'][data-offer-selected='true'] img");
const getImageUrl = selectedOffer[0].getAttribute('src'); //Get the image url
return getImageUrl;
}
}

module.exports = TrendingNowPageObject
16 changes: 15 additions & 1 deletion test/stepDefs/simpleSearchStepDef.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
const { Given } = require('@cucumber/cucumber')
const { Given, When, Then } = require('@cucumber/cucumber')
const SimpleSearchPageObject = require('../pageObjects/simpleSearchPageObject')
const { expect } = require('chai')

const simpleSearchPageObject = new SimpleSearchPageObject()

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

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

When('I enter {string}', async (searchTerm) => {
await simpleSearchPageObject.inputSearchTerm(searchTerm)
})

Then('I should select the {int}th {string} search listing', async (searchIndex, searchTerm) => {
const selectedListing = await simpleSearchPageObject.selectSearchResult(searchIndex, searchTerm);
expect(selectedListing).to.exist;
})
20 changes: 20 additions & 0 deletions test/stepDefs/trendingNowStepDef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { Given, When, Then } = require('@cucumber/cucumber')
const TrendingNowPageObject = require('../pageObjects/trendingNowPageObject')
const { expect } = require('chai')
let trendingImageSelected;

const trendingNowPageObject = new TrendingNowPageObject()

Given('I open the trending now page', async () => {
await trendingNowPageObject.selectTrendingNowLink()
})

When('I select the {int}th discount on the trending now page', async (itemIndex) => {
trendingImageSelected = trendingNowPageObject.selectTendingNowOffer(itemIndex);
})

//To Fix: Compare the content of offer on trending page to the offer object page
Then('I should be on the 6th discount page', async () => {
const selectedTrendingOffer = trendingNowPageObject.getSelectedOffer();
expect(await selectedTrendingOffer).eql(await trendingImageSelected);
})
16 changes: 16 additions & 0 deletions test/stepDefs/userLoginStepDef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { Given, When, Then } = require('@cucumber/cucumber')
const LoginPageObject = require('../pageObjects/loginPageObject')

const loginPageObject = new LoginPageObject()

Given('I go to the login page', async () => {
await loginPageObject.openLoginPage();
})

When('I enter {string} and {string}', async (email, password) => {
await loginPageObject.enterLoginDetails(email, password)
})

Then('I should get an error message displayed', async () => {
await loginPageObject.verifyInvalidPasswordError();
})