Skip to content

Commit

Permalink
Add a step definition of selecting the option in the dropdown list fi…
Browse files Browse the repository at this point in the history
…eld by its attributes #165
  • Loading branch information
TasneemNatshah committed Aug 13, 2024
1 parent a125a0f commit 1d5c6b8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: An example to select option from dropdown list by its attributes

As a tester
I want to be able to test select option from dropdown list by its attributes

Scenario: Check of selecting option from dropdown list by its attributes
Given I am on "/test--when--i-select-option-from-dropdownlist.html"
When I select "Saab" from "#cars" by attr
When I press "Submit"
Then I should see "Option ( Saab ) has been selected successfully"

Scenario: Check of selecting option from drop down list
Given I am on "/test--when--i-select-option-from-dropdownlist.html"
When I select "Mercedes" from "cars" by its "id" attr
When I press "Submit"
Then I should see "Option ( Mercedes ) has been selected successfully"
31 changes: 31 additions & 0 deletions tests/step-definitions/webship.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,37 @@ When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (pronoundCase, opti
});
});

/**
* Selects option in select field
* Example: When I select "Mercedes" from "cars" its "id" attr
* Example: When I select "Saab" from "#cars" by attr
*
*/

When(/^(I|we)* select "([^"]*)?" from "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronoundCase, option, attrValue, itsCase, attr, attrCase) {

const hasASpace = attrValue.indexOf(' ');

var selector = '';
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
selector = attrValue;
}
else 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.waitForElementVisible('css selector', selector)
.click(selector)
.click(browser.element.findByText(option))
.click(selector);
});

/**
* Checks checkbox specified
* Example: When I check "Remember me"
Expand Down

0 comments on commit 1d5c6b8

Please sign in to comment.