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

Handling modal pop-up in protractor (with cucumber js)

我正在使用 Protractor(带有 Cucumber js)对应用程序进行 E2E 测试。我正在尝试用它测试一个消极的场景,即当用户输入重复的值来创建对象时,它不应该被创建,并且用户应该在模式框中收到一条错误消息(2-3 秒后消失).但是,在测试单击时模态框的可见性时,protractor 会抛出错误。这是我的代码:

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-pop-up-message

是自定义 Angular2 组件。

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

E/launcher - The Element with xpath "//aw-pop-up-message//div[contains(@class, "aw-modal-content")]" is not displayed: expected false to equal true

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

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

注意:早些时候,我对同一个问题使用了公认的答案,但对我不起作用。