Exemple #1
0
        public void Remote_WithOptions()
        {
            var context = RemoteDriverAtataContextBuilderOverride.Context;

            using (context.UseNullDriver())
            {
                AtataContextBuilder builder = AtataContext.Configure().
                                              ApplyJsonConfig(@"Configs/RemoteChrome.json");

                builder.BuildingContext.DriverFactoryToUse.Create();
            }

            ICapabilities capabilities = context.Capabilities;

            capabilities.GetCapability(CapabilityType.BrowserName).Should().Be(DriverAliases.Chrome);

            var chromeCapabilities = (Dictionary <string, object>)capabilities.GetCapability(ChromeOptions.Capability);

            chromeCapabilities.Should().Equal(new Dictionary <string, object>
            {
                ["detach"] = true,
                ["cap1"]   = true,
                ["cap2"]   = 5,
                ["cap3"]   = "str"
            });
        }
Exemple #2
0
//        protected PaidHub(Uri remoteAddress, ICapabilities capabilities) : base(remoteAddress, capabilities)
//        {
//        }

        protected PaidHub(string hubUrl, string keyText, string secretText, ICapabilities capabilities) : base(
                new Uri(hubUrl), capabilities)
        {
            //ToDo auth from App.Config
            Api = new PaidHubApi(capabilities.GetCapability(keyText).ToString(),
                                 capabilities.GetCapability(secretText).ToString(), RestApiUri, SessionId.ToString(), HubType);
        }
Exemple #3
0
 private static FirefoxBinary ExtractBinary(ICapabilities capabilities)
 {
     if (capabilities.GetCapability(BinaryCapabilityName) != null)
     {
         return new FirefoxBinary(capabilities.GetCapability(BinaryCapabilityName).ToString());
     }
     return new FirefoxBinary();
 }
Exemple #4
0
 private static FirefoxBinary ExtractBinary(ICapabilities capabilities)
 {
     if (capabilities.GetCapability(FirefoxDriver.BinaryCapabilityName) != null)
     {
         string pathToFirefoxBinary = capabilities.GetCapability(FirefoxDriver.BinaryCapabilityName).ToString();
         return(new FirefoxBinary(pathToFirefoxBinary));
     }
     return(new FirefoxBinary());
 }
        public void MiscellaneousSession_GetSessionCapabilities()
        {
            session = Utility.CreateNewSession(CommonTestSettings.AlarmClockAppId);
            Assert.IsNotNull(session.SessionId);

            ICapabilities capabilities = session.Capabilities;

            Assert.AreEqual(CommonTestSettings.AlarmClockAppId, capabilities.GetCapability("app"));
            Assert.AreEqual("Windows", capabilities.GetCapability("platformName"));
        }
        public void CreateLocalAndroidDriver()
        {
            driverConfig = new LocalDriverConfig
            {
                PlatformName      = MobilePlatform.Android,
                PlatformVersion   = "8",
                BrowserName       = MobileBrowserType.Chrome,
                DeviceName        = "device name",
                ServerUrl         = serverUrl,
                NewCommandTimeout = 90001,
                ImplicitWait      = 90002,
                PageLoad          = 90003
            };
            var testSettings = new TestSettingsConfig();

            testSettings.LocalDriver = driverConfig;

            var webTestContext = new WebTestContext(mockDriverFactory.Object, testSettings);

            webTestContext.StartDriver();
            mockDriverFactory.Verify(IDriverFactory => IDriverFactory.Create(It.IsAny <Uri>(), It.IsAny <DriverOptions>(), It.IsAny <TimeSpan>(), It.IsAny <Action <IWebDriver> >()), Times.Once);
            Assert.AreEqual(driverConfig.BrowserName, receivedCapabilities.GetCapability(MobileCapabilityType.BrowserName), "BrowserName is not equal");
            Assert.AreEqual(driverConfig.PlatformVersion, receivedCapabilities.GetCapability(MobileCapabilityType.PlatformVersion), "PlatformVersion is not equal");
            Assert.AreEqual(driverConfig.PlatformName, receivedCapabilities.GetCapability(MobileCapabilityType.PlatformName), "PlatformVersion is not equal");
            Assert.AreEqual(driverConfig.DeviceName, receivedCapabilities.GetCapability(MobileCapabilityType.DeviceName), "DeviceName is not equal");
            Assert.AreEqual(ProviderType.Default, webTestContext.ProviderType);
        }
