Created
November 29, 2014 15:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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