Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch from one app to another app at run time

Tags:

appium

Is there any possibility to switch from one application to another application at run time using Appium.

Thanks

like image 546
Sravan Avatar asked Mar 28 '14 10:03

Sravan


People also ask

How do you jump from one app to another?

To jump from one app to another app, you can add an action button. Clicking on the button will redirect the user to the linked app. The button will link to a specific App-Id.


1 Answers

Finally I found accurate answer, May it will be usefull for some one

source https://www.linkedin.com/grp/post/6669152-6027319885992841219?trk=groups-post-b-title

 // App1 capabilities
 String calculatorAppPackageName="com.android.calculator2";
 String calculatorAppActivityName="com.android.calculator2.Calculator";

// App2 capabilities
 String settingsAppPackageName="com.android.settings";
 String settingsAppActivityName="com.android.settings.Settings";

 @Before
 public void setUp() throws MalformedURLException
 {
        DesiredCapabilities capabilities = DesiredCapabilities.android();
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "192.168.215.101:5555");
        capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, calculatorAppPackageName);
        capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, calculatorAppActivityName);
        driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

 }

 @Test
    public void testApp() throws InterruptedException, MalformedURLException
    {
        //Perform calculation in calculator
        driver.findElement(By.name("4")).click();
        driver.findElement(By.name("×")).click();
        driver.findElement(By.name("3")).click();
        driver.findElement(By.name("=")).click();

        //launch settings App
        driver.startActivity(settingsAppPackageName, settingsAppActivityName);

        //Switch OFF WIFI
        driver.findElement(By.id("com.android.settings:id/switchWidget")).click();

        //Re launch calculator App
        driver.startActivity(calculatorAppPackageName, calculatorAppActivityName);

        //Validate results
        String result = driver.findElement(By.className("android.widget.EditText")).getText();
        System.out.println("Result : " + result);
        Assert.assertEquals("Incorrect Result", "12", result);
    }
like image 69
Sravan Avatar answered Oct 19 '22 07:10

Sravan