量角器图片未在对话框上载?

时间:2018-09-12 06:52:44

标签: css angular selenium jasmine protractor

我想使用量角器测试图像上传功能,但是我的书面脚本无法正常工作。 This is the image dialogue box.,当我们单击对话框图像时,它会打开窗口以选择所需的图像。选择图像后,该框的作用类似于image。我想编写一个脚本,通过该脚本我可以上传图片,然后点击“保存”按钮。This is the css of dialogue box. 下面给出的是我尝试过但无法正常工作的脚本。遇到的错误消息是this

   var path = require('path');
   var fileToUpload = '../new image.jpeg';
    var absolutePath = path.resolve('__dirname', fileToUpload);
    console.log(absolutePath);
 var fileElem=element(by.css('label[for="cropper-file-input"]'));
 browser.wait(EC.presenceOf(fileElem), 2000,);
 fileElem.sendKeys(absolutePath);

1 个答案:

答案 0 :(得分:0)

尝试以下方法。希望对您有帮助。

 fileUpload(element: ElementFinder, fileElem: ElementFinder, filePath: string): promise.Promise<void> {
        //We are using the setFileDetector method to let WebDriver know that we are uploading files from a local directory to a remote server.
        //Having this configuration resolves the "Failed: invalid argument: File not found" error that occurs otherwise.
        browser.driver.setFileDetector(new utils.remote.FileDetector);

        return browser.executeScript(`arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px';  arguments[0].style.opacity = 1`, element)
            .then(() => fileElem.sendKeys(filePath));
    }