在量角器中处理模态弹出窗口(使用黄瓜js)

时间:2016-09-14 14:22:23

标签: angular protractor cucumberjs

我正在使用Protractor(使用Cucumber js)进行应用程序的E2E测试。我正在尝试使用它来测试负面情况,即当用户输入用于创建对象的重复值时,它不应该被创建,并且用户应该在模式框中获得错误消息(在2-3秒后消失)。但是,在点击时测试模态框的可见性时,量角器会抛出错误。这是我的代码:

Scenario: User sets in a duplicate logical object name

        If a user enters a name which is the duplicate of an existing logical object, they should not be able
        to create the logical object

        When the user clicks on the "New" button
        Then the "New Logical Object" panel should be displayed

       Given the user enters "Part" in the "Name" field in the form
       And the user enters "Part Description" in the "Description" textarea in the form
       And the user uploads the "ProjectManagement.png" file

       When the user clicks on the "Create" button in the form
       Then there should be an error message in the form of a popup

这是stepdef文件:

@Then(/^there should be an error message in the form of a popup$/)
    public assertPopUpError() {
        return StepDefUtil.executeInIFrame<BladePanelPage>( BladePanelPage, (page: BladePanelPage) => {
            page.assertPopUpErrorMessage();
        });
    }

页面文件(BladePanelPage.ts)

/**
     * Asserts presence of popup message- for a step which fails .
     *
     *
     * @return Promise.
     */
    public assertPopUpErrorMessage(): Chai.PromisedAssertion {

        let xpathString = '//aw-pop-up-message//div[contains(@class, 'aw-modal-content')]';
        return expect(element(by.xpath(xpathString )).isPresent()).to.eventually.equal(true, 'The Element with xpath "' + xpath + '" is not displayed');
    }
  

AW-弹出消息

是一个自定义的Angular2组件。

来自量角器的错误信息是:

  

E / launcher - 带有xpath的元素   “// aw-pop-up-message // div [contains(@class,”aw-modal-content“)]”is   未显示:预期false等于true

我尝试了显示herehere的方法,但它无效。禁用protractor.config.js文件中的动画似乎也不起作用。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

https://stackoverflow.com/a/32076359/1989583

以上回答对我有用。事实证明,这是一个量角器issue,这个答案的解决方法允许我测试弹出元素。感谢@Chris Traynor的解决方法。

注意:早些时候,我在同一个问题上使用了接受的答案,这对我不起作用。