This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
26 / 27
Nov 2018

Ohhhhh. um. So you have two separate drivers? I don't think thats going to work. I bet android UIAutomator can only run one instance on a device.

Instead, Hm. If you first run App1, then tap a link to open the browser. Then you can automate the browser, then tap a button on the browser to return to your app. All with just one driver object (so just one appium session).

15 days later

Hey guys, @jonahss @DhirajAggarwal @jagadeeshkotha
I have a similar scenario here
Scenario:
I have a Hybrid app.
I login to the app and hit a link url which opens up the link in a browser.(Safari/Chrome)

Now i need to switch back to my app,for further testing.
How can i perform this particular action of switching to my App under test.?
Is there a command available in Appium to do so?
Any thoughts?

You could click on a link which brings you back to your app, or add a Back button. Kind of like how facebook login will redirect back to the app that launched it.

6 months later

Hi Jonahss,

I am launching the App in android when i click on the button it will open the browser with loaded URL.
Now i have to switch to browser and perform the action and return back to android app.

After loading browser page i am not able to switch the driver and not able to perform any action.
Please share if you have working sample code.

Thanks
Naresh

3 months later

Hi @jonahss

This is working spot on Android, swtich to browser from app and perform opeartion and using driver.naviaget().back() is obsoletely working fine,

But for IOS I tired below things to go back to App..
//Using xpath -
driver.findElement(By.xpath("//UIAButton[@name ='back to app']"));

//for this I'm getting instruments crash error and some time null pointer excpetions

//Using BackButton

driver.navigate().back()
//this is doing nothing....

Any suggestions for IOS to go back to app

10 days later

I have a separate admin link which i want to execute in between my app code to delete some entry from admin and again want to back to the app ...
Please guide me ...

24 days later

Apps are automated using Intruments. Once you leave the app, instruments crashes and doesn't let you automate anymore.

We automate Safari and Chrome using their separate debug ports (not Intruments) so even though Instruments dies, we can continue testing on the browser.

But you can't go back to your app once you leave, Instruments is done automating. This is how Apple's testing framework works currently.

It is possible that Apple could improve this and allow the operation in their new XCUITest framework. They have said they are very open to feedback, so go ahead and submit a report to Apple asking for the ability to test with XCUITest, and allow testers to leave the app and return to it.

did you find any solution for this? I have something very urgent to do and m stuck .. wasted almost 3 days now. Can you provide solution if it worked for u?

Thank you.

1 month later

I am also having the same issue on iOS. Works seamlessly on Android. I am not able to do a sendKeys or setValue on an element on a webpage opened in Safari (from my iOS native App).

1 month later
9 months later

My scenario is :

  1. Click “register with Facebook” link in my native app.
  2. Enter gmail id as email and click Login button on facebook login page ( I can perform switch context on emulator).
  3. Click “Login into google” button
  4. https://account.google.com3 page opened in chrome browser to check the verify code email

I am not able to switch to chrome browser in #4, I don’t know the activity and package of google app here, so I can’t be call switchActivity().

Let me know if you know solution for this scenario.Thanks

@Aru1 when Chrome page will open try 2 things:

  1. driver.getPageSource() - you can see what you see
  2. if first will not help to see Chrome elements try switch context to webView and repeat pageSource.
5 months later
4 months later

Hi @Mayuresh_Shirodkar, did you get the solution for this. I am also facing the same issue. My scenario is i have to open the chrome , do some validation on chrome page and return back to app.

can Anybody help me . I am automating in both android and ios with laster versions.

5 months later

Hi I am also facing this issue. Can anyone help me out with this. I click on a link in my app and it opens up the chrome browser. I want to get the url from chrome browser and switch to my native app.

12 days later

For android just using tap on phone’s back button (using key event) should do: driver.pressKey(new KeyEvent(AndroidKey.BACK));

For iOS; after tapping on deep link it takes to safari browser.
Browser address element: //XCUIElementTypeOther/XCUIElementTypeTextField[@name=“Address”]

Identify this element and get the value attribute to assert or action on it.
How to switch back to native?
Tap on this element so that clear button gets displayed and tap on clear button. Once again type your app’s scheme name in safari address field (every iOS app will have a scheme name; get this from your developer) e.g: driver.getKeyboard().sendKeys(“schemename://\n”);
This would popup the deep link alert, identify this alert - open button and tap on it - this takes you back to the iOS native app (AUT).

3 months later

Hi,It may be too late but it may be useful for other people.
You can do in following way:
//Alreday have driver created with default app which you want to test

//Here is point where you want to switch into another app
JavaScriptExecutor js = (JavaScriptExecutor)driver;
HashMap<String, String> map = new HasjMap<>();
map.put(“bundleId”,"")//ID of the app which you want to switch
js.executeScript(“mobile: lunachApp”, map)
… you can do what you want to do

//Switch to app1 again
driver.activateApp()