appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
379 stars 186 forks source link

[Bug]: cannot parse capability goog:chromeOptions unrecognized chrome option: AcceptInsecureCertificates #586

Closed mdberryh closed 1 year ago

mdberryh commented 1 year ago

Description

I used npm to set up appium@next, which is appiumV2. I am also using the Appium dot net SDK 5.3 beta version. I am able to use native contexts, but I cannot switch to a "WEBVIEW" due to the error:

[Chromedriver@a04e] invalid argument: cannot parse capability: goog:chromeOptions [Chromedriver@a04e] from invalid argument: unrecognized chrome option: AcceptInsecureCertificates

appiumserverlogs_error.log

Environment

Details

Please provide more details, if necessary.

Code To Reproduce Issue [ Good To Have ]

var chromeOptions = new ChromeOptions { AcceptInsecureCertificates=true };
chromeOptions.AddArgument("--log-level=3");
chromeOptions.AddArgument("--ignore-certificate-errors");

var capabilities = new AppiumOptions();
capabilities.DeviceName = "emulator-5554";
capabilities.PlatformName = "Android";
capabilities.AutomationName = "UiAutomator2";
capabilities.App = string.Empty;
capabilities.PlatformVersion = "12";
capabilities.AddAdditionalAppiumOption(AndroidMobileCapabilityType.ChromeOptions, chromeOptions);

capabilities.AddAdditionalAppiumOption(MobileCapabilityType.NewCommandTimeout, 24 * 60 * 60);
capabilities.AddAdditionalAppiumOption("wdaStartupRetries", "4");
capabilities.AddAdditionalAppiumOption("wdaStartupRetryInterval", "20000");

// Noreset = false removes the app data or cache
capabilities.AddAdditionalAppiumOption(MobileCapabilityType.NoReset, false);

// FullReset Uninstalls the App and reinstall every time.
capabilities.AddAdditionalAppiumOption(MobileCapabilityType.FullReset, false);

var _driver1 = new AndroidDriver(new Uri("http://127.0.0.1:4723/"), capabilities);

int timeout = int.Parse(Timeout);
WebDriverWait wait = new WebDriverWait(_driver1, TimeSpan.FromSeconds(timeout));
wait.PollingInterval = TimeSpan.FromSeconds(2);
wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException)); // ignore stale exception issues

string desiredContext = "WEBVIEW";
// Switch to specific webview
bool validContext = false;
foreach (var context in (_driver1.Contexts))
{
    if (desiredContext == "WEBVIEW")
    {
        validContext = true;
    }
}
// Switch to WEB VIEW APP
if (validContext)
{
    _driver1.Context = desiredContext;
    return true;
}
mdberryh commented 1 year ago

I wanted to add that I tried a python client with the same running appium server, and it worked perfectly. This tells me the appiumV2 server is working fine. It is something in the chain that C# side is using....or a setting not set on my side.

for those interested here is the python code to just try it out.

from appium import webdriver

from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy

options = UiAutomator2Options()
options.platformVersion = '12'

# Appium1 points to http://127.0.0.1:4723/wd/hub by default 
driver = webdriver.Remote('http://127.0.0.1:4723', options=options)

print("checking contexts")
print(driver.contexts)

webview = driver.contexts[1]
driver.switch_to.context(webview)
# ...
driver.switch_to.context('WEBVIEW_com')
#driver.switch_to.context('NATIVE_APP')
elementsList = driver.find_elements(AppiumBy.XPATH, "//*");
print(elementsList[0])

obj = elementsList[0]

print(obj.__dict__)
print(dir(obj))

for elem in elementsList:
    print(elem.text)
    if elem.text =='Click to Play!':
        elem.click()
