Skip to content

Commit

Permalink
Update the step definition to fill form fields of type input Text wit…
Browse files Browse the repository at this point in the history
…h the provided table according to their labels #148
  • Loading branch information
TasneemNatshah committed Jul 13, 2024
1 parent 62a8ddd commit f444651
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/features/test--when--i-fill-in-table-by-attr.feature
Original file line number Diff line number Diff line change
@@ -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"
48 changes: 48 additions & 0 deletions tests/step-definitions/webship.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f444651

Please sign in to comment.