public void Patch_WithNullOptions_ShouldReturnCorrectDriverOptionsType(BrowserType browserType, Type expectedType)
        {
            OpenQA.Selenium.DriverOptions options = DriverOptionsHelper.Patch(null, browserType);

            Assert.IsTrue(options.GetType().Equals(expectedType));
            Assert.AreEqual(options.PageLoadStrategy, OpenQA.Selenium.PageLoadStrategy.Normal);
            Assert.AreEqual(options.UnhandledPromptBehavior, OpenQA.Selenium.UnhandledPromptBehavior.DismissAndNotify);
        }
        public void Patch_WithUnhandledPromptBehaviorDefault_ShouldReturnWithUnhandledPromptBehaviorDismissAndNotify()
        {
            OpenQA.Selenium.Chrome.ChromeOptions originalOptions = new OpenQA.Selenium.Chrome.ChromeOptions();
            originalOptions.PageLoadStrategy = OpenQA.Selenium.PageLoadStrategy.Normal;

            OpenQA.Selenium.DriverOptions patchedOptions = DriverOptionsHelper.Patch(originalOptions, BrowserType.Chrome);

            Assert.AreEqual(OpenQA.Selenium.UnhandledPromptBehavior.DismissAndNotify, patchedOptions.UnhandledPromptBehavior);
        }
        public void Patch_WithExistingOptions_ShouldReturnUnchangedOptions()
        {
            OpenQA.Selenium.Chrome.ChromeOptions originalOptions = new OpenQA.Selenium.Chrome.ChromeOptions();
            originalOptions.PageLoadStrategy        = OpenQA.Selenium.PageLoadStrategy.Eager;
            originalOptions.UnhandledPromptBehavior = OpenQA.Selenium.UnhandledPromptBehavior.AcceptAndNotify;

            OpenQA.Selenium.DriverOptions patchedOptions = DriverOptionsHelper.Patch(originalOptions, BrowserType.Chrome);

            Assert.AreEqual(originalOptions, patchedOptions);
        }
Example #4
0
        /// <summary>
        /// Patches <see cref="DriverOptions"/> objects make them suitable to start a session with the Agent.
        /// </summary>
        /// <param name="originalOptions">The original <see cref="DriverOptions"/> as specified by the user.</param>
        /// <param name="browserType">The type of browser in use (required to return the right type of options).</param>
        /// <returns>A patched <see cref="DriverOptions"/> object suitable to start a session with the Agent.</returns>
        public static OpenQA.Selenium.DriverOptions Patch(OpenQA.Selenium.DriverOptions originalOptions, BrowserType browserType)
        {
            if (originalOptions == null)
            {
                return(CreateDefaultOptionsFor(browserType));
            }

            // Patch PageLoadStrategy if necessary, the Agent does not understand the 'Default' value
            if (originalOptions.PageLoadStrategy.Equals(OpenQA.Selenium.PageLoadStrategy.Default))
            {
                originalOptions.PageLoadStrategy = OpenQA.Selenium.PageLoadStrategy.Normal;
            }

            // Patch UnhandledPromptBehavior if necessary, the Agent does not understand the 'Default' value
            if (originalOptions.UnhandledPromptBehavior.Equals(OpenQA.Selenium.UnhandledPromptBehavior.Default))
            {
                originalOptions.UnhandledPromptBehavior = OpenQA.Selenium.UnhandledPromptBehavior.DismissAndNotify;
            }

            return(originalOptions);
        }