Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Aug 20, 2020 13:35

This method launches the Settings application on iOS devices. It validates that the app is on its home page or navigates to it in case it is not.

public static boolean launchSettingsApp(RemoteWebDriver driver) {
    //defining variables
    HashMap<String, Object> params1 = new HashMap();
    HashMap<String, Object> params2 = new HashMap();
    //launch settings application
    switchToContext("NATIVE_APP");
    params2.put("name", "Settings");
    try {
        driver.executeScript("mobile:application:close", params2);
    } catch (Exception e) {
        System.out.println("Settings is already closed, continue with script");
    }
    try {
        driver.executeScript("mobile:application:open", params2);
    } catch (Exception e) {
        return false;
    }
    params2.clear();
    //configure hay stack:
    params1.put("screen.top","3%");
    params1.put("screen.height","10%");
    params1.put("screen.left","27%");
    params1.put("screen.width","43%");
    //validate we are on the home page of app:
    try {
        for(int i=0;i<6;i++){
            //scroll o top of the page
            params2.put("location", "50%,1%");
            driver.executeScript("mobile:touch:tap", params2);
            sleep(2000);
            String title=(String) driver.executeScript("mobile:screen:text", params1);
            if (title.toLowerCase().startsWith("settings")){
                return true;
            }else {
                //go back one page and check again
                params2.put("location", "5%,5%");
                driver.executeScript("mobile:touch:tap", params2);
                sleep(3000);
                continue;
            }
         }
        return false;
    } catch (Exception e) {
        System.out.println(e.toString());
        return false;
    }    
}