Switch App to browser and back to app

Below is the java code, which worked for me on appium sever 1.16.0 (need appropriate chrome driver executable for this to work)

ad.findElement(By.xpath("//android.widget.Button[@text=‘XYX’]")).click(); //native app button when clicked on the button chrome browser is launched
forceWait(40000);
ad.activateApp(“com.android.chrome”); //activating the chrome app
ad.getContextHandles(); // getting available contexts
ad.context(“WEBVIEW_chrome”); //switching to webview_chorome content
forceWait(15000);
ad.findElement(By.xpath("//input[@type=‘email’]")).sendKeys("[email protected]");
ad.findElement(By.xpath("//input[@type=‘password’]")).sendKeys(“abcd@1234”);
ad.findElement(By.id(“signInSubmit”)).click();
ad.context(“NATIVE_APP”); //setting context to native app
ad.activateApp(“com.native.app”); //activating the native app

Hi @Mayuresh_Shirodkar and @akash_mahato1

I got a working solution for my hybrid app.
Here’s what I did:

  1. Logged in to my hybrid app
  2. Clicked on a link which opened chrome.
  3. Switched context to web before validating anything.
  4. Did some validation with chrome elements.
  5. Switched context back to native
  6. Used self.driver.back() to go back to the App.

Hope this helps, please reply if this works or not.

Thx,
Ammar

I had a similar scenario:

  1. Open Windows app
  2. Click on boutton, --> Open a browser separately
  3. New Instance of my windows app thats opened
  4. I dont want to create a new instance, i just want to switch between chrome and my windows app , but I don’t now how

[TestClass]
public class NuancesUITest
{

    static WindowsDriver<WindowsElement> SessionExemple;
    

    [ClassInitialize]
    public static void PrepareForTestinNuances(TestContext testContext)
    {
        Debug.WriteLine("ClassInitialize");

        AppiumOptions Exemple = new AppiumOptions();
        Exemple.AddAdditionalCapability("app", @"Path");
        Exemple.AddAdditionalCapability("appArguments", "--Environment=development.me");
        Exemple.AddAdditionalCapability("platformName", "Windows");
        Process.Start(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe");
        SessionExemple= new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), capNuances);

Hello Everyone, Currently, I am using multiremote feature with two capabilities (ios app and chrome browser) defined in webdriverio config file and looking to automate webapp and mobileapp (ios) by adding test cases in the same spec file. 1. First test case opens up browser and click elements 2. second test should open mobile app, click element, enter value. 3. Going back to browser test case again and continue automation. Basis scenario is, like joining zoom meeting where browser client starts meeting and mobile app joins the same meeting. To achieve this switching between browser, mobile, browser views, what would be the best way ? Any inputs please, #webdriverio #appium ? Thanks

Hello jonahss,

I am testing one application through appium.
when I entered mobile number in that Mobile Emulator I got OTP in Web portal ,
So need to grab that OTP from web Portal and need to enter that OTP in mobile application in emulator.

So Can you please help me with code how can I switch app to browser grab that OTP and then come back to app emulator .

Could you please suggest how I can do this …?

Hello Ammar,

Could you please share code how can we switch to Mobile to browser or come back to mobile app in emulator.

In latest version used driver.activateApp("your.app.id"). If you don’t need to return to the active session of the main application.
Or driver.navigate().back() and go back until u get main application active session(repeat it several times, if it’s necessary).

Solution for iOS app using webdriverIO :

First you need to get your app id , to find that run below command on terminal :

xcrun simctl listapps booted
OR
xcrun simctl listapps

you will output as collection with list of apps installed on simulator, it should something like : “com.XXX.YYY.ZZZ”

Now use command as
await driver.activateApp(“com.XXX.YYY.ZZZ”)

Hope this is work for you as well.