From e46905ea096d3f49cad23306ceef679dcbd9039f Mon Sep 17 00:00:00 2001 From: Kieran Dhir Date: Mon, 2 Dec 2019 01:14:16 +0000 Subject: [PATCH] Fixing UI test New fetures meant that the UI tests failed Fixed the UI test to pass wiht the new fetures --- core/models/answer.js | 1 - core/models/badge.js | 1 - features/D-addQuestion.feature | 4 +-- features/F-home.feature | 52 +++++++++++++++++----------------- features/G-answer.feature | 36 +++++++++++++++++++++-- steps/todo.steps.js | 32 ++++++++++++--------- 6 files changed, 81 insertions(+), 45 deletions(-) diff --git a/core/models/answer.js b/core/models/answer.js index c412d1a..f93b3c4 100644 --- a/core/models/answer.js +++ b/core/models/answer.js @@ -132,7 +132,6 @@ module.exports = class Answer { } async bronzeAnswers(star) { - console.log(star) const Answers = await this.getAllUserId() const starArray = [] const bronzeAnswersArray = [] diff --git a/core/models/badge.js b/core/models/badge.js index 69858a9..580a04a 100644 --- a/core/models/badge.js +++ b/core/models/badge.js @@ -1,7 +1,6 @@ 'use strict' async function addStars(data, bronzeQuestionArray, silverQuestionArray, goldQuestionArray) { - console.table('addstars Data', data ) data.forEach(entry => { if(bronzeQuestionArray.includes(entry.id)) { entry.bronze = 'true' diff --git a/features/D-addQuestion.feature b/features/D-addQuestion.feature index 96cee80..214dcb7 100644 --- a/features/D-addQuestion.feature +++ b/features/D-addQuestion.feature @@ -20,7 +20,7 @@ Feature: Create a question And the "article" number "0" should be """ Call of Duty - Sam Smith + Sam Smith {current date} """ @@ -61,6 +61,6 @@ Feature: Create a question And the "article" number "3" should be """ Elder Scrolls Online - Sam Smith + Sam Smith {current date} """ \ No newline at end of file diff --git a/features/F-home.feature b/features/F-home.feature index a300de8..38e1e3b 100644 --- a/features/F-home.feature +++ b/features/F-home.feature @@ -2,38 +2,38 @@ Feature: Open Home page The user should be able to view the home page. Scenario: home page - Given The browser is open on the home page + Given The browser is open on the home page Then take a screenshot called "home-page" in "home" And the "title" number "0" should be "Game Hub | Welcome to the GameHub" - And the "h1" number "0" should be "WELCOME TO THE GAMEHUB" - And the "ul" number "0" should be "Home Login Register" + And the "h1" number "0" should be "WELCOME TO THE GAMEHUB" + And the "ul" number "0" should be "Home Login Register" Scenario: home page link - Given The browser is open on the "register" page + Given The browser is open on the "register" page When I click on the "home" field Then take a screenshot called "home-page-another" in "home" And the "title" number "0" should be "Game Hub | Welcome to the GameHub" - And the "h1" number "0" should be "WELCOME TO THE GAMEHUB" - And the "ul" number "0" should be "Home Login Register" + And the "h1" number "0" should be "WELCOME TO THE GAMEHUB" + And the "ul" number "0" should be "Home Login Register" Scenario: home page logo button - Given The browser is open on the "login" page + Given The browser is open on the "login" page When I click on the "logo" field Then take a screenshot called "home-page-button" in "home" And the "title" number "0" should be "Game Hub | Welcome to the GameHub" - And the "h1" number "0" should be "WELCOME TO THE GAMEHUB" - And the "ul" number "0" should be "Home Login Register" + And the "h1" number "0" should be "WELCOME TO THE GAMEHUB" + And the "ul" number "0" should be "Home Login Register" Scenario: search for Elder Scrolls questions - Given The browser is open on the home page - When I enter "Elder Scrolls" in the "searchbar" field - And I click on the "submit" field - Then take a screenshot called "search-elder-scrolls" in "home" - And the "title" number "0" should be "Game Hub | Welcome to the GameHub" + Given The browser is open on the home page + When I enter "Elder Scrolls" in the "searchbar" field + And I click on the "submit" field + Then take a screenshot called "search-elder-scrolls" in "home" + And the "title" number "0" should be "Game Hub | Welcome to the GameHub" And the "h1" number "0" should be "WELCOME TO THE GAMEHUB" And the "ul" number "0" should be "Home Login Register" - And the amount of questions shown should be "2" - And the "article" number "0" should be + And the amount of questions shown should be "2" + And the "article" number "0" should be """ Skyrim Elder Scrolls V Emma Jones @@ -42,21 +42,21 @@ Feature: Open Home page And the "article" number "1" should be """ Elder Scrolls Online - Sam Smith + Sam Smith {current date} """ Scenario: search for Call of Duty questions - Given The browser is open on the home page - When I enter "Call of Duty" in the "searchbar" field - And I click on the "submit" field - Then take a screenshot called "call-of-duty" in "home" - And the "title" number "0" should be "Game Hub | Welcome to the GameHub" + Given The browser is open on the home page + When I enter "Call of Duty" in the "searchbar" field + And I click on the "submit" field + Then take a screenshot called "call-of-duty" in "home" + And the "title" number "0" should be "Game Hub | Welcome to the GameHub" And the "h1" number "0" should be "WELCOME TO THE GAMEHUB" - And the "ul" number "0" should be "Home Login Register" - And the amount of questions shown should be "1" - And the "article" number "0" should be + And the "ul" number "0" should be "Home Login Register" + And the amount of questions shown should be "1" + And the "article" number "0" should be """ Call of Duty - Sam Smith + Sam Smith {current date} """ \ No newline at end of file diff --git a/features/G-answer.feature b/features/G-answer.feature index 841dbea..974fbfc 100644 --- a/features/G-answer.feature +++ b/features/G-answer.feature @@ -38,6 +38,17 @@ Feature: Create an answer {current date} Sam Smith + + Rate this answer + 0 + 1 + 2 + 3 + 4 + 5 + + + Average: 0 """ Scenario: create another answer for question when logged in @@ -56,8 +67,19 @@ Feature: Create an answer Starting area {current date} - + Emma Jones + + Rate this answer + 0 + 1 + 2 + 3 + 4 + 5 + + + Average: 0 """ Scenario: create an answer for question2 when loggin in @@ -78,5 +100,15 @@ Feature: Create an answer {current date} Sam Smith - """ + Rate this answer + 0 + 1 + 2 + 3 + 4 + 5 + + + Average: 0 + """ diff --git a/steps/todo.steps.js b/steps/todo.steps.js index 9fc464d..aaaef99 100644 --- a/steps/todo.steps.js +++ b/steps/todo.steps.js @@ -7,6 +7,7 @@ const Question = require('../core/models/question') let page // this is the page object we use to reference a web page +//setting the page dimensions const width = 800 const height = 900 @@ -22,8 +23,9 @@ Given('The browser is open on the {string} page', async(route) => { }) When('I login as {string} with password {string}', async(username, password) => { + //field represents the id attribute in html await page.waitForSelector('#login') - await page.click('#login') //field represents the id attribute in html + await page.click('#login') await page.waitForSelector('#username') await page.click('#username') await page.keyboard.type(username) @@ -33,8 +35,9 @@ When('I login as {string} with password {string}', async(username, password) => }) When('I register as {string} with username {string} and password {string}', async(fullname,username,password) => { + //field represents the id attribute in html await page.waitForSelector('#register') - await page.click('#register') //field represents the id attribute in html + await page.click('#register') await page.waitForSelector('#name') await page.click('#name') await page.keyboard.type(fullname) @@ -46,8 +49,9 @@ When('I register as {string} with username {string} and password {string}', asyn }) When('I create the question title:{string} body:{string}', async(title,body) => { + //field represents the id attribute in html await page.waitForSelector('#add') - await page.click('#add') //field represents the id attribute in html + await page.click('#add') await page.waitForSelector('#title') await page.click('#title') await page.keyboard.type(title) @@ -57,14 +61,16 @@ When('I create the question title:{string} body:{string}', async(title,body) => }) When('I enter {string} in the {string} field', async(value, field) => { + //field represents the id attribute in html await page.waitForSelector(`#${field}`) - await page.click(`#${field}`) //field represents the id attribute in html + await page.click(`#${field}`) await page.keyboard.type(value) }) When('I enter image {string} in the {string} field', async(filePath, field) => { + //field represents the id attribute in html await page.waitForSelector(`#${field}`) - await page.click(`#${field}`) //field represents the id attribute in html + await page.click(`#${field}`) const input = await page.$('input[type="file"]') await input.uploadFile(filePath) }) @@ -94,30 +100,30 @@ Then('the page should be the home page logged in as {string}', async(username) = const dom = document.querySelector('ul') return dom.innerText }) - assert.equal('Game Hub | Welcome to the GameHub', title) + assert.equal('Game Hub | Welcome to the GameHub', title) //Checks if the html is equal to the parameters assert.equal('WELCOME TO THE GAMEHUB', h1) assert.equal(`Home ${username} Add Logout`, ul) }) -//single argument steps +//single string argument steps Then('the {string} number {string} should be {string}', async(element, num, heading) => { const text = await page.evaluate( (element, num) => { const dom = document.querySelectorAll(element) - const arr = Array.from(dom).map(h1 => h1.innerText) - return arr[num] + const arr = Array.from(dom).map(h1 => h1.innerText) //Appends all elements to an array + return arr[num] // returns the desired element in the array }, element, num) assert.equal(text, heading) }) -//Multiple argument steps +//Multiple string argument steps Then('the {string} number {string} should be', async(element, num, heading) => { const question = await new Question(process.env.DB_NAME) - const date = await question.currentDate(new Date()) + const date = await question.currentDate(new Date())//Get current date const newHeading = heading.replace('{current date}', date) const text = await page.evaluate( (element, num) => { const dom = document.querySelectorAll(element) - const arr = Array.from(dom).map(h1 => h1.innerText) - return arr[num] + const arr = Array.from(dom).map(h1 => h1.innerText) //Appends all elements to an array + return arr[num] // returns the desired element in the array }, element, num) assert.equal(text, newHeading) })