private static SafariOptions SafariOptions()
        {
            var options = new SafariOptions();

            options.AddAdditionalCapability("safari.options", "skipExtensionInstallation");
            return(options);
        }
Пример #2
0
        public static SafariOptions GetSafariOptions(PlatformType platformType = PlatformType.Any)
        {
            SafariOptions options = new SafariOptions();

            SetPlatform(options, platformType);
            return(options);
        }
        public void SafariSession()
        {
            var options = new SafariOptions();
            var driver  = new SafariDriver(options);

            driver.Quit();
        }
        private static object getSafariCapabilities_()
        {
            SafariOptions options     = new SafariOptions();
            ICapabilities cpabilities = options.ToCapabilities();

            return(cpabilities);
        }
Пример #5
0
        private void SetSafariOptions()
        {
            try
            {
                SafariOptions = new SafariOptions();
                SetAutomaticInspection();
                SetAutomaticProfiling();
            }
            catch (Exception ex)
            {
                switch (BaseSettings.DebugLevel)
                {
                case EnumConsoleDebugLevel.Human:
                    Console.Out.WriteLine("Could not set the safari diver options.");
                    Console.Out.WriteLine("Please investigate the changes you have made to your config file.");
                    break;

                case EnumConsoleDebugLevel.NotSpecified:
                case EnumConsoleDebugLevel.Message:
                    Console.Out.WriteLine(ex.Message);
                    break;

                case EnumConsoleDebugLevel.StackTrace:
                    Console.Out.WriteLine(ex.Message);
                    Console.Out.WriteLine(ex.StackTrace);
                    break;
                }
            }
        }
Пример #6
0
        private SafariOptions ConfigureSauceLabsRealDevice()
        {
            var options = new SafariOptions();

            options.AddAdditionalCapability(MobileCapabilityType.AppiumVersion, AppiumVersion);
            options.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS");
            options.AddAdditionalCapability(MobileCapabilityType.DeviceName, "iPad.*");
            options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, PlatformVersion);
            options.AddAdditionalCapability("testobject_api_key", RealDeviceApiKey);
            options.AddAdditionalCapability("tabletOnly", true);
            options.AddAdditionalCapability("autoGrantPermissions", true);
            options.AddAdditionalCapability(IOSMobileCapabilityType.AutoAcceptAlerts, true);
            options.AddAdditionalCapability(MobileCapabilityType.BrowserName, "Safari");
            LocalAppiumTimeout *= 9;
            options.AddAdditionalCapability("newCommandTimeout", LocalAppiumTimeout.TotalSeconds);;
            options.AddAdditionalCapability(MobileCapabilityType.NewCommandTimeout, LocalAppiumTimeout.TotalSeconds);
            options.AddAdditionalCapability(IOSMobileCapabilityType.LaunchTimeout, LocalAppiumTimeout.TotalSeconds);

            foreach (var(key, value) in SauceOptions)
            {
                options.AddAdditionalCapability(key, value);
            }

            return(options);
        }
Пример #7
0
        protected SafariOptions getSafariOptions()
        {
            var safariOptions = new SafariOptions();

            //if (!String.IsNullOrEmpty(directory))
            //    safariOptions.SafariLocation = directory;
            if (_profile != null)
            {
                throw new Exception("Profile configuration is not available for Safari driver!");
            }
            if (_preferences != null)
            {
                throw new Exception("Preference configuration is not available for Safari!");
            }
            if (_extensions != null && _extensions.Count != 0)
            {
                safariOptions.CustomExtensionPath = _extensions[0];
            }
            if (_proxy != null)
            {
                throw new Exception("Proxy configuration is not available for Safari!");
            }
            foreach (var capability in _capabilities)
            {
                safariOptions.AddAdditionalCapability(capability.Key, capability.Value);
            }
            return(safariOptions);
        }
