diff --git a/exercises/03_acceptance/cucumber/features/add_one.feature b/exercises/03_acceptance/cucumber/features/add_one.feature index 81684bf..f48f8e6 100644 --- a/exercises/03_acceptance/cucumber/features/add_one.feature +++ b/exercises/03_acceptance/cucumber/features/add_one.feature @@ -6,4 +6,11 @@ Feature: Adding Items When I add "bread" with the quantity "17" Then that data exists in memory - + Scenario: add item via webpage + Given The browser is open on the home page + When I enter "bread" in the "item" field + When I enter "42" in the "qty" field + When I click on the submit button + Then the heading should be "ToDo List" + Then the list should contain "1" row + Then the item should be "bread" \ No newline at end of file diff --git a/exercises/03_acceptance/cucumber/features/nextFeature.devel b/exercises/03_acceptance/cucumber/features/nextFeature.devel deleted file mode 100644 index 7479c16..0000000 --- a/exercises/03_acceptance/cucumber/features/nextFeature.devel +++ /dev/null @@ -1,10 +0,0 @@ -#When ready copy the code below into add_one.feature and implement it into add_one.steps.js. - - Scenario: add item via webpage - Given The browser is open on the home page - When I enter "bread" in the "item" field - When I enter "42" in the "qty" field - When I click on the submit button - Then the heading should be "ToDo List" - Then the list should contain "1" row - Then the item in row "1" should be "bread" \ No newline at end of file diff --git a/exercises/03_acceptance/cucumber/steps/add_one.steps.js b/exercises/03_acceptance/cucumber/steps/add_one.steps.js index ddcc60f..746bf74 100644 --- a/exercises/03_acceptance/cucumber/steps/add_one.steps.js +++ b/exercises/03_acceptance/cucumber/steps/add_one.steps.js @@ -23,15 +23,8 @@ const todo = require('../modules/todo.js') assert.equal(currentData.qty, 17) }); -/* -STARTING CODE TO HELP WITH "nextFeature.devel" - -Copy the contents of nextFeature.devel into add_one.feature, -then come back to this file and implement the features one by one. - -There is already some setup code, so you only need to focus on the tests. - - +// Scenario: add item via webpage +//Setup Code const puppeteer = require('puppeteer') const PAGE = 'http://localhost:8080' @@ -43,6 +36,11 @@ const delayMS = 5 let page let browser +let rows = -1 //test 6 && +//-1 because we don't count the heading row +let headingToCheck = "" //test 5 +let itemValue = "" //test 7 + async function initialize() { console.log("Launching browser") browser = await puppeteer.launch({ headless: true, slowMo: delayMS, args: ['--disable-gpu', `--no-sandbox`, '--disable-dev-shm-usage'] }) @@ -56,21 +54,47 @@ async function initialize() { } async function addToPage(field, value){ - // add puppeteer code - console.log("In development!") + await page.click("#" + field) //field represents the id attribute in html + await page.keyboard.type(value) } async function pressSubmit(){ - // add puppeteer code - console.log("In development!") + await page.click("#submit") +} + +async function parseHTML(html) +{ + let startOfHeading = 0 + for (let i = 0; i < html.length -4; i++) + { + let nextWord = html.slice(i, i+4) + if (nextWord == "

") + { + startOfHeading = i+4 + } + + if (nextWord == "") + { + rows += 1 //useful for test 6 + itemValue = html.slice(i+8, i+13) //useful for test 7 + } + } } // Scenario: add item via webpage +//Tests Given('The browser is open on the home page', async function () { + //If you get a CONNECTION_REFUSED make sure your website is running in a separate terminal await initialize() }); When('I enter {string} in the {string} field', async function (value, field) { + //make sure you set the "id" field in your html tags you want to add to await addToPage(field, value); }); @@ -78,6 +102,17 @@ async function pressSubmit(){ await pressSubmit() }) + Then('the heading should be {string}', async function (neededHeading) { + let html = await page.content() + await parseHTML(html) //deciphers page content, sets variables + assert.equal(headingToCheck, neededHeading) + }); + + Then('the list should contain {string} row', function (amount) { + assert.equal(rows, amount) //we count rows in parseHTML + }); + + Then('the item should be {string}', function (neededValue) { + assert.equal(itemValue, neededValue) //we find itemValue in parseHTML + }); -}) -*/ \ No newline at end of file diff --git a/exercises/03_acceptance/cucumber/views/home.hbs b/exercises/03_acceptance/cucumber/views/home.hbs index 1a9495f..a10ba3f 100644 --- a/exercises/03_acceptance/cucumber/views/home.hbs +++ b/exercises/03_acceptance/cucumber/views/home.hbs @@ -24,10 +24,10 @@ {{/if}}
Item: - + Qty: - - + +