0

Am working on protractor framework and I need to upload files to the application using a script.I know how to do it in java but no idea in javascript. Can someone please help me on this:

Java code :

public static void fileUpload(String script, String filePath) {
    try {
        Process proc = Runtime.getRuntime().exec("script " + script + " " + filePath);

    BufferedReader read = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    try {
        proc.waitFor();
    } catch (InterruptedException e) {
        System.out.println(e.getMessage());
    }
    }catch (IOException e) {
        System.out.println(e.getMessage());
    }
} 

Thanks !

Rahul
  • 759
  • 3
  • 21
  • 43
  • Maybe you check this thread: https://stackoverflow.com/questions/21305298/how-to-upload-file-in-angularjs-e2e-protractor-testing – huan feng Jun 11 '20 at 07:59

1 Answers1

0

Not sure what you meant by script here. Using sendkeys with upload input element should work in protractor.

like : var path = require('path'); var fileToUpload = '../test-resources/filetoupload'; //(the example relative path of the file ) var absolutePath = path.resolve(__dirname, fileToUpload); element(by.css('input[type="file"]')).sendKeys(absolutePath); uploadButton().click();

  • Script is a file that contains set of instructions like enter the path in the window popup ,selects the file and hits enter to upload. – Rahul Jun 11 '20 at 09:59