From 14dc2f1aaecac0407bc06fafa2355d8b0ee68957 Mon Sep 17 00:00:00 2001 From: Tasneem Natshah Date: Sat, 20 Jul 2024 08:06:59 +0300 Subject: [PATCH] Update assertion that input text contains a specific value to be by its label #153 --- ...est--then--i-should--see-text-in-element.feature | 10 ++++++++++ tests/step-definitions/webship.js | 13 ++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100755 tests/features/test--then--i-should--see-text-in-element.feature diff --git a/tests/features/test--then--i-should--see-text-in-element.feature b/tests/features/test--then--i-should--see-text-in-element.feature new file mode 100755 index 0000000..f6794c5 --- /dev/null +++ b/tests/features/test--then--i-should--see-text-in-element.feature @@ -0,0 +1,10 @@ +Feature: An example to test whether an input text contains a certain text by its label + 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 "Username" element + And I should see "1234" in the "Password" element \ No newline at end of file diff --git a/tests/step-definitions/webship.js b/tests/step-definitions/webship.js index 19fc7da..595e675 100755 --- a/tests/step-definitions/webship.js +++ b/tests/step-definitions/webship.js @@ -483,14 +483,17 @@ Then(/^the response should not contain "([^"]*)?"$/, function (expectedText) { /** - * Assert, that element contains a specific text value - * Example: Then I should see "John Smith" in the "#username" element + * Assert, that input text contains a specific value by its label + * Example: Then I should see "John Smith" in the "Username" element * */ Then(/^(I|we)* should see "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, expectedText, element) { - return this.shouldSee = function (browser) { - browser.assert.textContains(element, expectedText); - }; + const elementField = browser.element.findByText(element); + browser.getAttribute(elementField, 'for', function (eleAttribute) { + return this.shouldSee = function (browser) { + browser.assert.textContains('#' + eleAttribute.value, expectedText); + }; + }); }); /**