How to launch already installed app from iPhone using appium - ios

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?

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.
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'

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

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;
}

Related

Ionic 4 IOS deeplinks redirect to broswer instead of the actual app

i am trying to set up deeplinks for my ionic 4 ios app, i followed these steps to accomplish the given task:
i uploaded an apple site association file to the web version of the app, i used the actual bundle id and app id prefix from Certificates, Identifiers & Profiles page on apple.com
i verified the website url using https://branch.io/resources/aasa-validator, i got 5/5 green results
i also enabled associated domains in both xcode and on apple.com dev space for the application
inside the code in the app components i used the following code :
const subDeepLinks = this.deeplinks.route({
'/verify/:code': VerifyPage,
'/reset-password/:token': ResetPasswordPage,
}).subscribe((match: any) => {
this.zone.run(() => this.router.navigate([match.$link.path]));
}
});
And here is the list of the deeplink variables from package.json
"ionic-plugin-deeplinks": {
"URL_SCHEME": "<my-domain-name>",
"DEEPLINK_SCHEME": "https",
"DEEPLINK_HOST": "<my-domain-name>"
}
I test this using iPhone simulator, i created a contact with a url that is supposed to lead to the app. But when i click on it i get redirected to the web version of the app.
Any help is appreciated, thanks!
well, it turned out aasa worked. i used my gf's iphone installed the app and checked. so nevermind

Issues running MDX toolkit wrapped Swift 4.2 iOS application after Enterprise distribution. Exception Type: EXC_BREAKPOINT (SIGTRAP) iOS 12.4

I am working on distributing my iOS application within the enterprise after wrapping the application with MDX toolkit. The application works on all my devices when I run it using Xcode but after the distribution the application crashes on launch on the company allocated devices. We are using Secure Hub for enterprise distribution.
The crash log files that I retrieved from the device are :
I also managed to collect device console logs and the console logs are as follows:
Can't get most elevated app state from dictionary {
BKSApplicationStateExtensionKey = 0;
SBApplicationStateDisplayIDKey = "my.app.NARMS.dev"
SBApplicationStateKey = 0;
SBApplicationStateProcessIDKey =398;
SBApplicationStateRunningReasonsKey = (
{
SBApplicationStateRunningReasonAssertionIdentifierKey =
Resume;
SBApplicationStateRunningReasonAssertionReasonKey = 10000;
},
{
SBApplicationStateRunningReasonAssertionIdentifierKey = "FBSceneSnapshotAction:my.app.NARMS.dev";
SBApplicationStateRunningReasonAssertionReasonKey = 4;
}
);
}
Please note that I had to convert a swift 3.0 project to swift 4.2 before facing this issue and also we are trying Enterprise distribution.
An Update to the above question:
We decided to try out skipping the step where we wrap the .ipa file with MDX toolkit and that solved the problem for us.
So instead of the following steps:
Archive and generate .ipa
Wrap the .ipa with MDX toolkit to generate .mdx.
Distribute .mdx with XenMobile.
We did this:
Archive and generate .ipa
Distribute .ipa with XenMobile

Access iphone’s settings app on real device

I want to access device settings, I checked there are similar posts but no answer for real device.
I tried passing parameters as
desired_caps['app'] = 'settings' and desired_caps['bundleId'] = 'com.apple.Preferences'
But I get error Instruments Trace Error : Target failed to run: Permission to debug com.apple.Preferences was denied. The app must be signed with a development identity (e.g. iOS Developer).
Seems like above works on simulator but not device.
I can launch my test app, so I'm passing other parameters correctly.
Or is there any other way to access device settings?
desired_caps = dict()
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '9.2.1'
desired_caps['deviceName'] = 'iPhone'
desired_caps['udid'] = '09d905a'
desired_caps['app'] = 'settings'
# desired_caps['bundleId'] = 'com.apple.Preferences'
# desired_caps['fullReset'] = True
desired_caps['newCommandTimeout'] = 1000
config_iOS.driver_settings = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
For check all the info related to device you can use ios-deploy library. As per my knowledge you are Missing something. Can you attach appium logs.?
It's not possible to automate application which is on profile other than development. As the error says Settings application settings application of the application is build with development profile.
So the first moment when you try to fetch any element it will show the error.
In short, You can't automate application downloaded from app store/system application or installed with release mode using Appium.

