Manish
Manish

Reputation: 29

How to upload apk file from local path to android emulator automatically in scripting(Appium)?

Currently my dev team integrated their repository with jenkins it's automatically generate apk once it build from jenkins is there anyway to install that local apk in android emulator using automation script.

Please anybody help me on this.

Upvotes: 1

Views: 2511

Answers (2)

VSB
VSB

Reputation: 327

Use below mentioned Function and call it when you want to execute the .APK file on an Emulator

  1. You should have Appium server running before calling this
  2. this will launch the emulator for you and will install the .APK file on the same.

     protected AppiumDriver getAppiumDriver() throws MalformedURLException {
    
        if(appDriver == null)
        {
            DesiredCapabilities cap = new DesiredCapabilities();
    
            // APK location on system
             File appDir = new File("/Users/therapybox/Desktop/Appium/Apps");
    
    
            /* ANDROID DEPENDENCIES START*/
    
            File newApp = new File (appDir ,"selendroid-test.apk" );
            cap.setCapability(CapabilityType.BROWSER_NAME, "");
            cap.setCapability("deviceName", "Android Emulator");
            cap.setCapability("platformName", "Android");
            cap.setCapability("platformVersion","8.0");
            cap.setCapability("noReset", true);
            cap.setCapability("avd", "Nexus5XAPI26");
            cap.setCapability("automationName", "UiAutomator2");
            cap.setCapability("app", newApp.getAbsolutePath());
            appDriver = new AppiumDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);
        }
    
        return appDriver;
    }
    

Upvotes: 1

Suban Dhyako
Suban Dhyako

Reputation: 2526

If you are using appium you can set app capabilities in your DesiredCapability.

 DesiredCapabilities caps = new DesiredCapabilities();
 caps.setCapability(MobileCapabilityType.APP, "path to your apk");

Upvotes: 1

Related Questions