我使用IEDriverServer(32位)与Selenium一起运行了量角器测试。我遇到了一些<select>
标记没有被点击并显示其选项的问题。
这是我的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
}));
}
};
这是我的测试:
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');
});
});
当我执行reasonForDifficulty.click()
时,会突出显示<select>
,但sendKeys似乎无法正常工作。
如果<select>
是选定的下拉列表,则此代码有效。
我使用的是Protractor 2.0.0,Selenium 2.45.0和IEDriverServer 2.45.0.0。我也在Windows 8.1上运行并拥有IE11。
是否有针对此的解决方法或我在代码中遗漏了哪些内容?
答案 0 :(得分:1)
根据我的评论,以下内容应该有效;
var value = 'It was too difficult';
reasonForDifficulty.element(by.cssContainingText('option', value)).click();
这将选择下拉选项“它太难了”,如果您在应用程序上测试特定的选项效果,这是很好的。
或者,如果您想通过编号进行操作,可以使用
var optionNum = 5
var options = reasonForDifficulty.all(by.tagName('option'))
.then(function(options){
options[optionNum].click();
});
第二个选项将在下拉列表中选择第6个选项(0当然是第一个选项),如果您不关心选择哪个选项,这是一个不错的选项,如果您正在测试数据不断变化的应用程序,使您的测试更加稳健(在我看来)。