Skip to content

Instantly share code, notes, and snippets.

@DonAbney
Created November 29, 2014 15:36
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 DonAbney/30c6329bf14dc9b3fc54 to your computer and use it in GitHub Desktop.
Save DonAbney/30c6329bf14dc9b3fc54 to your computer and use it in GitHub Desktop.
An approach for finding a selected option in Protractor that works with PhantomJS and gives useful output
'use strict';
var IndexPage = function() {
};
IndexPage.prototype = Object.create({}, {
load: {
value: function(){
browser.get('app/index.html');
}
},
optionWithText: {
value: function(inputText){
browser.wait(function() {
return element(by.cssContainingText('option',inputText)).isPresent();
}, 1500, 'No option containing text "' + inputText + '" was found...sorry');
return element(by.cssContainingText('option',inputText)).isSelected().then(function(isSelected){
if(isSelected) {return 'selected';}
else {return 'Element found but not selected';}
});
}
}
});
module.exports = IndexPage;
'use strict';
var IndexPage = require('./index.page.js');
var indexPage;
describe('My App', function() {
describe('My view', function() {
beforeEach(function() {
indexPage = new IndexPage();
indexPage.load();
});
it('should check to see if the My Option is selected', function() {
expect(indexPage.optionWithText('My Option')).toBe('selected');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment