Switching Application in iOS

Hello,

Is there anyway to switch to another app in iOS ,similar to StartActivity() which is present for android driver?

1 Like

Hi Mitesh

did you get any solution for this issue. If I do call driver.closeApp() then the simulator shutdown. Please let me know if you find any solution for this issue.

Thanks
Karthik

No karthik, I didn’t found any solution till yet. Will update you on this if I get any solution for this in future.

Hi Mitesh,

Did you get any solution/alternative for this?

Thanks,
Rohit Gupta

Hello Rohit,

I did explore for the alternatives but was not able to find any solution apart from the solution suggested in the thread above.

        Found a solution 

We have to set noReset field value as true in Desired Capability. This will not
allow the simulator to close when we call driver quit. So all the settings will
remain same for our next new driver.
Note: It can not be used for parallel access of two apps, but serial

  1. Add noReset in DC like desiredCapability(“noReset”,“true”);
  2. create a driver with your app in Desired Capability. This will install your app in simulator.
  3. quit driver.
  4. create new driver with Settings app in Desired Capability. and do the changes you want using script.
  5. Quit driver
  6. create new driver with your app and start working

Oh so sorry karthik I thought I have mentioned this solution earlier because we have already implemented same solution for our project.

Hey i tried what you recommended. But i get error
rg.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{app=com.apple.Preferences, noReset=true, platformVersion=10.3, platformName=iOS, deviceName=iPhone6}], required capabilities = Capabilities [{}]
Build info: version: ‘3.3.1’, revision: ‘5234b325d5’, time: ‘2017-03-10 09:10:29 +0000’

sample code :
driver.findElement(By.name(“Done”)).click();
System.out.println(driver.switchTo().alert().getText());
driver.switchTo().alert().accept();
driver.quit();

    IOSDriver d;
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", config.get("name"));
    capabilities.setCapability("platformVersion", config.get("version"));
    capabilities.setCapability("deviceName", "iPhone6");
    capabilities.setCapability("noReset", "true");
    capabilities.setCapability("app", "com.apple.Preferences");
    d = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
    d.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);

    driver.launchApp();