Skip to content

Commit 3e3f55a

Browse files
committed
Merge branch '1.0.x' of github.com:webship/webship-js into 1.0.x
2 parents e8c6ea5 + 17874cf commit 3e3f55a

File tree

3 files changed

+37
-55
lines changed

3 files changed

+37
-55
lines changed

tests/features/test--when--i-select-option-from-dropdownlist-by-attr.feature

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
Feature: An example of selecting an option in the dropdown list by its text label.
1+
Feature: An example of selecting an option from a dropdown list using its attributes.
22

33
As a tester,
4-
I want to be able to test selecting an option from a dropdown list by its text label.
4+
I want to be able to test selecting an option from a dropdown list using its attributes.
5+
6+
Scenario: Check selecting an option from a dropdown list using its attributes.
7+
Given I am on "/test--when--i-select-option-from-dropdownlist.html"
8+
When I select "Saab" from "#cars"
9+
When I press "Submit"
10+
Then I should see "Option ( Saab ) has been selected successfully"
11+
12+
Scenario: Check selecting an option from a dropdown list.
13+
Given I am on "/test--when--i-select-option-from-dropdownlist.html"
14+
When I select "mercedes" from "cars"
15+
When I press "Submit"
16+
Then I should see "Option ( Mercedes ) has been selected successfully"
517

618
Scenario: Check selecting an option from a dropdown list by its text label.
719
Given I am on "/test--when--i-select-option-from-dropdownlist.html"
820
When I select "Saab" from "Choose a car:"
9-
When I press "Submit" by attr
21+
When I press "Submit"
1022
Then I should see "Option ( Saab ) has been selected successfully"

tests/step-definitions/webship.js

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -414,52 +414,38 @@ When(/^(I|we)* fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr
414414
});
415415

416416
/**
417-
* Selecting the option in the dropdown list field by its text label.
418-
*
417+
* Selecting the option in the dropdown list field by its text label
419418
* Example: When I select "Mercedes" from "Cars"
419+
* Example: When I select "saab" from "#cars"
420+
* Example: When I select "Mercedes" from "cars"
420421
*
421422
*/
422-
When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, option, dropdownlist) {
423+
When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, option, selectList) {
423424

424-
const elementField = browser.element.findByText(dropdownlist, { exact: true });
425-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
426-
return browser.waitForElementVisible('css selector', '#' + eleAttribute.value)
427-
.click('#' + eleAttribute.value)
428-
.click(browser.element.findByText(option, { exact: true }))
429-
.click('#' + eleAttribute.value);
430-
});
431-
});
425+
const hasASpace = selectList.indexOf(' ');
432426

433-
/**
434-
* Selects option in select field.
435-
*
436-
* Example: When I select "Mercedes" from "cars" its "id" attr
437-
* Example: When I select "Saab" from "#cars" by attr
438-
*
439-
*/
440-
441-
When(/^(I|we)* select "([^"]*)?" from "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, option, attrValue, itsCase, attr, attrCase) {
442-
443-
const hasASpace = attrValue.indexOf(' ');
444-
445-
var selector = '';
446-
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
447-
selector = attrValue;
448-
}
449-
else if (!attr && hasASpace == -1){
450-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
427+
let selector = '';
428+
if((selectList.startsWith('#') || selectList.startsWith('.'))){
429+
selector = selectList;
451430
}
452-
else if (!attr && hasASpace > -1){
453-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
431+
else if (hasASpace == -1){
432+
selector = '[name="' + selectList + '"],[id="' + selectList + '"],[class="' + selectList + '"]';
454433
}
455434
else {
456-
selector = '[' + attr + '="' + attrValue + '"]';
435+
selector = browser.element.findByText(selectList, { exact: true });
457436
}
458437

459-
return browser.waitForElementVisible('css selector', selector)
460-
.click(selector)
461-
.click(browser.element.findByText(option, { exact: true }))
462-
.click(selector);
438+
let optionValue = '';
439+
const result = option.toLowerCase();
440+
441+
if(result == option){
442+
optionValue = '[value="' + option + '"]';
443+
}
444+
else{
445+
optionValue = browser.element.findByText(option, { exact: true });
446+
}
447+
448+
return browser.click(selector).click(optionValue).click(selector);
463449
});
464450

465451
/**

0 commit comments

Comments
 (0)