Skip to content

Commit

Permalink
Add assertion that input text contains a specific value by its attrib…
Browse files Browse the repository at this point in the history
…utes #154
  • Loading branch information
TasneemNatshah committed Jul 21, 2024
1 parent 14dc2f1 commit 13958c7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: An example to test whether an element contains a certain text or not
Given I am on "/test--then--i-should--not--see-text-in-element.html"
When I fill in "Username" with "user1"
And I fill in "Password" with "1234"
Then I should see "user1" in the "#uname" element
Then I should see "user1" in the "Usernam" element
When I fill in "uname" with: by attr
And I fill in "Password" with:
Then I should not see "user1" in the "#uname" element
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: An example to test whether an element contains a certain text or not
As a tester
I want to be able to check an element contains a certain text or not

Scenario: Check an element if it contains a specific text
Given I am on "/test--then--i-should--not--see-text-in-element.html"
When I fill in "Username" with "user1"
And I fill in "Password" with "1234"
Then I should see "user1" in the "uname" element by its "id" attr
And I should see "1234" in the "pwordcss" element by attr
26 changes: 26 additions & 0 deletions tests/step-definitions/webship.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,32 @@ Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element$/, function (pron
});
});

/**
* Assert, that input text contains a specific value by its attributes
* Example: Then I should see "John Smith" in the "uname" element by its "id" attr
* Example: Then I should see "1234" in the "pwordcss" element by attr
*
*/
Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, expectedText, attrValue, itsCase, attr, attrCase) {

const hasASpace = attrValue.indexOf(' ');

var selector = '';
if (!attr && hasASpace == -1){
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
}
else if (!attr && hasASpace > -1){
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
}
else {
selector = '[' + attr + '="' + attrValue + '"]';
}

return this.shouldSee = function (browser) {
browser.assert.textContains(selector, expectedText);
};
});

/**
* Assert, that element contains a specific text value
* Example: Then I should not see "Joe Smith" in the "#username" element
Expand Down

0 comments on commit 13958c7

Please sign in to comment.