private (DriverService, IWebDriver) GetSafariDriver(ILogger logger)
        {
            var options = new SafariOptions();

            options.SetLoggingPreference(LogType.Browser, SeleniumLogLevel.All);

            logger.LogInformation("Starting Safari");

            var driverService = SafariDriverService.CreateDefaultService();

            return(driverService, new SafariDriver(driverService, options, _arguments.Timeout));
        }
Пример #2
0
        private void SetupDriverOptions(BrowserType browser, DriverOptions options, LogLevel logLevel)
        {
            switch (browser)
            {
            case BrowserType.Chrome:
                if (options != null && options is ChromeOptions)
                {
                    _chromeOpts = options as ChromeOptions;
                }
                _chromeOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.Edge:
                if (options != null && options is EdgeOptions)
                {
                    _edgeOpts = options as EdgeOptions;
                }
                _edgeOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.Firefox:
                if (options != null && options is FirefoxOptions)
                {
                    _firefoxOpts = options as FirefoxOptions;
                }
                _firefoxOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.IE:
                if (options != null && options is InternetExplorerOptions)
                {
                    _ieOpts = options as InternetExplorerOptions;
                }
                _ieOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.Phantomjs:
                if (options != null && options is PhantomJSOptions)
                {
                    _phantomJsOpts = options as PhantomJSOptions;
                }
                _phantomJsOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.Safari:
                if (options != null && options is SafariOptions)
                {
                    _safariOpts = options as SafariOptions;
                }
                _safariOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;
            }
        }
Пример #3
0
        public override IWebDriver InitialiseForLocal()
        {
            var options = new SafariOptions()
            {
                PlatformName            = MacPlatform,
                BrowserVersion          = "14.0.2",
                UnhandledPromptBehavior = UnhandledPromptBehavior.Accept
            };

            if (LoggingEnabled)
            {
                options.SetLoggingPreference(LogType.Browser, LogLevel.Info);
            }

            const string driverDirectoryForMacOs = "/usr/bin/";

            return(new SafariDriver(driverDirectoryForMacOs, options, LocalDesktopTimeout));
        }
Пример #4
0
        public static IWebDriver Build(string browser, bool runTestsRemotely, string driverVersion = "Latest")
        {
            IWebDriver webDriver;

            const string nodeURI = "http://23.100.236.70:4446/wd/hub";

            switch (browser.ToLower())
            {
            case "chrome":
                var chromeOptions = new ChromeOptions();
                var chromeBrowser = new ChromeBrowser();
                chromeBrowser.StartIfNotRunning();
                chromeOptions.DebuggerAddress = $"localhost:{chromeBrowser.DebuggingPort}";

                chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                new DriverManager().SetUpDriver(new ChromeConfig(), driverVersion);
                webDriver = runTestsRemotely ? new RemoteWebDriver(new Uri(nodeURI), chromeOptions) : new ChromeDriver(chromeOptions);
                break;

            case "chrome-incognito-ignore-certificate":
                var chromeIncogAndIgnCertErrsOptions = new ChromeOptions();
                chromeIncogAndIgnCertErrsOptions.AddArguments("--incognito", "--ignore-certificate-errors");
                chromeIncogAndIgnCertErrsOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                new DriverManager().SetUpDriver(new ChromeConfig(), driverVersion);
                webDriver = runTestsRemotely ? new RemoteWebDriver(new Uri(nodeURI), chromeIncogAndIgnCertErrsOptions) : new ChromeDriver(chromeIncogAndIgnCertErrsOptions);
                break;

            case "chrome-headless":
                var chromeHeadlessOptions = new ChromeOptions();
                chromeHeadlessOptions.AddArgument("--headless");
                chromeHeadlessOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                new DriverManager().SetUpDriver(new ChromeConfig(), driverVersion);
                webDriver = runTestsRemotely ? new RemoteWebDriver(new Uri(nodeURI), chromeHeadlessOptions) : new ChromeDriver(chromeHeadlessOptions);
                break;

            case "firefox":
                var firefoxOptions = new FirefoxOptions();
                firefoxOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                new DriverManager().SetUpDriver(new FirefoxConfig(), driverVersion);
                webDriver = runTestsRemotely ? new RemoteWebDriver(new Uri(nodeURI), firefoxOptions) : new FirefoxDriver(firefoxOptions);
                break;

            case "edge":
                var edgeOptions = new EdgeOptions();
                edgeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                new DriverManager().SetUpDriver(new EdgeConfig(), driverVersion);
                webDriver = runTestsRemotely ? new RemoteWebDriver(new Uri(nodeURI), edgeOptions) : new EdgeDriver(edgeOptions);
                break;

            case "safari":
                var safariOptions = new SafariOptions();
                safariOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                webDriver = runTestsRemotely ? new RemoteWebDriver(new Uri(nodeURI), safariOptions) : new SafariDriver(safariOptions);
                break;

            default:
                throw new ApplicationException($"The functionality to run scripts for {browser} driver has not been implemented");
            }

            webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(WaitUtils.defaultImplicitWait);
            webDriver.Manage().Window.Maximize();
            return(webDriver);
        }