3

I am trying to automate file upload using Appium. Below is the code I am using (Java):

public class DownloadLocal {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
    caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.1");
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
    caps.setCapability("nativeWebTap",true);
    caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 7");
    caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
    IOSDriver driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    //Accessing files.com
    driver.get("http://files.com/");

    JavascriptExecutor js = (JavascriptExecutor) driver;

    try{
        driver.findElement(By.xpath("//*[@name='file_0']")).click();
        //Sleep to wait for upload prompt to appear
        Thread.sleep(3000);
    }catch (Exception e){
        e.printStackTrace();
    }
    //Checking if the prompt is creating an additional handle
    Set<String> contexts2= driver.getContextHandles();
    System.out.println(contexts2);
    try {
        int h=driver.manage().window().getSize().getHeight();
        int w=driver.manage().window().getSize().getWidth();
        Map<String, Object> params = new HashMap<>();
        System.out.println("x"+h);
        System.out.println("y"+w);
        params.put("x", 100);
        params.put("y", w/2);
        Thread.sleep(2000);
        js.executeScript("mobile: tap", params);

        //new TouchAction(driver).press(50,w/2).waitAction(Duration.ofSeconds(10)).release().perform();
    }catch (Exception e){
        e.printStackTrace();
    }
    driver.quit();
}
}

The code open the file upload prompt, however, I am not able to click it using Appium. I have tried using the tap gesture. Also, tried using TouchAction class and default alert function. However, I have not been able to successfully click the upload option. enter image description here

I am not looking to use options like Robot or Sikuli since I may later run the tests on appium server hosted on a remote machine.

BountyHunter
  • 1,413
  • 21
  • 35

0 Answers0