mykola-mokhnach commented 1 year ago
2023-02-08 14:55:16:945 [Chromedriver@2db0] Starting W3C Chromedriver session with capabilities: {
2023-02-08 14:55:16:946 [Chromedriver@2db0]   "capabilities": {
2023-02-08 14:55:16:947 [Chromedriver@2db0]     "alwaysMatch": {
2023-02-08 14:55:16:949 [Chromedriver@2db0]       "goog:chromeOptions": {
2023-02-08 14:55:16:950 [Chromedriver@2db0]         "androidPackage": "com.TEST.arcade",
2023-02-08 14:55:16:950 [Chromedriver@2db0]         "androidUseRunningApp": true,
2023-02-08 14:55:16:951 [Chromedriver@2db0]         "androidProcess": "com.TEST.arcade",
2023-02-08 14:55:16:952 [Chromedriver@2db0]         "androidDeviceSerial": "emulator-5554",
2023-02-08 14:55:16:952 [Chromedriver@2db0]         "CapabilityName": "goog:chromeOptions",
2023-02-08 14:55:16:953 [Chromedriver@2db0]         "BinaryLocation": null,
2023-02-08 14:55:16:953 [Chromedriver@2db0]         "LeaveBrowserRunning": false,
2023-02-08 14:55:16:954 [Chromedriver@2db0]         "Extensions": [],
2023-02-08 14:55:16:955 [Chromedriver@2db0]         "DebuggerAddress": null,
2023-02-08 14:55:16:955 [Chromedriver@2db0]         "MinidumpPath": null,
2023-02-08 14:55:16:956 [Chromedriver@2db0]         "PerformanceLoggingPreferences": null,
2023-02-08 14:55:16:956 [Chromedriver@2db0]         "AndroidOptions": null,
2023-02-08 14:55:16:957 [Chromedriver@2db0]         "UseSpecCompliantProtocol": true,
2023-02-08 14:55:16:960 [Chromedriver@2db0]         "BrowserName": "chrome",
2023-02-08 14:55:16:962 [Chromedriver@2db0]         "BrowserVersion": null,
2023-02-08 14:55:16:962 [Chromedriver@2db0]         "PlatformName": null,
2023-02-08 14:55:16:963 [Chromedriver@2db0]         "AcceptInsecureCertificates": true,
2023-02-08 14:55:16:964 [Chromedriver@2db0]         "UseWebSocketUrl": null,
2023-02-08 14:55:16:965 [Chromedriver@2db0]         "UnhandledPromptBehavior": 0,
2023-02-08 14:55:16:965 [Chromedriver@2db0]         "PageLoadStrategy": 0,
2023-02-08 14:55:16:966 [Chromedriver@2db0]         "Proxy": null,
2023-02-08 14:55:16:967 [Chromedriver@2db0]         "UseStrictFileInteractability": false,
2023-02-08 14:55:16:967 [Chromedriver@2db0]         "args": [
2023-02-08 14:55:16:968 [Chromedriver@2db0]           "--log-level=3",
2023-02-08 14:55:16:969 [Chromedriver@2db0]           "--ignore-certificate-errors",
2023-02-08 14:55:16:971 [Chromedriver@2db0]           "--headless"
2023-02-08 14:55:16:972 [Chromedriver@2db0]         ]
2023-02-08 14:55:16:973 [Chromedriver@2db0]       },
2023-02-08 14:55:16:973 [Chromedriver@2db0]       "goog:loggingPrefs": {
2023-02-08 14:55:16:974 [Chromedriver@2db0]         "browser": "ALL"
2023-02-08 14:55:16:975 [Chromedriver@2db0]       }
2023-02-08 14:55:16:976 [Chromedriver@2db0]     }
2023-02-08 14:55:16:976 [Chromedriver@2db0]   }
2023-02-08 14:55:16:977 [Chromedriver@2db0] }

maybe just don't use ChromeOptions class as it targets a desktop browser, which has different capabilities in comparison to the mobile one. Just provide the necessary options as vanilla dictionary in capabilities

mdberryh commented 1 year ago

Wow... so simple I didn't even try that... didn't even think that we could simply dump a dictionary in there... it works well. I have to point out this isn't a good "fix" but a very good work around.

my capabilities now look like this:


    var chromeOptions = new Dictionary<string, string>();

    var capabilities = new AppiumOptions();
    capabilities.DeviceName = "emulator-5554";
    capabilities.PlatformName = "Android";
    capabilities.AutomationName = "UiAutomator2";
    capabilities.App = string.Empty;
    capabilities.PlatformVersion = "12";
    capabilities.AddAdditionalAppiumOption(AndroidMobileCapabilityType.ChromeOptions, chromeOptions);

[debug] [AndroidUiautomator2Driver@baf4] Creating session with W3C capabilities: { [debug] [AndroidUiautomator2Driver@baf4] "alwaysMatch": { [debug] [AndroidUiautomator2Driver@baf4] "platformName": "Android", [debug] [AndroidUiautomator2Driver@baf4] "goog:chromeOptions": {}, [debug] [AndroidUiautomator2Driver@baf4] "appium:automationName": "UiAutomator2", [debug] [AndroidUiautomator2Driver@baf4] "appium:deviceName": "emulator-5554", [debug] [AndroidUiautomator2Driver@baf4] "appium:platformVersion": "12", [debug] [AndroidUiautomator2Driver@baf4] "appium:newCommandTimeout": 86400, [debug] [AndroidUiautomator2Driver@baf4] "appium:wdaStartupRetries": "4", [debug] [AndroidUiautomator2Driver@baf4] "appium:wdaStartupRetryInterval": "20000", [debug] [AndroidUiautomator2Driver@baf4] "appium:noReset": false, [debug] [AndroidUiautomator2Driver@baf4] "appium:fullReset": false [debug] [AndroidUiautomator2Driver@baf4] }, [debug] [AndroidUiautomator2Driver@baf4] "firstMatch": [ [debug] [AndroidUiautomator2Driver@baf4] {} [debug] [AndroidUiautomator2Driver@baf4] ] [debug] [AndroidUiautomator2Driver@baf4] }

Dor-bl commented 1 year ago

@mdberryh Closed as not an issue. if you think a fix is needed please open a new issue with detailed information.