From 62a8dddd7ff471a7ed4f17ab61098e4a792f7b07 Mon Sep 17 00:00:00 2001 From: Tasneem Natshah Date: Sat, 13 Jul 2024 23:08:53 +0300 Subject: [PATCH] Update the step definition to fill form fields of type input Text with the provided table according to their labels #148 --- tests/features/test--when--i-fill-in.feature | 4 ++-- tests/step-definitions/webship.js | 24 ++++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/features/test--when--i-fill-in.feature b/tests/features/test--when--i-fill-in.feature index 7a8f599..4334b16 100755 --- a/tests/features/test--when--i-fill-in.feature +++ b/tests/features/test--when--i-fill-in.feature @@ -26,7 +26,7 @@ I want to be able to fill input text with value Scenario: Check fill in table of input fields Given I am on "/test--when--i-fill-in.html" When I fill in the following: - | #uname | John Smith | - | #pword | 1234 | + | Username | John Smith | + | Password | 1234 | When I press "Login" by attr Then I should see "You enter Username: John Smith and Password: 1234" diff --git a/tests/step-definitions/webship.js b/tests/step-definitions/webship.js index de2a61c..a2c5303 100755 --- a/tests/step-definitions/webship.js +++ b/tests/step-definitions/webship.js @@ -312,21 +312,25 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attrib }); /** - * Fills in form fields with provided table + * Fills in form input fields type text with provided table by there labels * Example: When I fill in the following: - * | username | webshipco | - * | password | 1234 | - * Example: And I fill in the following" - * | username | webshipco | - * | password | 1234 | - * + * | Username | webshipco | + * | Password | 1234 | */ + When(/^(I|we)* fill in the following:$/, function (pronoundCase, table) { - browser.setValue(table.rawTable[0][0], table.rawTable[0][1]); + var elementField = browser.element.findByText(table.rawTable[0][0]); + browser.getAttribute(elementField, 'for', function (eleAttribute) { + browser.setValue('#' + eleAttribute.value, table.rawTable[0][1]); + }); + table.rows().forEach(row => { - browser.setValue(row[0], row[1]); - // browser.fillTextInput(row[0], row[1]); + + elementField = browser.element.findByText(row[0]); + browser.getAttribute(elementField, 'for', function (eleAttribute2) { + browser.setValue('#' + eleAttribute2.value, row[1]); + }); }); });