what are the appium capabilities for webviews in android?

1.4k Views Asked by At

I have tried using below capabilities

{
      maxInstances: 1,
      browserName: '',
      appiumVersion: '1.18.2',
      platformName: 'android',
      platformVersion: '10.0',
      deviceName: 'device',
      webviewConnectTimeout: '90000',
      chromeOptions: {args: ['--windowTypes=webview']},
      safariLogAllCommunication: true,
      enableWebviewDetailsCollection: true,
      ensureWebviewsHavePages: true,
      showChromedriverLog: true,
      app: './android/app/build/outputs/apk/',
      noReset: true,
      autoWebview: true,
}

but still not able to fetch the webview url. Below is the snippet of my code

let contexts = driver.getContexts();
console.log(contexts);
driver.switchContext('WEBVIEW_be.belgacom.hello');
console.log(driver.getPageSource());
console.log(driver.getUrl());
2

There are 2 best solutions below

2
Mohammad Monfared On BEST ANSWER

By meaning WebView if you want to open a web application/website in chrome app in android, these are the mandatory capabilities:

{'platformName': 'Android,'udid': YOUR DEVICE UDID, 
'appActivity': 'com.google.android.apps.chrome.Main', 
'appPackage': 'com.android.chrome',
'chromedriverExecutable': PATH OF CHROME DRIVER, 
'deviceName': ANY NAME,'chromeOptions': {'w3c': False},'autoGrantPermissions': True}

You should switch to WEB_VIEW in case of doing action on the chrome mobile.

The syntax is in Python:

driver.switch_to.context['NATIVE_APP]   #appium chrome driver
driver.switch_to.context['WEB_VIEW_chrome']    # selenium chrome driver

Here is my full answer about context switching: https://stackoverflow.com/a/62284044/7302505

Answer to the comment:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--incognito")
1
Mikhail Nersesov On

for Java:

ChromeOptions options = new ChromeOptions(); 
options.setExperimentalOption("w3c",false); 
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);