Search code examples
c#selenium-webdriverselenium-chromedriverremotewebdriver

ChromeDriver and RemoteWebDriver differences


So I have a .Net/C#/Selenium project which is currently split into 2 branchs (mobile and web) I would like to have this all in once branch but at the moment I am getting errors setting up the web driver. For the mobile version which links to a physical device via appium this works very nicely

protected static IWebDriver? _driver = null;

or

protected static WebDriver? _driver = null;

or

protected static RemoteWebDriver? _driver = null;

var options = new ChromeOptions();
options.PlatformName = "Android";
options.AddAdditionalChromeOption("androidPackage", "com.android.chrome");
options.AddArgument("PlatformName=Android");
options.AddArgument("platformVersion=6.0.0");
options.AddArgument("deviceName=Tab");
options.AddArgument("isRealMobile=true");
options.AddArgument("network=false");
Uri url = new Uri("http://127.0.0.1:4723/wd/hub");
_driver = new RemoteWebDriver(url, options);

However for the web version I need to setup like this otherwise I get a not found error for ExecuteCdpCommand

protected static ChromeDriver? _driver = null;

    var options = new ChromeOptions();
options.AddArgument("enable-automation");
options.AddArgument("disable-dev-shm-usage");
options.AddArgument("ignore-certificate-errors");
options.AddArgument("ignore-ssl-errors");
options.AddArgument("disable-popup-blocking");
options.AddArgument("window-size=1920,1080");
if (!System.Diagnostics.Debugger.IsAttached)
{
    _isDebug = false;
    options.AddArgument("headless");
}
options.AddArgument("disable-gpu");
options.AddUserProfilePreference("download.default_directory", _downloadPath);
options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("download.directory_upgrade", true);

ChromeDriverService serviceObj = ChromeDriverService.CreateDefaultService();
_driver = new ChromeDriver(serviceObj, options, TimeSpan.FromSeconds(_maxWait));
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Cookies.DeleteAllCookies();
_driver.Manage().Window.Maximize();
_driver.ExecuteCdpCommand(
    "Emulation.setTimezoneOverride",
    new Dictionary<string, object>
    {
        ["timezoneId"] = "Europe/London"
    });

There has to be a way around this, can anyone help please. Cheers


Solution

  • To solve this I have created 2 seperate projects within the same solution. I for the desktop tests, 1 for the mobile. Most of the shared functions are being moved to a shared dll which both can access. Works very nicely indeed.