Пример #8
0
        static IWebDriver GetDriver(Action <DriverOptions> driverOptions)
        {
            var options = new SafariOptions();

            driverOptions?.Invoke(options);
            return(new SeleniumSafariDriver(AppDomain.CurrentDomain.BaseDirectory, options));
        }
        private static ICapabilities ReturnBrowserOptions(string platformName,
                                                          string browserName,
                                                          string browserVersion)
        {
            DriverOptions browserOptions;

            switch (browserName)
            {
            case "chrome":
                browserOptions = new ChromeOptions();
                break;

            case "edge":
                browserOptions = new EdgeOptions();
                break;

            case "firefox":
                browserOptions = new FirefoxOptions();
                break;

            case "safari":
                browserOptions = new SafariOptions();
                break;

            default:
                throw new Exception($"Browser {browserName} not supported!");
            }

            browserOptions.PlatformName   = platformName;
            browserOptions.BrowserVersion = browserVersion;
            return(browserOptions.ToCapabilities());
        }
Пример #10
0
        private static SafariOptions GetSafariOptions()
        {
            var options = new SafariOptions();

            options.AddAdditionalCapability("cleanSession", true);
            return(options);
        }
Пример #11
0
        private static RemoteWebDriver StartSafariDriver(DriverSettings settings)
        {
            var options = new SafariOptions();

            settings.Capabilities?.ForEach(cap => options.AddAdditionalCapability(cap.Key, cap.Value));
            return(new SafariDriver(options));
        }
Пример #12
0
        private DriverOptions GetNativeCapabilities()
        {
            DriverOptions driverOptions = null;

            switch (mContextType)
            {
            case eContextType.NativeIOS:
            case eContextType.NativeAndroid:
                driverOptions = new AppiumOptions();
                break;

            case eContextType.WebAndroid:
                driverOptions = new ChromeOptions();
                break;

            case eContextType.WebIOS:
                driverOptions = new SafariOptions();
                break;

            default:
                break;
            }

            driverOptions.AddAdditionalCapability("user", Perfecto_User_Name);
            driverOptions.AddAdditionalCapability("password", Perfecto_Password);
            driverOptions.AddAdditionalCapability("deviceName", Perfecto_Device_ID);

            return(driverOptions);
        }
Пример #13
0
        public void TestSafari()
        {
            IWebDriver driver = null;

            try
            {
                SafariOptions options = new SafariOptions();

                driver     = new SafariDriver();
                driver.Url = "http://www.softpost.org";
                driver.Manage().Window.Maximize();
                driver.Navigate();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception ....*********" + e.ToString());
            }

            finally
            {
                Thread.Sleep(2000);
                driver.Close();
                driver.Quit();
            }
        }
Пример #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name=""></param>
 /// <returns></returns>
 public static void LoadSafariDriver(int CurrentAttempt)
 {
     if (CurrentAttempt <= BrowserRetryMax)
     {
         try
         {
             if (CurrentAttempt == 0)
             {
                 KillSafariDriver();
             }
             SafariDriverService serv = SafariDriverService.CreateDefaultService("/Applications/Safari Technology Preview.app/Contents/MacOS/", "safaridriver");
             SafariOptions       opts = new SafariOptions();
             opts.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
             opts.AddAdditionalCapability(CapabilityType.AcceptInsecureCertificates, true);
             opts.AddAdditionalCapability("cleanSession", true);
             webDriver = new SafariDriver(serv, opts);
             Test.Log.Message("Safari " + browserVersion);
         }
         catch (Exception ex)
         {
             Test.Log.Message("Error Safari driver failed to load: " + ex.Message);
             LoadSafariDriver(CurrentAttempt++);
         }
     }
 }
Пример #15
0
 public void WithSafari()
 {
     ConfiguredSafariOptions = new SafariOptions
     {
         BrowserVersion = DefaultBrowserVersion,
         PlatformName   = Platforms.MacOsMojave.Value
     };
 }
Пример #16
0
        public SafariOptions GetOptions(SafariConfiguration configuration)
        {
            var options = new SafariOptions();

            configuration.SetAdditionalCapability(options);

            return(options);
        }
        public void AcceptsSafariOptionsClass()
        {
            var options = new SafariOptions();

            SauceOptions = new SauceOptions(options);

            SauceOptions.BrowserName.Should().BeEquivalentTo(Browser.Safari);
            SauceOptions.SeleniumOptions.Should().BeEquivalentTo(options);
        }
