Apk installation command not working

Hi guys ,

I tried installing an apk using the command " driver.installApp("/Test Suite/Apps/com.android.chrome.apk")
, but it throws an error

Unable to install [/Test Suite/Apps/com.android.chrome.apk] to device with id [null]. Error [Error: spawn OK] (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 57 milliseconds

Please Help.

@ArunPG:- I think you have not mentioned device name caps, for me driver.installApp command is working fine.
send your complete code which you used. So may be we can help you.

1 Like

Hi ,

I am sorry , i really didn’t get what you have meant by device name caps.

Please find the code below

public void browsing() throws InterruptedException{

    System.out.println("Browser");
    Batterystart();
    dr.installApp("/Test Suite/Apps/com.android.chrome.apk");
    
    Thread.sleep(5000);
    
    for(int j=0;j<=3;j++){
    dr.startActivity("com.android.chrome", "com.google.android.apps.chrome.Main");
    dr.findElementById("com.android.chrome:id/terms_accept").click();
    dr.findElementById("com.android.chrome:id/negative_button").click();
    Thread.sleep(2000);
    dr.findElementById("com.android.chrome:id/got_it_button").click();
    dr.findElementById("com.android.chrome:id/url_bar").click();
    dr.findElementById("com.android.chrome:id/url_bar").sendKeys("Steve Jobs");
    dr.sendKeyEvent(66);
    dr.findElementByAccessibilityId("Steve Jobs - Wikipedia").click();
    dr.scrollToExact("External links");
    dr.scrollTo("Search Wikipedia");
    for(int i=0;i<=3;i++){
        Thread.sleep(5000);
        
     dr.swipe(448, 1095, 448,225,0);
     
    }
    dr.sendKeyEvent(3);
    }    
    Batteryend();
    Thread.sleep(2000);
}

are you using appium?

if yes then where is caps= capabilities? have you defined desired capabilities ? for more details how to open browser on android device and run your tests refer below link. In description I have added sample code. download it and try it.

driver.installApp can install app in between the test, but first you need to define some capabilities to launch any other app first.

I have defined all the “Caps” necessary , as pasted below

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.VERSION, “5.1”);
capabilities.setCapability(MobileCapabilityType.PLATFORM, “Windows”);
capabilities.setCapability(“deviceName”, “04z107x15082100044”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(MobileCapabilityType.TAKES_SCREENSHOT, “true”);
capabilities.setCapability(“appPackage”, “com.android.dialer”);
capabilities.setCapability(“appActivity”, “com.android.dialer.DialtactsActivity”);

    dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    dr.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

Please let me know if I need to add any new capability to make the app install work and it would be very help full if you could paste your code where you have used the appinstall method.

Thanks.

Please tell me what is your test case?.

See, through my caps, dialer activity will me launched as a default app and then it goes to my method browsing where it should install chrome application and then launch it.

See the code which i had pasted earlier for the browsing method.

Its simple as that i need to install an another app and launch it while running on another app

FYI:- Chrome is a browser and you can’t treat chrome just as a normal android app. Coming to your issue.
Every android devices already have chrome installed. In that case you don’t need to install chrome at all,

FYI : I am not running on an emulator nor my device has chrome application pre-installed and its not necessary that all the devices should have chrome app as different odm’s have different customisations.

Anyways my concern is not just for chrome app, its about how to install an app using the dr.installapp command.

Thank you, Appium_Master.

Refer this code which is working fine for me. Hoping that it will help you to understand how it will work.

public class appInstalled {
AppiumDriver driver;

@BeforeClass
public void setUp() throws MalformedURLException{
	
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("deviceName","192.168.0.7:5555");	
    capabilities.setCapability("appPackage", "com.policybazaar");
	capabilities.setCapability("appActivity","com.policybazaar.login.Splash_DashBoard"); // This is Launcher activity of your app (you can get it from apk info app)
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
     driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
   
}


@org.testng.annotations.Test
public void Test()
{
	
	if(!driver.isAppInstalled("com.experitest.ExperiBank"))
	{
		driver.installApp("F:\\Learning\\automation_latest\\PolicyBazar\\apps\\EriBank.apk");
		System.out.println("App is installed");
	}
	
	else
	{
		System.out.println("App is already installed");
		
		driver.removeApp(("com.experitest.ExperiBank"));
		System.out.println("App is Removed");
		
		driver.installApp("F:\\Learning\\automation_latest\\PolicyBazar\\apps\\EriBank.apk");
	
	}
	
}

}

1 Like

Hi Arun,

I am also facing the same issue

public void f() throws InterruptedException, IOException {

      File scrFile = ((TakesScreenshot) dr).getScreenshotAs(OutputType.FILE);
      FileUtils.copyFile(scrFile, new File("E:\\update\\imran.png"));
      
      dr.installApp("D:\\pjt\\supporting formats and apks\\android system info.apk");

errors

Unable to install [D:\pjt\supporting formats and apks\android system info.apk] to device with id [null]. Error [Error: spawn OK] (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 73 milliseconds

kindly tell me have you got some solutions for this////…

thanks

Dear master,

Please find the code i used which is not using for me

@Before Class
DesiredCapabilities capabilities = new DesiredCapabilities();

       capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Windows");
       capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Android");
       capabilities.setCapability(MobileCapabilityType.VERSION, "5.0.2");
     
       capabilities.setCapability("platformName"," Android");
       capabilities.setCapability("deviceName", "0123456789ABCDEF");
                  
       capabilities.setCapability("appPackage", "org.mozilla.firefox");
       capabilities.setCapability("appActivity","org.mozilla.firefox.App");

dr= new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),capabilities);
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

}

@Test
public void f() throws InterruptedException {

   dr.installApp("D:\\pjt\\power management\\pm files\\battery\\browser\\Firefox.apk");

Thread.sleep(1000);
}