Switch between native app and browser ANDROID


I’m testing a native app and currently I’m trying to press a button which opens a link in a google chrome window. What I want to do with this is make a simple getCurrentUrl and make a assertEquals and make sure the correct URL is opened.

From what I have understood I have to switch to the new webpage activity, I did it like this

    //Clicking the link which redirects me to the webpage   

    //get the currentactivity when I open the link, 
     String activity = driver.currentActivity();

    driver.startActivity(appPackage, activity);

    String URL=driver.getCurrentUrl();
    Assert.assertEquals(URL, "theCorrectUrl.com/example/test");

When I run this code I get Unable to launch the app: Error: Permission to start activity denied.

Maybe this isn’t so strange because the startActivity isn’t really the “startactivity” when you start chrome, but at the same time. I want to assert the current URL when I click the link and not when I start google chrome. Hope I made myself clear.
If I just make getCurrentUrl after clicking the link and dont change the startactivity I get “Not yet implemented. Please help us: http://appium.io/get-involved.html” .

So I’m kinda stuck, would appreciate all help. Cheers
Appium v1.4.16 , Java client 4.1.2, Android.

Someone a solution for this issue ?

Try the Java solution posted here…


I have used the Ruby example posted on the same page (since my projects are in Ruby, and it works perfectly)

hi @rickesnick I guess without starting new activity itself this works fine. I too faced the same scenario and the code snippet like below worked out.

Thread.sleep(1000); //Try to put some sleep in between because the URL gets some time to get loaded
String url=driver.getCurrentUrl;