2016-09-14 65 views
0

我正在使用量角器(使用Cucumber js)进行E2E测试的应用程序。我试图用它来测试一个负面的情况,即当用户输入一个重复的值来创建一个对象时,它不应该被创建,并且用户应该在一个模式框中得到一个错误信息(它会在2-3秒后消失)。但是,在单击时测试模态框的可见性时,量角器会发出错误。这里是我的代码:在量角器中处理模态弹出(使用黄瓜js)

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 /发射器 - 元素使用XPath “// AW-弹出消息// DIV [含有(@class,” AW -modal内容“)]”是 不显示:预期假等于真

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

回答

0

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

以上回答为我工作。原来,这是一个量角器issue,解决方法是让我测试弹出元素。感谢@Chris Traynor提供解决方法。

注意:早些时候,我对相同的问题使用了接受的答案,这对我来说并不适用。