Skip to content

Commit

Permalink
Add a step definition when I press value by the attribute name #140
Browse files Browse the repository at this point in the history
  • Loading branch information
TasneemNatshah committed Jul 7, 2024
1 parent 12a3155 commit 0aee378
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
7 changes: 5 additions & 2 deletions examples/test--when--i-press-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
<body>
<h1>Press Button</h1>
<div id="result" class="style"></div><br/>
<label for="btnClickid">Press button</label>
<input id="btnClickid" class="btnClickclass" name="btnClickname" type="button" value="Submit" onclick="onClick()">
<label for="btn-pressID">Press button</label>
<button id="btn-pressID" class="btn-pressclass" name="btn-pressname" onclick="onClick()">Button</button>

<input type="submit" id="submit-pressID" class="submit-pressclass" name="submit-pressname" value="Submit" onclick="onClick()" />

</body>
</html>
2 changes: 1 addition & 1 deletion nightwatch.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {

test_settings: {
default: {
launch_url: 'http://localhost/products/webship-js/examples',
launch_url: 'http://localhost:8080',
selenium_port: 4444,
selenium_host: '127.0.0.1',
silent: true,
Expand Down
15 changes: 15 additions & 0 deletions tests/features/test--when--i-press-button-by-attribute.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: An example to press a button

As a tester
I want to be able to press a button

Scenario: Verify clicking a button using its ID attribute.
Given I am on "/test--when--i-press-button.html"
When I press "btn-pressID" by "id" attr
Then I should see "Button Pressed Successfully"

Scenario: Verify that you can click a button using its default name attribute.
Given I am on "/test--when--i-press-button.html"
When I press "btn-pressname" by attr
Then I should see "Button Pressed Successfully"

24 changes: 23 additions & 1 deletion tests/step-definitions/webship.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,29 @@ When(/^(I|we)* move backward one page$/, function (pronoundCase) {
*
*/
When(/^(I|we)* press "([^"]*)?"$/, function (pronoundCase, element) {
browser.click('[value="' + element + '"]');
browser.element.findByText(element).click();
});

/**
* Presses button with specified element
* Example: When I press "btn-pressID" by attr
* Example: When I press "btn-pressID" by attribute
* Example: And I press "Your full name" by "placeholder" attribute
* Example: And I press "Your full name" by its "placeholder" attribute
* Example: And I press "save-name" by "data-drupal-selector" attr
*
*/
When(/^(I|we)* press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, attrValue, itsCase, attr, attrCase) {

var selector = '';
if (!attr){
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "],[value=" + attrValue + "]";
}
else {
selector = '[' + attr + '="' + attrValue + '"]';
}

browser.click(selector);
});

/**
Expand Down

0 comments on commit 0aee378

Please sign in to comment.