From f444651f7efa2a2b091e0f89802debadfa7b3abd Mon Sep 17 00:00:00 2001 From: Tasneem Natshah Date: Sun, 14 Jul 2024 00:38:35 +0300 Subject: [PATCH] Update the step definition to fill form fields of type input Text with the provided table according to their labels #148 --- ...est--when--i-fill-in-table-by-attr.feature | 19 ++++++++ tests/step-definitions/webship.js | 48 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 tests/features/test--when--i-fill-in-table-by-attr.feature diff --git a/tests/features/test--when--i-fill-in-table-by-attr.feature b/tests/features/test--when--i-fill-in-table-by-attr.feature new file mode 100755 index 0000000..e038ecb --- /dev/null +++ b/tests/features/test--when--i-fill-in-table-by-attr.feature @@ -0,0 +1,19 @@ +Feature: An example of filling the input text with value by attribute +As a tester +I want to be able to fill input text with value by attribute + + Scenario: Check fill in table of input fields by different attribute + Given I am on "/test--when--i-fill-in.html" + When I fill in the following: by attr + | uname | John Smith | + | pwordcss | 1234 | + When I press "Login" + Then I should see "You enter Username: John Smith and Password: 1234" + + Scenario: Check fill in table of input fields by specific attribute + Given I am on "/test--when--i-fill-in.html" + When I fill in the following: by its "placeholder" attribute + | Your full name | John Smith | + | Your Password | 1234 | + When I press "Login" + Then I should see "You enter Username: John Smith and Password: 1234" \ No newline at end of file diff --git a/tests/step-definitions/webship.js b/tests/step-definitions/webship.js index a2c5303..19fc7da 100755 --- a/tests/step-definitions/webship.js +++ b/tests/step-definitions/webship.js @@ -334,6 +334,54 @@ When(/^(I|we)* fill in the following:$/, function (pronoundCase, table) { }); }); +/** + * Fill in value for input type text by its attributeFill form fields of type input Text with the provided table according to their attributes + * Example: When I fill in the following: by attr + * | uname | John Smith | + * | pwordcss | 1234 | + + * Example: When I fill in the following: by its "placeholder" attribute + * | Your full name | John Smith | + * | Your Password | 1234 | + */ + +When(/^(I|we)* fill in the following: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, itsCase, attr, attrCase, table) { + + var hasASpace = table.rawTable[0][0].indexOf(' '); + var selector = ''; + if (!attr && hasASpace == -1){ + selector = table.rawTable[0][0] + ',#' + table.rawTable[0][0] + ',.' + table.rawTable[0][0] + ',[name=' + table.rawTable[0][0] + "]," + '[value="' + table.rawTable[0][0] + '"],[placeholder="' + table.rawTable[0][0] + '"]'; + } + else if (!attr && hasASpace > -1){ + selector ='[value="' + table.rawTable[0][0] + '"],[placeholder="' + table.rawTable[0][0] + '"]'; + } + else { + selector = '[' + attr + '="' + table.rawTable[0][0] + '"]'; + } + + browser.setValue(selector, table.rawTable[0][1]); + + + table.rows().forEach(row => { + + hasASpace = row[0].indexOf(' '); + var selector = ''; + if (!attr && hasASpace == -1){ + + selector = row[0] + ',#' + row[0] + ',.' + row[0] + ',[name=' + row[0] + "]," + '[value="' + row[0] + '"],[placeholder="' + row[0] + '"]'; + } + else if (!attr && hasASpace > -1){ + selector ='[value="' + row[0] + '"],[placeholder="' + row[0] + '"]'; + } + else { + selector = '[' + attr + '="' + row[0] + '"]'; + } + + browser.setValue(selector, row[1]); + + }); +}); + /** * Selects option in select field * Example: When I select "Mercedes" from "Cars"