Пример #18
0
        private void SetupRemoteWebDriver()
        {
            NameValueCollection driverCapabilitiesConf = new NameValueCollection();
            NameValueCollection settings = new NameValueCollection();

#if net47 || net45
            driverCapabilitiesConf = ConfigurationManager.GetSection("DriverCapabilities") as NameValueCollection;
            settings = ConfigurationManager.GetSection("environments/" + this.CrossBrowserEnvironment) as NameValueCollection;
#endif
#if netcoreapp3_1
            driverCapabilitiesConf = BaseConfiguration.GetNameValueCollectionFromAppsettings("DriverCapabilities");
            settings = BaseConfiguration.GetNameValueCollectionFromAppsettings("environments:" + this.CrossBrowserEnvironment);
#endif
            var browserType = this.GetBrowserTypeForRemoteDriver(settings);
            switch (browserType)
            {
            case BrowserType.Firefox:
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.Proxy = this.CurrentProxy();
                this.SetRemoteDriverBrowserOptions(driverCapabilitiesConf, settings, firefoxOptions);
                this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetDriverOptions(firefoxOptions).ToCapabilities());
                break;

            case BrowserType.Android:
            case BrowserType.Chrome:
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.Proxy = this.CurrentProxy();
                this.SetRemoteDriverBrowserOptions(driverCapabilitiesConf, settings, chromeOptions);
                this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetDriverOptions(chromeOptions).ToCapabilities());
                break;

            case BrowserType.Iphone:
            case BrowserType.Safari:
                SafariOptions safariOptions = new SafariOptions();
                this.SetRemoteDriverOptions(driverCapabilitiesConf, settings, safariOptions);
                this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetDriverOptions(safariOptions).ToCapabilities());
                break;

            case BrowserType.Edge:
                EdgeOptions egEdgeOptions = new EdgeOptions();
                this.SetRemoteDriverOptions(driverCapabilitiesConf, settings, egEdgeOptions);
                this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetDriverOptions(egEdgeOptions).ToCapabilities());
                break;

            case BrowserType.IE:
            case BrowserType.InternetExplorer:
                InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
                internetExplorerOptions.Proxy = this.CurrentProxy();
                this.SetRemoteDriverBrowserOptions(driverCapabilitiesConf, settings, internetExplorerOptions);
                this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetDriverOptions(internetExplorerOptions).ToCapabilities());
                break;

            default:
                throw new NotSupportedException(
                          string.Format(CultureInfo.CurrentCulture, "Driver {0} is not supported", this.CrossBrowserEnvironment));
            }
        }
Пример #19
0
        private static DriverOptions GetiOSSafariOptions()
        {
            SafariOptions options = new SafariOptions();

            options.AddAdditionalCapability("deviceName", "iPhone X Simulator");
            options.AddAdditionalCapability("platformVersion", "11.2");
            options.PlatformName = "iOS";
            return(options);
        }
Пример #20
0
 public void WithSafari(string safariVersion)
 {
     ConfiguredSafariOptions = new SafariOptions
     {
         BrowserVersion = safariVersion,
         //TODO temporarily fine, but I need the logic to determine what
         //version is running and then set the correct PlatformName
         PlatformName = SetCorrectPlatformVersion(safariVersion)
     };
 }
Пример #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SafariDriver"/> class.
 /// </summary>
 /// <param name="remoteAddress">The base address for the Agent API (e.g. http://localhost:8585).</param>
 /// <param name="token">The development token used to communicate with the Agent, see <a href="https://app.testproject.io/#/integrations/sdk">here</a> for more info.</param>
 /// <param name="safariOptions">See <see cref="SafariOptions"/> for more details.</param>
 /// <param name="projectName">The project name to report.</param>
 /// <param name="jobName">The job name to report.</param>
 /// <param name="disableReports">Set to true to disable all reporting (no report will be created on TestProject).</param>
 public SafariDriver(
     Uri remoteAddress           = null,
     string token                = null,
     SafariOptions safariOptions = null,
     string projectName          = null,
     string jobName              = null,
     bool disableReports         = false)
     : base(remoteAddress, token, DriverOptionsHelper.Patch(safariOptions, BrowserType.Safari), projectName, jobName, disableReports)
 {
 }
