Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dynamic-websites/exercises/03_acceptance/cucumber/steps/todo.steps.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
92 lines (75 sloc)
2.71 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const { Given, When, Then } = require('cucumber') | |
const assert = require('assert') | |
// const todo = require('../modules/todo.js') | |
const Page = require('./page.js') | |
/* ===================== STEP DEFINITIONS ==================== */ | |
// Given('I currently have no items', () => { | |
// // Write code here that turns the phrase above into concrete actions | |
// todo.clear() | |
// }) | |
// When('I add {string} with the quantity {string}', (item, qty) => { | |
// // Write code here that turns the phrase above into concrete actions | |
// todo.add(item, qty) | |
// }) | |
// Then('that data exists in memory', () => { | |
// // Write code here that turns the phrase above into concrete actions | |
// const currentData = todo.getAll()[0] | |
// assert.equal(currentData.item, 'bread') | |
// assert.equal(currentData.qty, 17) | |
// }) | |
let page // this is the page object we use to reference a web page | |
Given('The browser is open on the home page', async() => { | |
page = await new Page(800, 600) | |
}) | |
When('I enter {string} in the {string} field', async(value, field) => { | |
await page.click(`#${field}`) //field represents the id attribute in html | |
await page.keyboard.type(value) | |
}) | |
When('I click on the submit button', async() => { | |
await page.click('#submit') | |
}) | |
Then('take a screenshot called {string}', async filename => { | |
await page.screenshot({ path: `screenshots/${filename}.png` }) | |
}) | |
Then('the heading should be {string}', async heading => { | |
const text = await page.evaluate( () => { | |
const dom = document.querySelector('h1') | |
return dom.innerText | |
}) | |
assert.equal(heading, text) | |
}) | |
Then('the list should contain {string} rows', async rowCount => { | |
rowCount = Number(rowCount) | |
const items = await page.evaluate( () => { | |
const dom = document.querySelectorAll('table tr td:first-child') | |
const arr = Array.from(dom) | |
return arr.map(td => td.innerText) | |
}) | |
assert.equal(items.length, rowCount) | |
}) | |
Then('the item should be {string}', async item => { | |
const items = await page.evaluate( () => { | |
const dom = document.querySelectorAll('table tr td:first-child') | |
const arr = Array.from(dom) | |
return arr.map(td => td.innerText) | |
}) | |
assert.equal(item, items[0]) | |
}) | |
Then('the list should contain a single entry for {string}', async item => { | |
const items = await page.evaluate( () => { | |
const dom = document.querySelectorAll('table tr td:first-child') | |
const arr = Array.from(dom).map(td => td.innerText) | |
return arr | |
}) | |
const count = items.reduce( (acc, val) => (val === item ? acc += 1 : acc), 0) | |
assert.equal(count, 1) | |
}) | |
Then('the {string} quantity should be {string}', async(item, qty) => { | |
const items = await page.evaluate( () => { | |
const dom = document.querySelectorAll('table tr') | |
// const arr = Array.from(dom) | |
return dom | |
}) | |
assert.equal(2, 2) | |
}) |