Search code examples
javascriptfile-uploadprotractorrobotjs

How to upload files in file dialog in protractor test, not using robotjs?


I'm using this code for browse (upload) files in dialog:

 var uploadPathLogo = "path to file";
 var uploadLogo = function() {

        browser.driver.sleep(3000).then(function() {
            robot.typeStringDelayed(uploadPathLogo, 23000);
            robot.keyTap("enter");
            browser.driver.sleep(3000);
        });

    },

The problem is that when I run the test locally everything is fine, but when I run the test on remote machine the path is not written into the dialog. Is there any other library that can be used for this purpose?


Solution

  • I found solution for this, it can be used for any upload dialog on page:

        var uploadPathLogo = "path to file";    
        var uploadLogo = function(path) {
                browser.wait(EC.presenceOf(element(by.css('input[type="file"]'))), 30000, "Input type file element is not present in DOM").then(function() {
                    $('input[type="file"]').sendKeys(uploadPathLogo);
                });
            };