I have protractor tests running with Selenium using the IEDriverServer (32 bit). I am having a few issues with <select>
tags not being clicked and revealing their options.
Here is my conf.js:
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
multiCapabilities: [
{
browserName: 'internet explorer',
ignoreProtectedModeSettings: true,
ignoreZoomSetting: true,
nativeEvents: false
}
//,
//{
// browserName: 'chrome'
//}
],
baseUrl: String(process.env.COMPUTERNAME.toLowerCase()) === String('build') ? 'http://dev/' : 'http://' + process.env.COMPUTERNAME + '/',
// can use 'suites' instead of 'specs' - check api documentation
suites: {
dashboard: 'dashboard/myCallbacksWidget_spec.js',
employees: 'employees/employees_spec.js',
lead: 'lead/lead_spec.js',
},
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 80000
},
allScriptsTimeout: 80000,
onPrepare: function () {
browser.driver.manage().window().maximize();
if (process.env.TEAMCITY_VERSION) {
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.TeamcityReporter());
};
//var ScreenShotReporter = require('protractor-screenshot-reporter');
var ScreenShotReporter = require('protractor-html-screenshot-reporter');
var path = require('path');
jasmine.getEnv().addReporter(new ScreenShotReporter({
baseDirectory: 'tmp/report',
pathBuilder: function pathBuilder(spec, descriptions, results, capabilities) {
return descriptions.join('-');
}
//takeScreenShotsOnlyForFailedSpecs: true
}));
}
};
Here is my test:
describe('Lead Details Test', function () {
var arrowDown = '\uE015';
it('should open the first lead', function () {
browser.get('Slate.Iva/#/search-leads');
var firstItem = element(by.repeater('row in renderedRows').row(0));
firstItem.evaluate('onDblClickRow(row)');
expect(element(by.id('leadName')).isPresent()).toBe(true);
});
it('should select reason for difficulty', function () {
var reasonForDifficulty = element(by.id('reasonForDifficultySelect'));
expect(reasonForDifficulty.isPresent()).toBe(true);
reasonForDifficulty.click().sendKeys(arrowDown).sendKeys(protractor.Key.ENTER);
var saveButton = element(by.id('saveLead'));
saveButton.click();
browser.refresh();
var firstOption = element.all(by.options('item.id as item.name for item in leadData.reasonForDifficultyTypes')).first();
expect(firstOption.getText()).toEqual('Cosmetic Surgery');
});
});
When I do reasonForDifficulty.click()
, it highlights the <select>
but the sendKeys don't seem to work.
This code works if the <select>
is a chosen dropdown.
I am using Protractor 2.0.0, Selenium 2.45.0 and IEDriverServer 2.45.0.0. I am also running on Windows 8.1 and have IE11.
Is there a workaround for this or have I missed something in my code?
As per my comment the following should work;
var value = 'It was too difficult';
reasonForDifficulty.element(by.cssContainingText('option', value)).click();
This will select the drop down option "It was too difficult", this is good if you are testing a specific options effect on your application.
Alternatively if you wanted to do it by number you can use
var optionNum = 5
var options = reasonForDifficulty.all(by.tagName('option'))
.then(function(options){
options[optionNum].click();
});
The second one will select the 6th option (0 being the first of course) in the drop down list, this is a good option if you don't really care what option is selected, and is better if you are testing an application where data is changing constantly and it makes your tests that much more robust (in my opinion).