Skip to content

Commit

Permalink
Add assertion that element exists on the current page by its attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
TasneemNatshah committed Jul 25, 2024
1 parent 7e7c310 commit d85e422
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: An example to test seeing for a specific element on current page by its attributes
As a user
I want to make sure that when I'm on a particular page, I should see a specific element by its attributes

Scenario: Check to test seeing for a specific element by its attributes
Given I am on "/test--then--i-should--see-text-in-element.html"
Then I should see a "uname" element by its "id" attr
And I should see a "pwordcss" element by attr
24 changes: 24 additions & 0 deletions tests/step-definitions/webship.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,30 @@ Then(/^(I|we)* should see (a|an) "([^"]*)?" element$/, function (pronoundCase, a
});
});

/**
* Assert, that element exists on the current page by its attribute
* Example: Then I should see a "uname" element by its "id" attr
* Example: Then I should see a "pwordcss" element by attr
*
*/
Then(/^(I|we)* should see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, aAnCase, 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 browser.verify.visible(selector);
});

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

0 comments on commit d85e422

Please sign in to comment.