Skip to content

Commit 13958c7

Browse files
Add assertion that input text contains a specific value by its attributes #154
1 parent 14dc2f1 commit 13958c7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

tests/features/test--then--i-should--not--see-text-in-element.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: An example to test whether an element contains a certain text or not
66
Given I am on "/test--then--i-should--not--see-text-in-element.html"
77
When I fill in "Username" with "user1"
88
And I fill in "Password" with "1234"
9-
Then I should see "user1" in the "#uname" element
9+
Then I should see "user1" in the "Usernam" element
1010
When I fill in "uname" with: by attr
1111
And I fill in "Password" with:
1212
Then I should not see "user1" in the "#uname" element
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: An example to test whether an element contains a certain text or not
2+
As a tester
3+
I want to be able to check an element contains a certain text or not
4+
5+
Scenario: Check an element if it contains a specific text
6+
Given I am on "/test--then--i-should--not--see-text-in-element.html"
7+
When I fill in "Username" with "user1"
8+
And I fill in "Password" with "1234"
9+
Then I should see "user1" in the "uname" element by its "id" attr
10+
And I should see "1234" in the "pwordcss" element by attr

tests/step-definitions/webship.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,32 @@ Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element$/, function (pron
496496
});
497497
});
498498

499+
/**
500+
* Assert, that input text contains a specific value by its attributes
501+
* Example: Then I should see "John Smith" in the "uname" element by its "id" attr
502+
* Example: Then I should see "1234" in the "pwordcss" element by attr
503+
*
504+
*/
505+
Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, expectedText, attrValue, itsCase, attr, attrCase) {
506+
507+
const hasASpace = attrValue.indexOf(' ');
508+
509+
var selector = '';
510+
if (!attr && hasASpace == -1){
511+
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
512+
}
513+
else if (!attr && hasASpace > -1){
514+
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
515+
}
516+
else {
517+
selector = '[' + attr + '="' + attrValue + '"]';
518+
}
519+
520+
return this.shouldSee = function (browser) {
521+
browser.assert.textContains(selector, expectedText);
522+
};
523+
});
524+
499525
/**
500526
* Assert, that element contains a specific text value
501527
* Example: Then I should not see "Joe Smith" in the "#username" element

0 commit comments

Comments
 (0)