amit joshi
amit joshi

Reputation: 31

How to launch already installed app from iPhone using appium

I am writing an automation script using Java + TestNG + Appium.

In a test scenario, I am trying to launch already installed application on iphone. (Box in this case). Box contains some MS office file which I need to access. I am not very sure how can I achieve this.

I tried multiple options such as extracting .app file from iTunes and deploying using Appium, but no success.

Can someone please guide me, if this is possible. If yes, how?

Upvotes: 1

Views: 16616

Answers (3)

KavinduWije
KavinduWije

Reputation: 42379

Refer below code snippet:

cap.setCapability(IOSMobileCapabilityType.APP_NAME, "{appName}");

This capability is the MOST important capability to open the app automatically if the app is already installed on mobile device.

    public static IOSDriver<IOSElement> capabilities() throws IOException {
    
    //Configure absolute path of the .ipa file

    FileInputStream fis = new FileInputStream(System.getProperty("user.dir")+"//automation.properties");
    System.out.println(fis);
    Properties prop = new Properties();
    prop.load(fis);     

    File f = new File("src/test/resources");
    File fs = new File(f, (String)prop.get("iOSAppName"));
    
    DesiredCapabilities cap = new DesiredCapabilities(); 
    cap.setCapability(MobileCapabilityType.PLATFORM_NAME, (String)prop.get("iOSPlatformName"));
    cap.setCapability(MobileCapabilityType.UDID, (String)prop.get("iDeviceUDID"));
    cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
    cap.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone");

    driveriOS = new IOSDriver<IOSElement>(new URL("http://127.0.0.1:4725/wd/hub"), cap);
    
    //Check app is already installed if NOT install app to device automatically
    if(driveriOS.isAppInstalled("com.test.app")==false)
    {
    cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
    }
    
    //cap.setCapability(MobileCapabilityType.BROWSER_NAME, (String)prop.get("iOSBrowserType"));
    cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, (String)prop.get("iOSPlatformVersion"));
    cap.setCapability(IOSMobileCapabilityType.APP_NAME, "{appName}"); //Provide your app name here
    cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, (String)prop.get("updateWDABundleId"));
    cap.setCapability("xcodeSigningId", "iPhone Developer");
    cap.setCapability("xcodeOrgId", (String)prop.get("xcodeOrgId"));

    driveriOS = new IOSDriver<IOSElement>(new URL("http://127.0.0.1:4725/wd/hub"), cap);
    driveriOS.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    stepRecorder(Status.INFO, "iOS Driver initiated");

    return driveriOS; 

}

Upvotes: 0

Chad Esguerra
Chad Esguerra

Reputation: 1

this works for me

HashmMap<String, Object> args = new HashMap<String,Object>();
args.put("bundleId","*YOUR_APP_BUNDLEID*");
driver.executeScript("mobile: launchApp", args);

Upvotes: 0

Amit Srivastava
Amit Srivastava

Reputation: 1105

Automate a preinstalled app with following scenario.

1.This will only work for applications that are signed with a DEVELOPMENT cert.

2.This will NOT work for applications that are signed with a DISTRIBUTION cert

3.If you have created the app with a developer provisioning profile, and built yourself. Or downloaded it using testFlight, and is signed with a development provisioning profile

4.This is because Apple's Instruments will not allow you to interact with those applications which is live. (Even if you knew the bundleId)

if your app is in development mode please follow these things 1.The bundleId of the app that was installed on the device. Use that as the app capability.

  1. Follow the Appium Real Devices guide (substitute any .ipa/.app reference with the bundleId)

In addition to your regular desiredCapabilities (ex. platformName, platformVersion, deviceName).. these should be your desiredCapabilities:

For preinstalled apps

desiredCaps['app'] = 'yourbindleID'

Device's unique identifier

desiredCaps['udid'] = '1824y983h2849gh2498'

Upvotes: 6

Related Questions