Skip to content

Commit

Permalink
Add assertion that input text does not contains a specific value by i…
Browse files Browse the repository at this point in the history
…ts attributes #156
  • Loading branch information
TasneemNatshah committed Jul 24, 2024
1 parent d6c6d70 commit b83d734
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
Feature: An example to test whether the input text does not contain a specific value by its label
Feature: An example to test whether the input text does not contain a specific value by its attribute
As a tester
I want to be able to check an input text if does not contain a specific value by its label
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 "Username" element
When I fill in "uname" with: by attr
And I fill in "Password" with:
Then I should not see "user1" in the "Username" element

I want to be able to check an input text does not contain a specific value by its attribute
Scenario: Check an element if it does not contain a specific text
Given I am on "/test--then--i-should--not--see-text-in-element.html"
And I fill in "Username" with "user2"
Then I should not see "user1" in the "Username" element
When I fill in "Username" with "user1"
And I fill in "Password" with "1234"
Then I should see "user1" in the "Username" element
When I fill in "uname" with: by attr
And I fill in "Password" with:
Then I should not see "user1" in the "Username" element
Then I should not see "1234" in the "pword" 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 @@ -537,6 +537,32 @@ Then(/^(I|we)* should not see "([^"]*)?" in the "([^"]*)?" element$/, function (
});
});

/**
* Assert, that input text contains a specific value by its attributes
* Example: Then I should not see "John Smith" in the "uname" element by its "id" attr
* Example: Then I should not see "1234" in the "pwordcss" element by attr
*
*/
Then(/^(I|we)* should not 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.not.textContains(selector, expectedText);
};
});

/**
* Assert, that element exists on current page
* Example: Then I should see a "body" element
Expand Down

0 comments on commit b83d734

Please sign in to comment.