加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 使用Protractor在IE中选择标记的问题

发布时间:2020-12-17 16:56:56 所属栏目:安全 来源:网络整理
导读:我使用IEDriverServer(32位)运行Selenium的量角器测试.我在 select上遇到了一些问题标签未被点击并显示其选项. 这是我的conf.js: exports.config = {// The address of a running selenium server.seleniumAddress: 'http://localhost:4444/wd/hub',// Capa
我使用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.

是否有解决方法或我错过了我的代码?

解决方法

根据我的评论,以下内容应该有效;

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当然是第一个选项),如果您不关心选择哪个选项,这是一个不错的选项,如果您正在测试数据应用程序,则更好正在不断变化,它使你的测试更加强大(在我看来).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读