Skip to content
Permalink
Browse files
Fixing UI test
New fetures meant that the UI tests failed

Fixed the UI test to pass wiht the new fetures
  • Loading branch information
dhirk committed Dec 2, 2019
1 parent 39cbc0c commit e46905ea096d3f49cad23306ceef679dcbd9039f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 45 deletions.
@@ -132,7 +132,6 @@ module.exports = class Answer {
}

async bronzeAnswers(star) {
console.log(star)
const Answers = await this.getAllUserId()
const starArray = []
const bronzeAnswersArray = []
@@ -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'
@@ -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}
"""
@@ -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}
"""
@@ -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
"""
@@ -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)
})

0 comments on commit e46905e

Please sign in to comment.