量角器没有检测到弹出对话框(md-dialog-content)

时间:2015-12-10 06:07:46

标签: javascript selenium automation protractor

it("Checking for file uploaded pop up window",function(){
    expect(element(by.css('md-dialog-content')).isPresent()).toBe(true); //Check the upload success window

    var h2 = element(by.css('md-dialog-content > h2')).getText(); //Get h2 of the pop up

    expect(h2).toEqual("Attention"); //h2 is equal to attention

    var h2Content = element(by.css('md-dialog-content > p')).getText(); //get h2 content

    expect(h2Content).toEqual("File: "+"repair_anonymized_1000sample.json"+" uploaded"); //content h2 is equal to ...

    element(by.css('.md-actions > button')).click(); //Click on the close button

    expect(element(by.css('md-dialog-content')).isPresent()).toBe(false); //THe dialog box will not exist

});

我要做的是检查&md-dialog-content'的弹出对话框。元件。我正在检查它里面的h2和p元素。

但是量角器给了我一个错误,说他们期待第一个期望是“错误的”。而不是真的。这意味着他们没有检测到明显存在的md-dialog-content。

是的,以前的'它'测试已经完成了生成此对话框以弹出的所有必要步骤。

我的测试规范的前面步骤(我正在使用ng-file-upload):

it("Upload files",function(){

    var fileToUpload = "/home/vagrant/Desktop/repair_anonymized_1000sample.json";

    var absolutePath = path.resolve(fileToUpload);

    browser.executeAsyncScript(function(callback){ //Fire Fox needs this code to display the hidden input element or it will give error of element not visible

        document.querySelectorAll('input[type="file"]')[0]

        .style.visibility= 'visible';

        callback();

    });

    var input = element(by.css('input[type="file"]'));

    input.sendKeys(absolutePath);   

    browser.sleep(2000); //wait for the alert to appear

});

1 个答案:

答案 0 :(得分:0)

您可能需要等待弹出对话框become present

var EC = protractor.ExpectedConditions,
    dialog = element(by.css('md-dialog-content'));  // or just $('md-dialog-content')

browser.wait(EC.presenceOf(dialog), 5000);

如果您收到Timeout Exception,这意味着该元素不存在,或者您的定位器不正确,或者该元素可能位于iframe内。