量角器无法在我的Angular应用程序上打开手风琴下拉列表

时间:2015-02-28 00:05:40

标签: angularjs protractor angularjs-e2e

自昨晚以来,我一直在对此进行排查,但我无法弄清楚它为什么不起作用。

以下是Chrome在“元素”标签中捕获的代码 - https://gist.github.com/c0debreaker/2b0de5179710b9c236c3

// I added name="classPrinterAnalytics" to it hoping Protractor would find it
<div class="panel panel-default ng-isolate-scope" name="classPrinterAnalytics" ng-repeat="menu in leftNavMenusUIv2 track by menu.class" is-disabled="menu.disabled" is-open="isopenModel.opened[menu.class]" ng-class="{ 'classPrinterAnalytics' : isopenModel.opened[menu.class] }">
<div class="panel-heading" ng-click="toggleOpen()">
    <h4 class="panel-title">
        <a class="accordion-toggle" accordion-transclude="heading">
            <div ng-switch="" on="menu.glyphiconShow" class="ng-scope">
                <!-- ngSwitchWhen: hide -->
                <!-- ngSwitchWhen: show --><div ng-switch-when="show" class="ng-scope">
                    <div><i class="fa fa-print" style="font-size : 1.3em"></i><span class="hidden-xs ng-binding">&nbsp;&nbsp;&nbsp;Printer Analytics<i class="pull-right glyphicon submenu glyphicon-chevron-right" ng-class="{'glyphicon-chevron-down': isopenModel.opened[menu.class], 'glyphicon-chevron-right': !isopenModel.opened[menu.class] }"></i></span></div>
                </div>
            </div>
        </a>
    </h4>
</div>
<div class="panel-collapse collapse" collapse="!isOpen" style="height: 0px;">
    <div class="panel-body" ng-transclude="">
        <div class="ng-scope"><accordion-heading></accordion-heading></div>
        <!-- ngRepeat: submenus in menu.submenus -->
        <div ng-repeat="submenus in menu.submenus" class="ng-scope">
            <div ng-switch="" on="submenus.linktype">
                <!-- ngSwitchWhen: ui-router --><div ng-switch-when="ui-router" class="ng-scope">
                    <span class="dottedbar"></span>
                    <div id="subMenuOdometers" class="submenu ng-binding highlight" ng-class="{highlight: isOneHighlight(submenus), unhighlight : isGlobalDashboardActive}" ng-click="updateOneSpan(submenus)">Odometers
                        <i ng-hide="isGlobalDashboardActive" class="pull-right fa faCaretColor fa-caret-left" ng-class="{'fa-caret-left': isOneHighlight(submenus)}"></i>
                    </div>
                </div>
                <!-- ngSwitchWhen: static -->
            </div>
        </div><!-- end ngRepeat: submenus in menu.submenus -->
        <div ng-repeat="submenus in menu.submenus" class="ng-scope">
            <div ng-switch="" on="submenus.linktype">
                <!-- ngSwitchWhen: ui-router --><div ng-switch-when="ui-router" class="ng-scope">
                    <span class="dottedbar"></span>
                    <div id="subMenuPrinthead" class="submenu ng-binding" ng-class="{highlight: isOneHighlight(submenus), unhighlight : isGlobalDashboardActive}" ng-click="updateOneSpan(submenus)">Real Time Print Job
                        <i ng-hide="isGlobalDashboardActive" class="pull-right fa faCaretColor" ng-class="{'fa-caret-left': isOneHighlight(submenus)}"></i>
                    </div>
                </div>
                <!-- ngSwitchWhen: static -->
            </div>
        </div><!-- end ngRepeat: submenus in menu.submenus -->
        <div ng-repeat="submenus in menu.submenus" class="ng-scope">
            <div ng-switch="" on="submenus.linktype">
                <!-- ngSwitchWhen: ui-router --><div ng-switch-when="ui-router" class="ng-scope">
                    <span class="dottedbar"></span>
                    <div id="subMenuPrinthead" class="submenu ng-binding" ng-class="{highlight: isOneHighlight(submenus), unhighlight : isGlobalDashboardActive}" ng-click="updateOneSpan(submenus)">Battery
                        <i ng-hide="isGlobalDashboardActive" class="pull-right fa faCaretColor" ng-class="{'fa-caret-left': isOneHighlight(submenus)}"></i>
                    </div>
                </div>
                <!-- ngSwitchWhen: static -->
            </div>
        </div><!-- end ngRepeat: submenus in menu.submenus -->
        <div ng-repeat="submenus in menu.submenus" class="ng-scope">
            <div ng-switch="" on="submenus.linktype">
                <!-- ngSwitchWhen: ui-router --><div ng-switch-when="ui-router" class="ng-scope">
                    <span class="dottedbar"></span>
                    <div id="subMenuPrinthead" class="submenu ng-binding" ng-class="{highlight: isOneHighlight(submenus), unhighlight : isGlobalDashboardActive}" ng-click="updateOneSpan(submenus)">Printhead
                        <i ng-hide="isGlobalDashboardActive" class="pull-right fa faCaretColor" ng-class="{'fa-caret-left': isOneHighlight(submenus)}"></i>
                    </div>
                </div>
                <!-- ngSwitchWhen: static -->
            </div>
        </div><!-- end ngRepeat: submenus in menu.submenus -->
    </div>
</div>
</div>

这是我的spec文件

describe('UI End2End Testing', function() {

it('should authenticate', function() {
    browser.get('http://localhost:9000/#/login');
    element(by.model('username')).sendKeys('demouser1');
    element(by.model('password')).sendKeys('secret');
    element(by.id('circleLogin')).click();

    expect(element(by.binding('userData.username')).getText()).
        toEqual('demouser1');

});

it('should open accordion dropdown', function() {

    var hasClass = function (element, cls) {
        return element.getAttribute('class').then(function (classes) {
            return classes.split(' ').indexOf(cls) !== -1;
        });
    };

    element(by.name('classPrinterAnalytics')).click();

    //  hasClass(element(by.name('classPrinterAnalytics')), 'classPrinterAnalytics').then(function(d) {
    //    console.log('result', d); // d is false
    //    element(by.name('classPrinterAnalytics')).click();
    //  });

})

});

这是我的配置文件 - https://gist.github.com/c0debreaker/94d7b0744f7a83c6efd0

量角器能够登录,但无法在左侧导航栏中打开手风琴下拉列表。我得到的错误是

$ protractor conf.js
Using the selenium server at http://127.0.0.1:4444/wd/hub
.F

Failures:

  1) UI End2End Testing should open accordion dropdown
   Message:
     NoSuchElementError: No element found using locator: By.name("classPrinterAnalytics")
   Stacktrace:
     NoSuchElementError: No element found using locator: By.name("classPrinterAnalytics")
==== async task ====
Asynchronous test function: it()
Error
    at [object Object].<anonymous> (/Users/xxxx/repos/ui/test/spec/protractor/ui-spec.js:15:5)
    at Object.<anonymous> (/Users/xxxx/repos/ui/test/spec/protractor/ui-spec.js:1:63)

Finished in 8.485 seconds
2 tests, 2 assertions, 1 failure

然后我尝试了一个不同的解决方案,添加了这个,id =&#34; classPrinterAnalytics&#34;到我的html模板,并将代码更改/使用

element(by.id('classPrinterAnalytics')).click();

我只注意到它突出了该菜单,但从未点击/打开手风琴下拉列表。

1 个答案:

答案 0 :(得分:1)

看起来您需要点击手风琴内的切换链接:

element(by.css('div#classPrinterAnalytics a.accordion-toggle')).click();