Search code examples
javaandroidmobileui-automationappium

Could not change profile image of my Android app while automating with Appium


Enter image description here

I could not select an image from the gallery app. I am automating my Android app using Appium.


Solution

    1. I have launch Android photo gallery using following code from a activity.

      Intent intent =  new Intent(Intent.ACTION_PICK);
      intent.setType("image/*");
      startActivity(intent);
      
    2. Test code can have following implementation.

      WebDriverWait wait = new WebDriverWait(driver, 30);wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.android.gallery:id/grid")));
       driver.context("NATIVE_APP");
       HashMap<String, Double> map = new HashMap<String, Double>();
       map.put("x", 0.3);
       map.put("y", 0.3);
       (driver).executeScript("mobile: tap", map);