Пример #22
0
        private IWebDriver CreateSafariDriver()
        {
            var options = new SafariOptions();

            Driver = new SafariDriver(options);
            SetBrowserSize(Driver);
            Driver.VaftExt().TurnOnImplicitlyWait();
            Driver.VaftExt().SetPageLoadTimeout();
            return(Driver);
        }
Пример #23
0
        private SafariOptions GetSafariDriverOptions()
        {
            SafariOptions options = new SafariOptions();

            foreach (KeyValuePair <string, object> keyValuePair in _config.AdditionalCapability)
            {
                options.AddAdditionalCapability(keyValuePair.Key, keyValuePair.Value);
            }
            return(options);
        }
Пример #24
0
        public static IWebDriver CreateSauceDriver(SauceConfigurations sauceConfigurations)
        {
            var sauceOptions = new Dictionary <string, object>
            {
                { "screenResolution", sauceConfigurations.ScreenResolution },
                { "username", SauceUserName },
                { "accessKey", SauceAccessKey },
                { "deviceName", sauceConfigurations.DeviceName },
                { "deviceOrientation", sauceConfigurations.DeviceOrientation },
                { "name", TestContext.CurrentContext.Test.Name }
            };

            switch (sauceConfigurations.Browser)
            {
            case Browser.Chrome:
                var chromeOptions = new ChromeOptions
                {
                    UseSpecCompliantProtocol = true,
                    PlatformName             = sauceConfigurations.Os,
                    BrowserVersion           = sauceConfigurations.Version
                };
                chromeOptions.AddAdditionalCapability("sauce:options", sauceOptions, true);
                return(new RemoteWebDriver(new Uri(SauceRemoteAddress), chromeOptions));

            case Browser.Firefox:
                var firefoxOptions = new FirefoxOptions
                {
                    PlatformName   = sauceConfigurations.Os,
                    BrowserVersion = sauceConfigurations.Version
                };
                firefoxOptions.AddAdditionalCapability("sauce:options", sauceOptions, true);
                return(new RemoteWebDriver(new Uri(SauceRemoteAddress), firefoxOptions));

            case Browser.Safari:
                var safariOptions = new SafariOptions
                {
                    PlatformName   = sauceConfigurations.Os,
                    BrowserVersion = sauceConfigurations.Version
                };
                safariOptions.AddAdditionalCapability("sauce:options", sauceOptions);
                return(new RemoteWebDriver(new Uri(SauceRemoteAddress), safariOptions));

            case Browser.Edge:
                var edgeOptions = new EdgeOptions
                {
                    PlatformName   = sauceConfigurations.Os,
                    BrowserVersion = sauceConfigurations.Version
                };
                edgeOptions.AddAdditionalCapability("sauce:options", sauceOptions);
                return(new RemoteWebDriver(new Uri(SauceRemoteAddress), edgeOptions));

            default:
                throw new ArgumentException("Invalid browser");
            }
        }
 /// <summary>
 /// Returns an initialised Safari Web Driver.
 /// </summary>
 /// <remarks>You need to have Safari installed on the machine running the test</remarks>
 /// <param name="options">Profile to use for the driver</param>
 /// <returns>Initialised Safari driver</returns>
 public static SafariDriver Safari(SafariOptions options)
 {
     try
     {
         return(new SafariDriver(options));
     }
     catch (Win32Exception e)
     {
         throw new BrowserNotFoundException("Safari", e);
     }
 }
