Search code examples
iosmobileautomationappium

Automate launching Safari from a iOS mobile app using appium


I am doing some automation with Appium on a iOS mobile app.

I need to:

  • open the app
  • do some tasks
  • open safari

I looked around how to do it but I've been reading that it's impossible due to a limitation in apple's framework, it doesn't allow you to sent commands to more than one app per session.

Does anyone know a way around this? Or if what I read is just not 100% true.


Solution

  • it doesn't allow you to sent commands to more than one app per session

    Thats true, but you can run 2 sessions in a single test:

    1. create instance of appium driver with app-based capabilities
    2. do what you need in the app
    3. quit driver
    4. create instance of appium driver with browser-based capabilities
    5. do what you need in the safari
    6. quit driver

    In a quick way it may look like:

    @Test
    public void testBothAppAndSafari() throws MalformedURLException {
        URL appiumServerUrl = new URL("<your appium server host>");
        DesiredCapabilities appCaps = new DesiredCapabilities();
        // put required native app capabilities in appCaps
        DesiredCapabilities safariCaps = new DesiredCapabilities();
        // put required safari capabilities in safariCaps
    
        IOSDriver driver = new IOSDriver(appiumServerUrl, appCaps);
        driver.findElement(<locator for element in native app>).click();
        // do whatever you want with mobile app
        driver.quit();
    
        driver = new IOSDriver(appiumServerUrl, safariCaps);
        driver.findElement(<locator for element in web>).click();
        // do whatever you want in safari
        driver.quit();
    }