Example #1
0
    public SeleniumBrowser(Browsertype browsertype, string location)
    {
        if (string.IsNullOrEmpty(location))
        {
            location = Environment.CurrentDirectory;
        }

        switch (browsertype)
        {
        case Browsertype.Chrome:
        {
            var chromeOptions = new ChromeOptions();
            chromeOptions.AddArguments("headless");
            chromeOptions.AddArguments("disable-gpu");
            chromeOptions.AddArguments("no-sandbox");
            chromeOptions.AddArguments("disable-dev-shm-usage");
            chromeOptions.AddArgument("disable-infobars");
            chromeOptions.AddArgument("--incognito");
            chromeOptions.AddUserProfilePreference("credentials_enable_service", false);
            chromeOptions.AddUserProfilePreference("profile.password_manager_enabled", false);
            chromeOptions.AddArgument("dns-prefetch-disable");
            _webDriver = new ChromeDriver(location, chromeOptions);
            _webDriver.Manage().Window.Size = new Size(1920, 1080);
            break;
        }

        case Browsertype.Firefox:
        {
            var firefoxOptions = new FirefoxOptions();
            firefoxOptions.AddArguments("--headless");
            _webDriver = new FirefoxDriver(location, firefoxOptions);
            _webDriver.Manage().Window.Size = new Size(1920, 1080);
            break;
        }

        default:
            throw new ArgumentOutOfRangeException(nameof(browsertype), browsertype, null);
        }
    }
Example #2
0
 public static SeleniumBrowser FromBrowserType(Browsertype browsertype)
 {
     return(new SeleniumBrowser(browsertype, Environment.CurrentDirectory));
 }