Exemple #7
0
        /// <summary>
        /// 選擇初始化之瀏覽器
        /// </summary>
        /// <param name="browser"></param>
        public BrowserHelper(string browser)
        {
            js   = (IJavaScriptExecutor)driver;
            vars = new Dictionary <string, object>();

            switch (browser)
            {
            case "Chrome":
                driver         = new ChromeDriver();
                capabilities   = ((RemoteWebDriver)driver).Capabilities;
                browserVersion = capabilities.GetCapability("browserVersion").ToString();
                browserName    = "Chrome";
                break;

            case "Firefox":
                driver         = new FirefoxDriver();
                capabilities   = ((RemoteWebDriver)driver).Capabilities;
                browserVersion = capabilities.GetCapability("browserVersion").ToString();
                browserName    = "Firefox";
                break;

            case "IE":
                driver      = new InternetExplorerDriver();
                browserName = "IE";
                break;
            }
        }
Exemple #8
0
        /// <summary>
        /// The create local driver.
        /// </summary>
        /// <param name="capabilities">
        /// The capabilities.
        /// </param>
        /// <returns>
        /// The <see cref="IWebDriver"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        private static IWebDriver CreateLocalDriver(ICapabilities capabilities)
        {
            // Implementation is incomplete: the capabilities are not converted to the options for all browsers
            string browserType = (string)capabilities.GetCapability("BrowserName");

            if (browserType == new FirefoxOptions().BrowserName)
            {
                var options = new FirefoxOptions();
                return(new FirefoxDriver(options));
            }

            if (browserType == new InternetExplorerOptions().BrowserName)
            {
                return(new InternetExplorerDriver());
            }

            if (browserType == new ChromeOptions().BrowserName)
            {
                return(new ChromeDriver());
            }

            if (browserType == new SafariOptions().BrowserName)
            {
                return(new SafariDriver());
            }

            if (browserType == new EdgeOptions().BrowserName)
            {
                var options = new EdgeOptions();
                options.AddAdditionalCapability("timeZone", "Europe/London");
                return(new EdgeDriver(options));
            }

            throw new Exception("Unrecognized browser type: " + browserType);
        }