Пример #26
0
        public void ShouldOpenOnSafari()
        {
            // Set your sauce user name and access key from environment variables
            var sauceUserName  = Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User);
            var sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY", EnvironmentVariableTarget.User);

            //configure sauce labs options
            var sauceOptions = new Dictionary <string, object>
            {
                ["username"]  = sauceUserName,
                ["accessKey"] = sauceAccessKey,
                ["name"]      = MethodBase.GetCurrentMethod().Name
            };

            //configure the browser options
            var safariOptions = new SafariOptions
            {
                BrowserVersion = "latest",
                PlatformName   = "macOS 10.15",
                //AcceptInsecureCertificates = true Don't use this as Safari doesn't support Insecure certs
            };

            //merge sauce options with browser options
            safariOptions.AddAdditionalCapability("sauce:options", sauceOptions);

            //It's not a good idea to set this value too high because if something goes wrong,
            // the test will just hang for this amount of time. 60 sec is plenty
            var connectionTimeout = TimeSpan.FromSeconds(60);

            _driver = new RemoteWebDriver(new Uri("https://ondemand.saucelabs.com/wd/hub"),
                                          safariOptions.ToCapabilities(), connectionTimeout);

            //navigate to the url of the Sauce Labs Sample app
            _driver.Navigate().GoToUrl("https://www.saucedemo.com");

            //Create an instance of a Selenium explicit wait so that we can dynamically wait for an element
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
            //wait for the user name field to be visible and store that element into a variable
            var userNameField = wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("[type='text']")));

            //type the user name string into the user name field
            userNameField.SendKeys("standard_user");
            //type the password into the password field
            _driver.FindElement(By.CssSelector("[type='password']")).SendKeys("secret_sauce");
            //hit Login button
            _driver.FindElement(By.CssSelector("[type='submit']")).Click();

            //Synchronize on the next page and make sure it loads
            var inventoryPageLocator =
                wait.Until(ExpectedConditions.ElementIsVisible(By.Id("inventory_container")));

            //Assert that the inventory page displayed appropriately
            Assert.IsTrue(inventoryPageLocator.Displayed);
        }
        private void setDriverOptions(ref SafariOptions driverOptions, string PlatformName, string BrowserVersion)
        {
            var sauceOptions = new Dictionary <string, object>();

            sauceOptions.Add("username", SAUCE_USERNAME);
            sauceOptions.Add("accesskey", SAUCE_ACCESS_KEY);
            driverOptions.PlatformName   = PlatformName;
            driverOptions.BrowserVersion = BrowserVersion;
            driverOptions.AddAdditionalCapability("username", SAUCE_USERNAME);
            driverOptions.AddAdditionalCapability("accesskey", SAUCE_ACCESS_KEY);
        }
Пример #28
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;
            }
        }
Пример #29
0
        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));
        }
Пример #30
0
        /// <summary>
        /// Get the remote driver options
        /// </summary>
        /// <param name="remoteBrowser">The remote browser type</param>
        /// <param name="remotePlatform">The remote platform</param>
        /// <param name="remoteBrowserVersion">The remote browser version</param>
        /// <param name="remoteCapabilities">Additional remote capabilities</param>
        /// <returns>The remote driver options</returns>
        public static DriverOptions GetRemoteOptions(RemoteBrowserType remoteBrowser, string remotePlatform, string remoteBrowserVersion, Dictionary <string, object> remoteCapabilities)
        {
            DriverOptions options = null;

            switch (remoteBrowser)
            {
            case RemoteBrowserType.IE:
                options = new InternetExplorerOptions();
                break;

            case RemoteBrowserType.Firefox:
                options = new FirefoxOptions();
                break;

            case RemoteBrowserType.Chrome:
                options = new ChromeOptions();
                break;

            case RemoteBrowserType.Edge:
                options = new EdgeOptions();
                break;

            case RemoteBrowserType.Safari:
                options = new SafariOptions();
                break;

            default:
                throw new ArgumentException(StringProcessor.SafeFormatter("Remote browser type '{0}' is not supported", remoteBrowser));
            }

            // Make sure the remote capabilities dictonary exists
            if (remoteCapabilities == null)
            {
                remoteCapabilities = new Dictionary <string, object>();
            }

            // Add a platform setting if one was provided
            if (!string.IsNullOrEmpty(remotePlatform) && !remoteCapabilities.ContainsKey("platform"))
            {
                remoteCapabilities.Add("platform", remotePlatform);
            }

            // Add a remote browser setting if one was provided
            if (!string.IsNullOrEmpty(remoteBrowserVersion) && !remoteCapabilities.ContainsKey("version"))
            {
                remoteCapabilities.Add("version", remoteBrowserVersion);
            }

            // Add additional capabilities to the driver options
            options.SetDriverOptions(remoteCapabilities);

            return(options);
        }