Skip to content

Commit

Permalink
Add the get element part using its direct attribute format. #163
Browse files Browse the repository at this point in the history
  • Loading branch information
TasneemNatshah committed Aug 5, 2024
1 parent c76c9d8 commit 38e12b4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: An example to click link by its attribute

Scenario: Check click link by class attribute
Given I am on "/test--when--i-click-link.html"
When I click "#aboutUs" by attr
When I click "#aboutUsid" by attr
And I wait max of 2 seconds
Then I should see "About Us"

Expand Down
16 changes: 8 additions & 8 deletions tests/features/test--when--i-fill-in-by-attr.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ I want to be able to fill input text with value by its attribute
Scenario: Check fill in input field with ready format attribute
Given I am on "/test--when--i-fill-in.html"
When I fill in "#uname" with "John Smith" by attr
And I fill in ".pwordcss" with "1234" by attr
When I press "Login"
Then I should see "You enter Username: John Smith and Password: 1234"

Scenario: Check fill in input field with ID and class attribute
Given I am on "/test--when--i-fill-in.html"
When I fill in "uname" with "John Smith" by attr
And I fill in "pwordcss" with "1234" by its "class" attr
When I press "Login"
Then I should see "You enter Username: John Smith and Password: 1234"
Expand All @@ -22,10 +15,17 @@ I want to be able to fill input text with value by its attribute
And I fill in "Your Password" with "1234" by attr
When I press "Login"
Then I should see "You enter Username: John Smith and Password: 1234"

Scenario: Check fill in value for input field
Given I am on "/test--when--i-fill-in.html"
When I fill in "John Smith" for "#uname" by attr
When I fill in "1234" for "pwordcss" by attr
When I press "Login"
Then I should see "You enter Username: John Smith and Password: 1234"

Scenario: Check fill in input field with empty value
Given I am on "/test--when--i-fill-in.html"
When I fill in "#uname" with: by attribute
And I fill in "Your Password" with: by attr
And I fill in "password" with: by attr
When I press "Login" by attr
Then I should see "You enter Username: and Password:"
2 changes: 1 addition & 1 deletion tests/features/test--when--i-fill-in-table-by-attr.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 |
| #uname | John Smith |
| pwordcss | 1234 |
When I press "Login"
Then I should see "You enter Username: John Smith and Password: 1234"
Expand Down
22 changes: 17 additions & 5 deletions tests/step-definitions/webship.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, valu

/**
* Fill in value for input type text by its attribute
* Example: When I fill in "John Smith" for "#uname" by attr
* Example: When I fill in "John Smith" for "uname" by attr
* Example: And I fill in "1234" for "pwordcss" by "class" attr
* Example: And I fill in "John Smith" for "Your full name" by its "placeholder" attribute
Expand All @@ -304,9 +305,12 @@ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, valu
When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, txtValue, attrValue, itsCase, attr, attrCase) {

const hasASpace = attrValue.indexOf(' ');

var selector = '';
if (!attr && hasASpace == -1){

if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
selector = attrValue;
}
else if (!attr && hasASpace == -1){
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
}
else if (!attr && hasASpace > -1){
Expand Down Expand Up @@ -346,7 +350,7 @@ 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 |
* | #uname | John Smith |
* | pwordcss | 1234 |
* Example: When I fill in the following: by its "placeholder" attribute
Expand All @@ -358,7 +362,11 @@ When(/^(I|we)* fill in the following: by( its)*( "([^"]*)?")* (attribute|attr)$/

var hasASpace = table.rawTable[0][0].indexOf(' ');
var selector = '';
if (!attr && hasASpace == -1){

if((table.rawTable[0][0].startsWith('#') || table.rawTable[0][0].startsWith('.')) && hasASpace == -1){
selector = table.rawTable[0][0];
}
else 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){
Expand All @@ -375,7 +383,11 @@ When(/^(I|we)* fill in the following: by( its)*( "([^"]*)?")* (attribute|attr)$/

hasASpace = row[0].indexOf(' ');
var selector = '';
if (!attr && hasASpace == -1){

if((row[0].startsWith('#') || row[0].startsWith('.')) && hasASpace == -1){
selector = row[0];
}
else if (!attr && hasASpace == -1){

selector = row[0] + ',#' + row[0] + ',.' + row[0] + ',[name=' + row[0] + "]," + '[value="' + row[0] + '"],[placeholder="' + row[0] + '"]';
}
Expand Down

0 comments on commit 38e12b4

Please sign in to comment.