Exemple #9
0
        public void CloseBrowser()
        {
            try
            {
                ICapabilities capabilities = ((RemoteWebDriver)Browser.CurrentBrowser).Capabilities;
                var           version      = capabilities.GetCapability("version");
                var           path         = Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents");
                System.IO.File.WriteAllText(path + "\\" + "seleniumVersion.txt", version.ToString());

                Browser.CurrentBrowser.Quit();
                Browser.CurrentBrowser.Close();
            }
            catch (Exception e)
            {
            }


            Process[] processes = Process.GetProcesses();

            foreach (Process process in processes)
            {
                if (process.ProcessName.Contains("chromedriver") || process.ProcessName.Contains("chrome"))
                {
                    try
                    {
                        process.Kill();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Exemple #10
0
        /// <summary>
        ///     Returns a normalized screenshot
        ///        - Resize image if the device pixel ratio is above 1
        ///        - Returns only the viewport of the browser. (E.g. in iPhone app and nav bar is removed)
        /// </summary>
        /// <param name="driver">This IWebDriver to extend</param>
        public static Bitmap GetNormalizedScreenshot(IWebDriver driver)
        {
            ICapabilities capabilities = ((RemoteWebDriver)driver).Capabilities;

            var yOffsetValue = (string)capabilities.GetCapability("sl_yOffset");
            var yOffset      = Convert.ToInt32(yOffsetValue);

            Screenshot sc  = ((ITakesScreenshot)driver).GetScreenshot();
            var        img = Image.FromStream(new MemoryStream(sc.AsByteArray)) as Bitmap;

            var executor         = (IJavaScriptExecutor)driver;
            var devicePixelRatio = Convert.ToDouble(executor.ExecuteScript("return window.devicePixelRatio || 1"));

            // Resize image if devicePixelRatio is not 1
            if (Math.Abs(devicePixelRatio - 1) > 0.0000001)
            {
                var newWidth  = Convert.ToInt32(Math.Round(img.Width / devicePixelRatio));
                var newHeight = Convert.ToInt32(Math.Round(img.Height / devicePixelRatio));

                img = new Bitmap(img, newWidth, newHeight);
            }

            var height = Convert.ToInt32(executor.ExecuteScript("return window.innerHeight;"));

            if (height > img.Height)
            {
                height = img.Height;
            }

            Bitmap retImg = img.Clone(new Rectangle(0, yOffset, img.Width, height), img.PixelFormat);

            return(retImg);
        }
        public void TestMethod()
        {
            if (browserType.Contains("chrome"))
            {
                driver = new ChromeDriver();
            }
            else if (browserType.Contains("firefox"))
            {
                driver = new FirefoxDriver();
            }
            else if (browserType.Contains("edge"))
            {
                driver = new EdgeDriver();
            }

            //To define driver properties
            browserCap  = ((RemoteWebDriver)driver).Capabilities;
            browserName = browserCap.GetCapability("browserName").ToString();
            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            driver.Manage().Cookies.DeleteAllCookies();

            driver.Url = "http://google.com";
            Thread.Sleep(3000);
            driver.Quit();
        }
Exemple #12
0
 public static T GetCapabilityAs <T>(this ICapabilities capabilities, string key) where T : class
 {
     if (capabilities == null)
     {
         return(default(T));
     }
     return(capabilities.GetCapability(key) as T);
 }
Exemple #13
0
        public String getEnvironmentInfo()
        {
            ICapabilities cap = ((IHasCapabilities)this.driver).Capabilities;

            String os;
            String browserName;
            String version;


            // check for platform
            if (cap.HasCapability("platformName"))
            {
                os = cap.GetCapability("platformName").ToString().ToLower();
            }
            else if (cap.HasCapability("platform"))
            {
                os = cap.GetCapability("platform").ToString().ToLower();
            }
            else if (cap.HasCapability("os"))
            {
                os = cap.GetCapability("os").ToString().ToLower();
            }
            else
            {
                os = "unknownPlatform";
            }


            // check for browser name
            if (cap.HasCapability("browserName"))
            {
                browserName = cap.GetCapability("browserName").ToString().ToLower();
            }
            if (cap.HasCapability("browser"))
            {
                browserName = cap.GetCapability("browser").ToString().ToLower();
            }
            else
            {
                browserName = "unknownBrowser";
            }


            // check for browser version
            if (cap.HasCapability("browserVersion"))
            {
                version = cap.GetCapability("browserVersion").ToString().ToLower();
            }
            else if (cap.HasCapability("version"))
            {
                version = cap.GetCapability("version").ToString().ToLower();
            }
            else
            {
                version = "unknownVersion";
            }


            return(String.Format("selenium-csharp; %s; %s/%s", os, browserName, version));
        }
        private static string GetSaveCapability(ICapabilities capabilities, string browsername)
        {
            if (capabilities.HasCapability(browsername))
            {
                return(capabilities.GetCapability(browsername)?.ToString() ?? string.Empty);
            }

            return(string.Empty);
        }
Exemple #15
0
 private static string getOs(ICapabilities capabilities, string systemOs)
 {
     if (capabilities != null)
     {
         string platformNameCapability = getPropertyValue(OPT_CAPABILITIES_PLATFORM_NAME, "platformName");
         if (capabilities.HasCapability(platformNameCapability))
         {
             string platformName = capabilities.GetCapability(platformNameCapability).ToString();
             string platformVersionCapability = getPropertyValue(OPT_CAPABILITIES_PLATFORM_VERSION, "platformVersion");
             if (capabilities.HasCapability(platformVersionCapability))
             {
                 return(platformName + " " + capabilities.GetCapability(platformVersionCapability).ToString());
             }
             return(platformName);
         }
     }
     return(systemOs);
 }
Exemple #16
0
 private static string getSoftware(ICapabilities capabilities, string driverType)
 {
     if (capabilities != null)
     {
         string browserNameCapability = getPropertyValue(OPT_CAPABILITIES_BROWSER_NAME, "browserName");
         if (capabilities.HasCapability(browserNameCapability))
         {
             string browserName = capabilities.GetCapability(browserNameCapability).ToString();
             string browserVersionCapability = getPropertyValue(OPT_CAPABILITIES_BROWSER_VERSION, "browserVersion");
             if (capabilities.HasCapability(browserVersionCapability))
             {
                 return(browserName + " " + capabilities.GetCapability(browserVersionCapability).ToString());
             }
             return(browserName);
         }
     }
     return("");
 }
        private static void ValidateChromeCapabilities(ICapabilities cap, string optionToCheck)
        {
            Assert.AreEqual(@"chrome", cap.GetCapability(CapabilityType.BrowserName));
            var argList = GetArgList(cap, @"goog:chromeOptions") as IReadOnlyCollection <object>;

            Assert.IsNotNull(argList, "argList cannot be mapped to IReadOnlyCollection ");
            Assert.IsTrue(argList.Count >= 1, "arg count ok");
            Assert.IsTrue(argList.Contains(optionToCheck), "option present");
        }
        private static object GetArgList(ICapabilities cap, string keyName)
        {
            var options = cap.GetCapability(keyName) as Dictionary <string, object>;

            Assert.IsNotNull(options);
            var argList = options.Values.ToList()[0];

            Assert.IsNotNull(argList, "ArgList is empty");
            return(argList);
        }
        private static void ValidateFirefoxCapabilities(ICapabilities cap)
        {
            Assert.AreEqual("firefox", cap.GetCapability(CapabilityType.BrowserName));
            var argList = GetArgList(cap, "moz:firefoxOptions") as Dictionary <string, object>;

            Assert.IsNotNull(argList, "ArgList cannot be mapped to Dictionary");
            Assert.IsTrue(argList.Count >= 4, "ff arg count ok");
            Assert.IsTrue(argList.ContainsKey(@"plugin.state.npctrl"), "ff silverlight enabled");
            Assert.IsTrue(argList.ContainsKey(@"network.negotiate-auth.trusted-uris"), "ff integrated authentication enabled");
        }
Exemple #20
0
 private static string getLocation(ICapabilities capabilities)
 {
     if (capabilities != null)
     {
         string capabilityName = getPropertyValue(OPT_CAPABILITIES_LOCATION, "location");
         if (capabilities.HasCapability(capabilityName))
         {
             return(capabilities.GetCapability(capabilityName).ToString());
         }
     }
     return("");
 }
Exemple #21
0
 private static string getHardware(ICapabilities capabilities)
 {
     if (capabilities != null)
     {
         string capabilityName = getPropertyValue(OPT_CAPABILITIES_DEVICE_NAME, "deviceName");
         if (capabilities.HasCapability(capabilityName))
         {
             return(capabilities.GetCapability(capabilityName).ToString());
         }
     }
     return("");
 }
        public void Test1()
        {
            string        browsername  = "";
            string        name         = Driver.GetType().FullName;
            ICapabilities capabilities = ((RemoteWebDriver)Driver.WrappedDriver).Capabilities;
            string        browserName  = string.Empty;

            if (capabilities.HasCapability("browserName"))
            {
                browserName = capabilities.GetCapability("browserName").ToString();
            }
            Driver.Manage().Window.Maximize();
            Assert.Pass();
        }
Exemple #23
0
        public void Remote_WithoutType()
        {
            var context = RemoteDriverAtataContextBuilderOverride.Context;

            using (context.UseNullDriver())
            {
                AtataContextBuilder builder = AtataContext.Configure().
                                              ApplyJsonConfig(@"Configs/RemoteFirefox.json");

                builder.BuildingContext.DriverFactoryToUse.Create();
            }

            ICapabilities capabilities = context.Capabilities;

            capabilities.GetCapability(CapabilityType.BrowserName).Should().Be(DriverAliases.Firefox);
        }
        public void TestMethod()
        {
            if (browserType.Contains("chrome"))
            {
                //Headless browser will execute script without GUI interference
                if (headlessBrowser.Equals("true"))
                {
                    ChromeOptions options = new ChromeOptions();
                    options.AddArguments("--headless", "--disable-gpu");
                    driver = new ChromeDriver(options);
                }
                else
                {
                    driver = new ChromeDriver();
                }
            }
            else if (browserType.Contains("firefox"))
            {
                //System.Environment(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
                if (headlessBrowser.Equals("true"))
                {
                    FirefoxOptions options = new FirefoxOptions();
                    options.AddArguments("--headless", "--disable-gpu");
                    driver = new FirefoxDriver(options);
                }
                else
                {
                    driver = new FirefoxDriver();
                }
            }
            else if (browserType.Contains("edge"))
            {
                driver = new EdgeDriver();
            }

            //To define driver properties
            browserCap  = ((RemoteWebDriver)driver).Capabilities;
            browserName = browserCap.GetCapability("browserName").ToString();
            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            driver.Manage().Cookies.DeleteAllCookies();

            driver.Url = "http://google.com";
            Thread.Sleep(3000);
            driver.Quit();
        }
Exemple #25
0
        private static FirefoxProfile ExtractProfile(ICapabilities capabilities)
        {
            FirefoxProfile profile = new FirefoxProfile();

            if (capabilities.GetCapability(ProfileCapabilityName) != null)
            {
                object         raw          = capabilities.GetCapability(ProfileCapabilityName);
                FirefoxProfile rawAsProfile = raw as FirefoxProfile;
                string         rawAsString  = raw as string;
                if (rawAsProfile != null)
                {
                    profile = rawAsProfile;
                }
                else if (rawAsString != null)
                {
                    try
                    {
                        profile = FirefoxProfile.FromBase64String(rawAsString);
                    }
                    catch (IOException e)
                    {
                        throw new WebDriverException("Unable to create profile from specified string", e);
                    }
                }
            }

            if (capabilities.GetCapability(CapabilityType.Proxy) != null)
            {
                Proxy  proxy      = null;
                object raw        = capabilities.GetCapability(CapabilityType.Proxy);
                Proxy  rawAsProxy = raw as Proxy;
                Dictionary <string, object> rawAsMap = raw as Dictionary <string, object>;
                if (rawAsProxy != null)
                {
                    proxy = rawAsProxy;
                }
                else if (rawAsMap != null)
                {
                    proxy = new Proxy(rawAsMap);
                }

                profile.SetProxyPreferences(proxy);
            }

            if (capabilities.GetCapability(CapabilityType.AcceptSslCertificates) != null)
            {
                bool acceptCerts = (bool)capabilities.GetCapability(CapabilityType.AcceptSslCertificates);
                profile.AcceptUntrustedCertificates = acceptCerts;
            }

            return(profile);
        }
    private List <string> GetFirefoxArguments(FirefoxOptions firefoxOptions)
    {
        List <string> argumentStringsList = new List <string>();
        ICapabilities capabilities        = firefoxOptions?.ToCapabilities();

        if (capabilities != null && capabilities.HasCapability("moz:firefoxOptions"))
        {
            Dictionary <string, object> dictionaryOfOptions = capabilities.GetCapability("moz:firefoxOptions") as Dictionary <string, object>;
            object argumentObject = null;
            dictionaryOfOptions?.TryGetValue("args", out argumentObject);
            List <object> arguments = argumentObject as List <object>;
            if (arguments != null)
            {
                argumentStringsList = arguments?.Select(obj => obj as string).ToList();
            }
        }

        return(argumentStringsList);
    }
Exemple #27
0
        private static FirefoxProfile ExtractProfile(ICapabilities capabilities)
        {
            FirefoxProfile firefoxProfile = new FirefoxProfile();

            if (capabilities.GetCapability(FirefoxDriver.ProfileCapabilityName) != null)
            {
                object         capability      = capabilities.GetCapability(FirefoxDriver.ProfileCapabilityName);
                FirefoxProfile firefoxProfile2 = capability as FirefoxProfile;
                string         text            = capability as string;
                if (firefoxProfile2 != null)
                {
                    firefoxProfile = firefoxProfile2;
                }
                else if (text != null)
                {
                    try
                    {
                        firefoxProfile = FirefoxProfile.FromBase64String(text);
                    }
                    catch (IOException innerException)
                    {
                        throw new WebDriverException("Unable to create profile from specified string", innerException);
                    }
                }
            }
            if (capabilities.GetCapability(CapabilityType.Proxy) != null)
            {
                Proxy  proxyPreferences = null;
                object capability2      = capabilities.GetCapability(CapabilityType.Proxy);
                Proxy  proxy            = capability2 as Proxy;
                Dictionary <string, object> dictionary = capability2 as Dictionary <string, object>;
                if (proxy != null)
                {
                    proxyPreferences = proxy;
                }
                else if (dictionary != null)
                {
                    proxyPreferences = new Proxy(dictionary);
                }
                firefoxProfile.SetProxyPreferences(proxyPreferences);
            }
            if (capabilities.GetCapability(CapabilityType.AcceptSslCertificates) != null)
            {
                bool acceptUntrustedCertificates = (bool)capabilities.GetCapability(CapabilityType.AcceptSslCertificates);
                firefoxProfile.AcceptUntrustedCertificates = acceptUntrustedCertificates;
            }
            return(firefoxProfile);
        }
Exemple #28
0
 private static FirefoxProfile ExtractProfile(ICapabilities capabilities)
 {
     FirefoxProfile profile = new FirefoxProfile();
     if (capabilities.GetCapability(ProfileCapabilityName) != null)
     {
         object capability = capabilities.GetCapability(ProfileCapabilityName);
         FirefoxProfile profile2 = capability as FirefoxProfile;
         string str = capability as string;
         if (profile2 != null)
         {
             profile = profile2;
         }
         else if (str != null)
         {
             try
             {
                 profile = FirefoxProfile.FromBase64String(str);
             }
             catch (IOException exception)
             {
                 throw new WebDriverException("Unable to create profile from specified string", exception);
             }
         }
     }
     if (capabilities.GetCapability(CapabilityType.Proxy) != null)
     {
         Proxy proxy = null;
         object obj2 = capabilities.GetCapability(CapabilityType.Proxy);
         Proxy proxy2 = obj2 as Proxy;
         Dictionary<string, object> settings = obj2 as Dictionary<string, object>;
         if (proxy2 != null)
         {
             proxy = proxy2;
         }
         else if (settings != null)
         {
             proxy = new Proxy(settings);
         }
         profile.SetProxyPreferences(proxy);
     }
     if (capabilities.GetCapability(CapabilityType.AcceptSslCertificates) != null)
     {
         bool flag = (bool)capabilities.GetCapability(CapabilityType.AcceptSslCertificates);
         profile.AcceptUntrustedCertificates = flag;
     }
     return profile;
 }
        public void PerfectoOpenConnection()
        {
            var browserName = "mobileOS";
            var host        = "demo.perfectomobile.com";

            DesiredCapabilities capabilities = new DesiredCapabilities(browserName, string.Empty, new Platform(PlatformType.Any));

            capabilities.SetCapability("user", "");

            //TODO: Provide your password
            capabilities.SetCapability("password", "");

            //TODO: Provide your device ID
            capabilities.SetCapability("platformName", deviceOS);
            Console.WriteLine(this.deviceOS + this.deviceVersion + this.deviceDescription);
            capabilities.SetCapability("platformVersion", deviceVersion);
            capabilities.SetCapability("description", deviceDescription);

            capabilities.SetPerfectoLabExecutionId(host);

            // Add a persona to your script (see https://community.perfectomobile.com/posts/1048047-available-personas)
            //capabilities.SetCapability(WindTunnelUtils.WIND_TUNNEL_PERSONA_CAPABILITY, WindTunnelUtils.GEORGIA);

            // Name your script
            capabilities.SetCapability("scriptName", "VSSimpleFixture_" + deviceOS);

            var url = new Uri(string.Format("https://{0}/nexperience/perfectomobile/wd/hub", host));

            System.Threading.Thread.Sleep(2000);
            driver = new RemoteWebDriverExtended(new HttpAuthenticatedCommandExecutor(url), capabilities);

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(40));
            ICapabilities cap = driver.Capabilities;

            executionID = (String)cap.GetCapability("executionId");
            Console.WriteLine(executionID);
        }
        private static ICommandExecutor GetCommandExecutor(int port, ICapabilities capabilities, TimeSpan commandTimeout)
        {
            // This method should be completely removed when the standalone server
            // is in widespread use.
            ICommandExecutor executor = null;
            if (capabilities.HasCapability("useLegacyInternalServer"))
            {
                useLegacyServer = (bool)capabilities.GetCapability("useLegacyInternalServer");
                executor = new HttpCommandExecutor(CreateServerUri(port), commandTimeout);
            }
            else
            {
                useLegacyServer = false;
                try
                {
                    executor = new DriverServiceCommandExecutor(InternetExplorerDriverService.CreateDefaultService(), commandTimeout);
                }
                catch (DriverServiceNotFoundException ex)
                {
                    throw new WebDriverException("You will need to use add InternetExplorerDriver.UseLegacyInternalServer to the desired capabilities to use the internal native code server library. This functionality will be deprecated in favor of the standalone InternetExplorerDriver.exe server.", ex);
                }
            }

            return executor;
        }
Exemple #31
0
        private static FirefoxProfile ExtractProfile(ICapabilities capabilities)
        {
            FirefoxProfile profile = new FirefoxProfile();
            if (capabilities.GetCapability(ProfileCapabilityName) != null)
            {
                object raw = capabilities.GetCapability(ProfileCapabilityName);
                FirefoxProfile rawAsProfile = raw as FirefoxProfile;
                string rawAsString = raw as string;
                if (rawAsProfile != null)
                {
                    profile = rawAsProfile;
                }
                else if (rawAsString != null)
                {
                    try
                    {
                        profile = FirefoxProfile.FromBase64String(rawAsString);
                    }
                    catch (IOException e)
                    {
                        throw new WebDriverException("Unable to create profile from specified string", e);
                    }
                }
            }

            if (capabilities.GetCapability(CapabilityType.Proxy) != null)
            {
                Proxy proxy = null;
                object raw = capabilities.GetCapability(CapabilityType.Proxy);
                Proxy rawAsProxy = raw as Proxy;
                Dictionary<string, object> rawAsMap = raw as Dictionary<string, object>;
                if (rawAsProxy != null)
                {
                    proxy = rawAsProxy;
                }
                else if (rawAsMap != null)
                {
                    proxy = new Proxy(rawAsMap);
                }

                profile.SetProxyPreferences(proxy);
            }

            if (capabilities.GetCapability(CapabilityType.AcceptSslCertificates) != null)
            {
                bool acceptCerts = (bool)capabilities.GetCapability(CapabilityType.AcceptSslCertificates);
                profile.AcceptUntrustedCertificates = acceptCerts;
            }

            return profile;
        }
Exemple #32
0
        private static FirefoxBinary ExtractBinary(ICapabilities capabilities)
        {
            if (capabilities.GetCapability(BinaryCapabilityName) != null)
            {
                string file = capabilities.GetCapability(BinaryCapabilityName).ToString();
                return new FirefoxBinary(file);
            }

            return new FirefoxBinary();
        }
 private void LogOverrideSetCapability(KeyValuePair <string, object> capability, ICapabilities caps)
 {
     if (caps.HasCapability(capability.Key))
     {
         TestLogs.Write($"Overriding Capability, Key:[{capability.Key}], OldValue:[{caps.GetCapability(capability.Key)}], NewValue:[{capability.Value}]");
         return;
     }
     TestLogs.Write($"New Capability, Key:[{capability.Key}], Value:[{capability.Value}]");
 }