android 中 webview 的 appium 功能是什么?

what are the appium capabilities for webviews in android?

我试过使用以下功能

{
      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,
}

但仍然无法获取网络视图 url。下面是我的代码片段

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

如果您想在 chrome 应用程序 android 中打开 Web application/website 的 WebView,这些是强制性功能:

{'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}

如果在 chrome 手机上执行操作,您应该切换到 WEB_VIEW。

语法在Python:

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

这是我对上下文切换的完整回答:

回复评论:

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