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());
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")