How to set desired capabilities for launching ios app on real device with appium ( c#)

Hi I am automating the native ios application on ios . I already automated android native app but for launching the appium server on mac from c# code running on windows I need to know how to setup the Desired capabilities for ios platform.
Please find the below peace of code for c# language:
DesiredCapabilities capabilities = new DesiredCapabilities();
TestCapabilities testCapabilities = new TestCapabilities();
testCapabilities.App = "";
testCapabilities.AutoWebView = true;
testCapabilities.AutomationName = "";
testCapabilities.BrowserName = String.Empty; // Leave empty otherwise you test on browsers
testCapabilities.DeviceName = "Needed if testing on IOS on a specific device. This will be the UDID";
testCapabilities.Platform = TestCapabilities.DevicePlatform.IOS; // Or Android
testCapabilities.PlatformVersion = String.Empty; // Not really needed
testCapabilities.AssignAppiumCapabilities(ref capabilities);
driver = new AppiumDriver(testServerAddress, capabilities, INIT_TIMEOUT_SEC);
driver.Manage().Timeouts().ImplicitlyWait(IMPLICIT_TIMEOUT_SEC);
To run Appium test on iOS simulator/real device, Mac hardware is needed and to run test on real device, team id from apple developer account is also needed. More details here.
Connect the iPhone to MacOS via cable or connect both iPhone and Mac computer to same wireless network (WiFi).
C# code for initialising appium iOS driver to run test on real device:
//Initialise driver options
AppiumOptions capabilities = new AppiumOptions();
//Declare capabilities
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS");
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "13.2"); //put real device iOS version
capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "iPhone X"; //put real device name
capabilities.AddAdditionalCapability(MobileCapabilityType.AutomationName, "XCUITest");
if (appInstalled)
{
//if app is installed and don't want to re-install, use below capability
capabilities.AddAdditionalCapability(IOSMobileCapabilityType.BundleId, "<app-bundle-id>");
}
else
{
//(re)installs app
capabilities.AddAdditionalCapability(IOSMobileCapabilityType.AppName, "<name-of-test-app>");
capabilities.AddAdditionalCapability(MobileCapabilityType.App, "<absolute-path-to-test-app.app>");
}
capabilities.AddAdditionalCapability(MobileCapabilityType.Udid, "<real-device-Udid>");
capabilities.AddAdditionalCapability("xcodeOrgId", "<team-id>");
capabilities.AddAdditionalCapability("xcodeSigningId","iPhone Developer");
//Initialise iOS driver
var driver = new IOSDriver<IMobileElement<AppiumWebElement>>(capabilities);

iOS app gets reset on creation of new appium session

I am performing following steps
Set capabilities and launch ABC app. By providing app path
capabilities.setCapability("app", "/Users/changdeojadhav/Library/Developer/Xcode/DerivedData/ABC/Build/Products/Debug-iphonesimulator/ABC.app");
capabilities.setCapability("bundleId","com.abc.ABC-Demo");
Perform some actions
quit driver by driver.quit()
Set capabilities for Xyz app. And launch XYZ app
Perform some steps
quit driver by driver.quit()
relaunch ABC app as mentioned in step #1.
Expected is "App ABC should retain it's state" but ABC gets reset.
I have launched appium with --no-reset parameter.
Any idea about what I am missing here
Thanks
As far as I can tell, there is currently no solution to reopening the application after going to the home screen without clearing the app from cache.
In past versions of iOS/Appium, the solution was to do:
from appium import webdriver
driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
driver.close_app()
app = driver.find_element_by_xpath('//UIAApplication/UIAWindow/UIAScrollView/UIAButton[#name="sampleApp"]')
app.click()
However this currently crashes Appium
I will update this question when I log a github issue for it.
The Appium help page says that it only supports multiple app testing in a single test session for Android without Selendroid:
iOS: Support for automating multiple apps in one session: No
Android:Support for automating multiple apps in one session: Yes (but not when using the Selendroid backend)
http://appium.io/slate/en/master/?ruby#toc_27
I'm guessing that is why you are having this issue, and it's most likely an Instruments/XCode issue.
I was able to relaunch the same app without it resetting its state with Appium 1.3.1 running with Xcode 6.1 on a Mac Mini running Mavericks. I did not try launching another app in between launches. I'm driving the automation from C#.
protected AppiumDriver GetAppiumDriver(bool forRestart = false)
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("appium-version", "1.0");
capabilities.SetCapability("platformName", "iOS");
capabilities.SetCapability("platformVersion", "7.1");
capabilities.SetCapability("deviceName", "iPhone Simulator");
capabilities.SetCapability("app", _appPath);
capabilities.SetCapability("locationServicesEnabled", true);
if (forRestart)
{
capabilities.SetCapability("noReset", true);
}
AppiumDriver driver = new AppiumDriver(_serverUrl), capabilities, new TimeSpan(0, 5, 0));
return driver;
}
public void iOSMobileAppBasicUITest()
{
// Initially Launch the app with the noReset capability at its default value of false to ensure a clean starting point.
_driver = GetAppiumDriver(false);
//Shut down the app.
_driver.Quit();
// Launch the app again, this time with the noReset capability set to true.
_driver = GetAppiumDriver(true);
// Use _driver to do whatever UI automation is desired.
// Optional: Send the app to the background so that iOS does state preservation.
_driver.BackgroundApp(3);
// Close the app.
_driver.CloseApp();
// Alternative: _driver.Quit();
// Launch the app.
_driver.LaunchApp();
// Alternative: _driver = GetAppiumDriver(true);
...
As I known, Appium by default runs in fast reset mode, and it tries to clear app's data when the session ends (as a result of the invocation of quit() in this case). If your want to keep app's data, the option --no-reset should work for you.

Resources