[Android] Hybrid app with embedded Chrome view for purchases

Hello,

I work with a hybrid application, which has its own webview, on which we switch the context to run tests.

Some interactions open an embedded chrome browser window for purchases (which is inspectable in Chrome inspector from the desktop browser).

However, when I switch context from our app’s webview to “WEBVIEW_chrome” I cannot find any of the elements, and furthermore I am still seeing and able to interact with the elements in our application’s webview, even though the current driver context is successfully switched to “WEBVIEW_chrome”.

What am I doing wrong?
Why is the context switched successfully and the html elements are still the ones from the application webview and not the chrome window?

Please tell me what details I need to add to investigate this issue (version, server logs, clarifications).

Regards,
Sealview

Hi,
Every Hybrid app will be having 2 contexts.

  1. Native app context
  2. WebView context (each app has its own webview context name). Use this webview context name to switch and locate elements in webview.

To automate Webview I have followed the below steps and it worked.
1. Mandatory step 1:
Your app webview - remote debugging should be enabled.
Refer below link
https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews

If your app webview is remote debugging enabled, then from chrome-inspector (Chrome app) you should be able to locate the elements from your app. Explore/search in google.

2. Capabilities setup:
To automate Webview we should set the chrome options at the capabilities before starting the appium session.

      capabilities.setCapability("chromedriver-executable", "---chromedriver file path---");
     capabilities.setCapability("showChromedriverLog", true);
     ChromeOptions chromeOpt = new ChromeOptions(); 
     chromeOpt.setExperimentalOption("androidPackage", "---your app package ID---");
     capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOpt);

Switch between context:
Step 3:
Every app has its own webview context name. Open your app first then list out all the context names. Most of the time it will return 2 context names (Native and webview name).
Example code:

	    Set<String> contextSet = androidDriver.getContextHandles();
    		for(String contextName: contextSet) {
    			System.out.println("context Name " + contextName);
    			androidDriver.context(contextName); //Changing the context
    		}

If you want to locate elements in Webview then switch to the webview (pass the web view name which we captured in above line)
If you want to locate elements in Native context then switch to native context.

Hope this will solve your problem.

I have no problems switching to the app’s webview, that works fine, and I can find element.

My app has 3 CONTEXTS:
native
APP_WEBVIEW
WEBVIEW_CHROME

When I switch from APP_WEBVIEW > WEBVIEW_CHROME, I cannot find the elements inside the chrome webview, and I can still see the elements in my app’s webview, even though driver.context points to WEBVIEW_CHROME