Skip to content

Instantly share code, notes, and snippets.

@e-oz
Created December 30, 2014 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-oz/0c5d9dbd3131d602f367 to your computer and use it in GitHub Desktop.
Save e-oz/0c5d9dbd3131d602f367 to your computer and use it in GitHub Desktop.
Protractor helper function: Click option[index] of select element
/**
* Click option[index] of select element
* @param select
* @param index
* @returns {protractor.promise}
*/
function clickOption(select, index) {
var deferred = protractor.promise.defer();
select.click().then(function () {
var options = select.all(by.css('option'));
expect(options.count()).toBeGreaterThan(index);
expect(options.get(index).getText()).toBeDefined();
options.get(index).click().then(function () {
select.click();
browser.waitForAngular().then(deferred.fulfill, deferred.reject);
}, deferred.reject);
}, deferred.reject);
return deferred.promise;
}
@e-oz
Copy link
Author

e-oz commented Dec 30, 2014

Usage example:

    var select = element.all(by.css('[ng-model="data.app.class_of_trade"] select')).first();
    yourHelpersObject.clickOption(select, 1).then(function () {
      // here will be your code of expectations, this code is just for example
      expect(element.all(by.css('.pc-field-error:not(.ng-hide)')).count()).toEqual(0);
      expect(element.all(by.css('.input-label.assertive')).count()).toEqual(0);
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment