diff --git a/tests/features/test--then--i-should--not--see-text-in-element.feature b/tests/features/test--then--i-should--not--see-text-in-element.feature index cf7c16e..f0be31d 100755 --- a/tests/features/test--then--i-should--not--see-text-in-element.feature +++ b/tests/features/test--then--i-should--not--see-text-in-element.feature @@ -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 diff --git a/tests/features/test--then--i-should--see-text-in-element-by-attr.feature b/tests/features/test--then--i-should--see-text-in-element-by-attr.feature new file mode 100755 index 0000000..ba86c21 --- /dev/null +++ b/tests/features/test--then--i-should--see-text-in-element-by-attr.feature @@ -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 \ No newline at end of file diff --git a/tests/step-definitions/webship.js b/tests/step-definitions/webship.js index 595e675..e15616d 100755 --- a/tests/step-definitions/webship.js +++ b/tests/step-definitions/webship.js @@ -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