public DesiredCapabilities GetCapabilitiesForBrowser(Browser browser)
        {
            switch (browser)
            {
            case Browser.PhantomJS:
                return(DesiredCapabilities.PhantomJS());

            case Browser.IE:
                return(DesiredCapabilities.InternetExplorer());

            case Browser.Chrome:
                return(DesiredCapabilities.Chrome());

            case Browser.Safari:
                return(DesiredCapabilities.Safari());

            case Browser.Android:
                return(DesiredCapabilities.Android());

            case Browser.IPhone:
                var capabilities = DesiredCapabilities.IPhone();
                capabilities.SetCapability("device", "iphone");
                capabilities.SetCapability("app", "safari");
                return(capabilities);

            case Browser.IPad:
                return(DesiredCapabilities.IPad());

            case Browser.Firefox:
            default:
                return(DesiredCapabilities.Firefox());
            }
        }
Exemplo n.º 2
0
        private static IWebDriver CreateMobileWebDriver()
        {
            DesiredCapabilities capabilities;

            var browser = Config.Settings.BrowserStackSettings.BsBrowserName;

            switch (browser)
            {
            case "android":
                capabilities = DesiredCapabilities.Android();
                SetCapabilities(capabilities, "android");
                return(CreateMobileRemoteWebDriver(capabilities));

            case "iPad":
                capabilities = DesiredCapabilities.IPad();
                SetCapabilities(capabilities, "iPad");
                return(CreateMobileRemoteWebDriver(capabilities));

            case "iPhone":
                capabilities = DesiredCapabilities.IPhone();
                SetCapabilities(capabilities, "iPhone");
                return(CreateMobileRemoteWebDriver(capabilities));

            default:
                throw new ArgumentOutOfRangeException("'Browser' value: " + browser);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 连接一个远程IEWebDriver
        /// </summary>
        /// <param name="strBrowserName"></param>
        /// <param name="strUrl"></param>
        /// <returns></returns>
        private static IWebDriver ConnectToRemoteWebDriver(string strBrowserName, string strUrl)
        {
            DesiredCapabilities caps = null;
            Uri hubUri = new Uri(strUrl);

            switch (strBrowserName)
            {
            case browser_Firefox:
                caps = DesiredCapabilities.Firefox();
                break;

            case browser_Chrome:
                caps = DesiredCapabilities.Chrome();
                break;

            case browser_InternetExplorer:
                caps = DesiredCapabilities.InternetExplorer();
                break;

            case browser_PhantomJS:
                caps = DesiredCapabilities.PhantomJS();
                break;

            case browser_HtmlUnit:
                caps = DesiredCapabilities.HtmlUnit();
                break;

            case browser_HtmlUnitWithJavaScript:
                caps = DesiredCapabilities.HtmlUnitWithJavaScript();
                break;

            case browser_Opera:
                caps = DesiredCapabilities.Opera();
                break;

            case browser_Safari:
                caps = DesiredCapabilities.Safari();
                break;

            case browser_IPhone:
                caps = DesiredCapabilities.IPhone();
                break;

            case browser_IPad:
                caps = DesiredCapabilities.IPad();
                break;

            case browser_Android:
                caps = DesiredCapabilities.Android();
                break;

            default:
                throw new ArgumentException(String.Format(@"<{0}> 类型浏览器不被支持。请注意区分大小写。", strBrowserName),
                                            "浏览器类型名");
            }
            RemoteWebDriver pDriver = new RemoteWebDriver(hubUri, caps);

            return(pDriver);
        }
Exemplo n.º 4
0
        private static IWebDriver ConnetctToRemoteWebDriver(string browserName, string remoteUrl)
        {
            DesiredCapabilities caps = null;
            Uri hubUri = new Uri(remoteUrl);

            switch (browserName)
            {
            case browser_Firefox:
                caps = DesiredCapabilities.Firefox();
                break;

            case browser_Chrome:
                caps = DesiredCapabilities.Chrome();
                break;

            case browser_InternetExplorer:
                caps = DesiredCapabilities.InternetExplorer();
                break;

            case browser_PhantomJS:
                caps = DesiredCapabilities.PhantomJS();
                break;

            case browser_HtmlUnit:
                caps = DesiredCapabilities.HtmlUnit();
                break;

            case browser_HtmlUnitWithJavaScript:
                caps = DesiredCapabilities.HtmlUnitWithJavaScript();
                break;

            case browser_Opera:
                caps = DesiredCapabilities.Opera();
                break;

            case browser_Safari:
                caps = DesiredCapabilities.Safari();
                break;

            case browser_IPhone:
                caps = DesiredCapabilities.IPhone();
                break;

            case browser_IPad:
                caps = DesiredCapabilities.IPad();
                break;

            case browser_Android:
                caps = DesiredCapabilities.Android();
                break;

            default:
                throw new ArgumentException(String.Format(@"<{0}> was not recognized as supported browser. This parameter is case sensitive", browserName),
                                            "WebDriverOptions.BrowserName");
            }
            RemoteWebDriver newDriver = new RemoteWebDriver(hubUri, caps);

            return(newDriver);
        }
Exemplo n.º 5
0
        private static DesiredCapabilities GetAndroidCapabilities()
        {
            DesiredCapabilities caps = DesiredCapabilities.Android();

            caps.SetCapability(CapabilityType.TakesScreenshot, true);
            caps.SetCapability(CapabilityType.Rotatable, true);
            ////caps.SetCapability(CapabilityType.SUPPORTS_BROWSER_CONNECTION, true);
            return(caps);
        }
        public static IWebDriver CreateWebDriver(MethodInfo testMethod, RemoteWebDriverCapability capability, string hub)
        {
            DesiredCapabilities capabilities = null;

            switch (capability)
            {
            case RemoteWebDriverCapability.Andriod:
                capabilities = DesiredCapabilities.Android();
                break;

            case RemoteWebDriverCapability.Chrome:
                capabilities = DesiredCapabilities.Chrome();
                break;

            case RemoteWebDriverCapability.FireFox:
                capabilities = DesiredCapabilities.Firefox();
                break;

            case RemoteWebDriverCapability.HtmlUnit:
                capabilities = DesiredCapabilities.HtmlUnit();
                break;

            case RemoteWebDriverCapability.HtmlUnitWithJS:
                capabilities = DesiredCapabilities.HtmlUnitWithJavaScript();
                break;

            case RemoteWebDriverCapability.InternetExplorer:
                capabilities = DesiredCapabilities.InternetExplorer();
                break;

            case RemoteWebDriverCapability.IPad:
                capabilities = DesiredCapabilities.IPad();
                break;

            case RemoteWebDriverCapability.IPhone:
                capabilities = DesiredCapabilities.IPhone();
                break;

            case RemoteWebDriverCapability.Safari:
                capabilities = DesiredCapabilities.Safari();
                break;
            }

            if (string.IsNullOrEmpty(hub))
            {
                var attr = ReflectionHelper.GetAttribute <RemoteWebDriverHubAddressAttribute>(testMethod);

                if (attr != null)
                {
                    hub = attr.Hub;
                }
            }

            return(CreateWebDriverInstance(testMethod, hub, capabilities));
        }
        public WebDriverAndroidCapabilities(SaucePlatform platform, string testName) : base(testName)
        {
            Console.WriteLine(SauceryConstants.SETTING_UP, testName, SauceryConstants.ANDROID_ON_WEBDRIVER);
            Caps = DesiredCapabilities.Android();
            Caps.SetCapability(SauceryConstants.SAUCE_PLATFORM_CAPABILITY, SauceryConstants.LINUX);
            Caps.SetCapability(SauceryConstants.SAUCE_VERSION_CAPABILITY, platform.BrowserVersion);
            Caps.SetCapability(SauceryConstants.SAUCE_DEVICE_NAME_CAPABILITY, platform.LongName);
            Caps.SetCapability(SauceryConstants.SAUCE_DEVICE_ORIENTATION_CAPABILITY, platform.DeviceOrientation);

            AddSauceLabsCapabilities();
        }
        public void HTCDesire626sDeviceRunner()
        {
            DesiredCapabilities DesiredCapability = DesiredCapabilities.Android();

            DesiredCapability.SetCapability("deviceName", AuthConstant.HTCDesire626sDevice);
            DesiredCapability.SetCapability(CapabilityType.BrowserName, "Android");
            DesiredCapability.SetCapability(CapabilityType.Version, AuthConstant.HTCDesire626sVersionNumber);
            DesiredCapability.SetCapability("platformName", "Android");
            DesiredCapability.SetCapability("appPackage", AuthConstant.ZonePackageName);
            DesiredCapability.SetCapability("appActivity", AuthConstant.ZoneAppActivity);

            DesiredCapabilityBrowser(DesiredCapability);
        }
Exemplo n.º 9
0
        public Remote(string Browser) : base()
        {
            switch (Browser)
            {
            case "IE":
                capability = DesiredCapabilities.InternetExplorer();
                capability.SetCapability("os", "Windows");
                capability.SetCapability("os_version", "10");
                capability.SetCapability("browser", "IE");
                capability.SetCapability("browser_version", "11.0");
                break;

            case "Firefox":
                capability = DesiredCapabilities.Firefox();
                capability.SetCapability("os", "Windows");
                capability.SetCapability("os_version", "10");
                capability.SetCapability("browser", "Firefox");
                capability.SetCapability("browser_version", "52.0 beta");
                break;

            case "Chrome":
                capability = DesiredCapabilities.Chrome();
                capability.SetCapability("os", "Windows");
                capability.SetCapability("os_version", "10");
                capability.SetCapability("browser", "Chrome");
                capability.SetCapability("browser_version", "56.0");
                break;

            case "Android":
                capability = DesiredCapabilities.Android();
                capability.SetCapability("browserName", "android");
                capability.SetCapability("platform", "ANDROID");
                capability.SetCapability("device", "Google Nexus 5");
                break;

            case "iPhone":
                capability = DesiredCapabilities.IPhone();
                capability.SetCapability("browserName", "iPhone");
                capability.SetCapability("platform", "MAC");
                capability.SetCapability("device", "iPhone 6S Plus");
                break;
            }
            //capability = DesiredCapabilities.Firefox();
            capability.SetCapability("server", "hub-cloud.browserstack.com");
            capability.SetCapability("browserstack.user", "birajpoddar1");
            capability.SetCapability("browserstack.key", "3fCuqYBKJUo4t2Jgc5ep");
            capability.SetCapability("browserstack.debug", "true");
            driver = new RemoteWebDriver(
                new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability
                );
        }
Exemplo n.º 10
0
        public static DesiredCapabilities GetCapability(TestConfiguration configuration)
        {
            DesiredCapabilities capab = null;

            switch (configuration.Browser.ToUpper())
            {
            case "FIREFOX":
                capab = DesiredCapabilities.Firefox();
                break;

            case "CHROME":
                capab = DesiredCapabilities.Chrome();
                break;

            case "IEXPLORER":
            case "INTERNET EXPLORER":
            case "INTERNET":
                capab = DesiredCapabilities.InternetExplorer();
                break;

            case "EDGE":
                capab = DesiredCapabilities.Edge();
                break;

            case "SAFARI":
                capab = DesiredCapabilities.Safari();
                break;

            case "ANDROID":
                capab = DesiredCapabilities.Android();
                break;

            case "IPAD":
                capab = DesiredCapabilities.IPad();
                break;

            case "IPHONE":
                capab = DesiredCapabilities.IPhone();
                break;

            default:
                capab = DesiredCapabilities.Firefox();
                break;
            }

            capab.IsJavaScriptEnabled = true;
            capab.SetCapability(CapabilityType.Version, configuration.BrowserVersion);
            capab.SetCapability(CapabilityType.Platform, configuration.Platform);
            capab.SetCapability("build", configuration.BuildName);
            return(capab);
        }
        public static DesiredCapabilities GetDesiredCapabilities(string capName)
        {
            switch (capName.ToLower())
            {
            case "android":
            case "linux":
                return(DesiredCapabilities.Android());

            case "chrome":
            case "googlechrome":
            case "google chrome":
                return(DesiredCapabilities.Chrome());

            case "firefox":
                return(DesiredCapabilities.Firefox());

            case "iphone":
                return(DesiredCapabilities.IPhone());

            case "ipad":
                return(DesiredCapabilities.IPad());

            case "phantomjs":
                return(DesiredCapabilities.PhantomJS());

            case "safari":
                var d = DesiredCapabilities.Safari();
                d.Platform            = new Platform(PlatformType.Mac);
                d.IsJavaScriptEnabled = true;
                return(d);

            case "iexplore":
            case "internetexplorer":
            case "internet explorer":
                return(DesiredCapabilities.InternetExplorer());

            case "opera":
                return(DesiredCapabilities.Opera());

            case "htmlunit":
            case "htmlunitfirefox":
                return(DesiredCapabilities.HtmlUnitWithJavaScript());

            case "htmlunitNoJavaScript":
                return(DesiredCapabilities.HtmlUnitWithJavaScript());

            default:
                return(DesiredCapabilities.Firefox());
            }
        }
        public WebDriverAndroidCapabilities(SaucePlatform platform, string testName) : base(testName)
        {
            Console.WriteLine(SauceryConstants.SETTING_UP, testName, SauceryConstants.ANDROID_ON_WEBDRIVER);
            Caps = DesiredCapabilities.Android();

            //See https://github.com/appium/appium-dotnet-driver/wiki/Android-Sample
            //AndroidDriver<AppiumWebElement> iosd = new AndroidDriver<AppiumWebElement>(Caps);

            Caps.SetCapability(SauceryConstants.SAUCE_PLATFORM_CAPABILITY, SauceryConstants.LINUX);
            Caps.SetCapability(SauceryConstants.SAUCE_VERSION_CAPABILITY, platform.BrowserVersion);
            Caps.SetCapability(SauceryConstants.SAUCE_DEVICE_NAME_CAPABILITY, platform.LongName);
            Caps.SetCapability(SauceryConstants.SAUCE_DEVICE_ORIENTATION_CAPABILITY, platform.DeviceOrientation);

            AddSauceLabsCapabilities();
        }
Exemplo n.º 13
0
        public static DesiredCapabilities FindDesiredCapabilities(this BrowserType browserType)
        {
            DesiredCapabilities capability;

            switch (browserType)
            {
            case BrowserType.IE:
                capability = DesiredCapabilities.InternetExplorer();
                break;

            case BrowserType.FireFox:
                capability = DesiredCapabilities.Firefox();
                break;

            case BrowserType.Chrome:
                capability = DesiredCapabilities.Chrome();
                break;

            case BrowserType.Safari:
                capability = DesiredCapabilities.Safari();
                break;

            case BrowserType.Opera:
                capability = DesiredCapabilities.Opera();
                break;

            case BrowserType.Android:
                capability = DesiredCapabilities.Android();
                break;

            case BrowserType.iPhone:
                capability = DesiredCapabilities.IPhone();
                break;

            case BrowserType.iPad:
                capability = DesiredCapabilities.IPad();
                break;

            case BrowserType.Edge:
                capability = DesiredCapabilities.Edge();
                break;

            default:
                throw new InvalidOperationException(
                          $"Browser Type '{browserType}' is not supported as a remote driver.");
            }
            return(capability);
        }
Exemplo n.º 14
0
        private static DesiredCapabilities GenerateDesiredCapabilities(Browser browser)
        {
            DesiredCapabilities browserCapabilities = null;

            switch (browser)
            {
            case Browser.InternetExplorer:
            case Browser.InternetExplorer64:
                browserCapabilities = DesiredCapabilities.InternetExplorer();
                break;

            case Browser.Firefox:
                browserCapabilities = DesiredCapabilities.Firefox();
                break;

            case Browser.Chrome:
                browserCapabilities = DesiredCapabilities.Chrome();
                break;

            case Browser.PhantomJs:
                browserCapabilities = DesiredCapabilities.PhantomJS();
                break;

            case Browser.Safari:
                browserCapabilities = DesiredCapabilities.Safari();
                break;

            case Browser.iPad:
                browserCapabilities = DesiredCapabilities.IPad();
                break;

            case Browser.iPhone:
                browserCapabilities = DesiredCapabilities.IPhone();
                break;

            case Browser.Android:
                browserCapabilities = DesiredCapabilities.Android();
                break;

            default:
                throw new FluentException("Selected browser [{0}] not supported. Unable to determine appropriate capabilities.", browser.ToString());
            }

            browserCapabilities.IsJavaScriptEnabled = true;
            return(browserCapabilities);
        }
Exemplo n.º 15
0
        public AppiumAndroidCapabilities(SaucePlatform platform, string testName)
            : base(testName)
        {
            var nativeApp          = Enviro.SauceNativeApp;
            var useChromeOnAndroid = Enviro.SauceUseChromeOnAndroid;

            Console.WriteLine(SauceryConstants.SETTING_UP, testName, SauceryConstants.ANDROID_ON_APPIUM);
            Caps = DesiredCapabilities.Android();
            Caps.SetCapability(SauceryConstants.SAUCE_BROWSER_NAME_CAPABILITY, GetBrowser(nativeApp, useChromeOnAndroid));
            Caps.SetCapability(SauceryConstants.SAUCE_PLATFORM_VERSION_CAPABILITY, platform.LongVersion);
            Caps.SetCapability(SauceryConstants.SAUCE_APPIUM_VERSION_CAPABILITY, SauceryConstants.SAUCE_APPIUM_VERSION);
            Caps.SetCapability(SauceryConstants.SAUCE_PLATFORM_NAME_CAPABILITY, SauceryConstants.ANDROID);
            Caps.SetCapability(SauceryConstants.SAUCE_DEVICE_NAME_CAPABILITY, platform.LongName);
            Caps.SetCapability(SauceryConstants.SAUCE_DEVICE_ORIENTATION_CAPABILITY, platform.DeviceOrientation);

            AddSauceLabsCapabilities(nativeApp);
        }
        static void Main()
        {
            AndroidDriver <AndroidElement> driver;
            DesiredCapabilities            capability = DesiredCapabilities.Android();

            capability.SetCapability("browserstack.user", Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME"));
            capability.SetCapability("browserstack.key", Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY"));
            capability.SetCapability("build", "App Testing Android");
            capability.SetCapability("name", "sample csharp");
            capability.SetCapability("browserstack.debug", true);
            capability.SetCapability("platform", "android");
            capability.SetCapability("device", "Google Nexus 6");
            capability.SetCapability("realMobile", true);
            capability.SetCapability("app", Environment.GetEnvironmentVariable("ANDROID_APP_URL"));

            driver = new AndroidDriver <AndroidElement>(
                new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability
                );

            ((ITakesScreenshot)driver).GetScreenshot();

            AndroidElement samplelabel = driver.FindElementById("sampleLabel");

            Console.WriteLine(samplelabel.Text);

            var contexts = driver.Contexts;

            AndroidElement num1 = driver.FindElementById("num1");
            AndroidElement num2 = driver.FindElementById("num2");

            num1.SendKeys("12");
            num2.SendKeys("32");

            AndroidElement add_btn = driver.FindElementById("addBtn");

            add_btn.Tap(1, 1000);

            ((ITakesScreenshot)driver).GetScreenshot();
            Console.WriteLine(samplelabel.Text);

            driver.Quit();
        }
Exemplo n.º 17
0
        private static DesiredCapabilities GetDefaultCapabilities(string browser)
        {
            switch (browser)
            {
            case "internet explorer":
                return(DesiredCapabilities.InternetExplorer());

            case "firefox":
                return(DesiredCapabilities.Firefox());

            case "phantomjs":
                return(DesiredCapabilities.PhantomJS());

            case "htmlunit":
                return(DesiredCapabilities.HtmlUnitWithJavaScript());

            case "iPhone":
                return(DesiredCapabilities.IPhone());

            case "iPad":
                return(DesiredCapabilities.IPad());

            case "android":
                return(DesiredCapabilities.Android());

            case "opera":
                return(DesiredCapabilities.Opera());

            case "safari":
                return(DesiredCapabilities.Safari());

            case "chrome":
            default:
                return(DesiredCapabilities.Chrome());
            }
        }
Exemplo n.º 18
0
        public IWebDriver StartBrowser()
        {
            string webBrowser = System.Configuration.ConfigurationManager.AppSettings["Browser"];;

            DesiredCapabilities caps;

            bool remote = false;

            switch (webBrowser.ToLower())
            {
            case "firefox":
                if (remote)
                {
                    caps = DesiredCapabilities.Firefox();
                    caps.SetCapability(CapabilityType.Platform, ConfigurationManager.AppSettings["Platform"]);
                    caps.SetCapability(CapabilityType.Version, ConfigurationManager.AppSettings["FireFoxVersion"]);
                    caps.SetCapability("j6", "Testing Selenium 2 with C# on Sauce");
                    caps.SetCapability("username", "hmnd42009");
                    caps.SetCapability("accessKey", "0cc5c5c4-db5a-4e69-bfd0-67889d3557e0");
                    _driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                }
                else
                {
                    _driver = new FirefoxDriver();
                }
                break;

            case "iexplore":
                if (remote)
                {
                    caps = DesiredCapabilities.InternetExplorer();
                    caps.SetCapability(CapabilityType.Platform, ConfigurationManager.AppSettings["Platform"]);
                    caps.SetCapability(CapabilityType.Version, ConfigurationManager.AppSettings["IexploreVersion"]);
                    caps.SetCapability("j6", "Testing Selenium 2 with C# on Sauce");
                    caps.SetCapability("username", "hmnd42009");
                    caps.SetCapability("accessKey", "0cc5c5c4-db5a-4e69-bfd0-67889d3557e0");
                    _driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                }
                else
                {
                    _driver = new InternetExplorerDriver();
                }
                break;

            case "chrome":
                if (remote)
                {
                    caps = DesiredCapabilities.Chrome();
                    caps.SetCapability(CapabilityType.Platform, ConfigurationManager.AppSettings["Platform"]);
                    caps.SetCapability(CapabilityType.Version, "");
                    caps.SetCapability("j6", "Testing Selenium 2 with C# on Sauce");
                    caps.SetCapability("username", "xingeryu");
                    caps.SetCapability("accessKey", "66647a62-0334-41a5-92ea-0c80b14a5a50");
                    _driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                }
                else
                {
                    _driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), new ChromeOptions(), TimeSpan.FromMinutes(5));
                }
                break;

            case "android":
                caps = DesiredCapabilities.Android();
                caps.SetCapability(CapabilityType.Platform, ConfigurationManager.AppSettings["AndroidPlatform"]);
                caps.SetCapability(CapabilityType.Version, ConfigurationManager.AppSettings["AndroidVersion"]);
                caps.SetCapability("j6", "Testing Selenium 2 with C# on Sauce");
                caps.SetCapability("username", "hmnd42009");
                caps.SetCapability("accessKey", "0cc5c5c4-db5a-4e69-bfd0-67889d3557e0");
                _driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                break;

            case "android_tablet":
                //NOT WORKING
                caps = DesiredCapabilities.Android();
                caps.SetCapability(CapabilityType.Platform, ConfigurationManager.AppSettings["AndroidPlatform"]);
                caps.SetCapability(CapabilityType.Version, ConfigurationManager.AppSettings["AndroidVersion"]);
                //caps.SetCapability(CapabilityType.DeviceType, "tablet");
                caps.SetCapability("j6", "Testing Selenium 2 with C# on Sauce");
                caps.SetCapability("username", "hmnd42009");
                caps.SetCapability("accessKey", "0cc5c5c4-db5a-4e69-bfd0-67889d3557e0");
                _driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                break;

            case "iphone":
                caps = DesiredCapabilities.IPhone();
                caps.SetCapability(CapabilityType.Platform, ConfigurationManager.AppSettings["AppleOS"]);
                caps.SetCapability(CapabilityType.Version, ConfigurationManager.AppSettings["IPhoneVersion"]);
                caps.SetCapability("j6", "Testing Selenium 2 with C# on Sauce");
                caps.SetCapability("username", "hmnd42009");
                caps.SetCapability("accessKey", "0cc5c5c4-db5a-4e69-bfd0-67889d3557e0");
                _driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                break;

            case "ipad":
                caps = DesiredCapabilities.IPad();
                caps.SetCapability(CapabilityType.Platform, ConfigurationManager.AppSettings["AppleOS"]);
                caps.SetCapability(CapabilityType.Version, ConfigurationManager.AppSettings["IPadVersion"]);
                caps.SetCapability("j6", "Testing Selenium 2 with C# on Sauce");
                caps.SetCapability("username", "hmnd42009");
                caps.SetCapability("accessKey", "0cc5c5c4-db5a-4e69-bfd0-67889d3557e0");
                _driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                break;
            }

            //_driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(60));
            //_driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(300));
            //_driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(300));

            _driver.Manage().Window.Maximize();

            return(_driver);
        }
        private void SetWebDriverToAndroid()
        {
            _capabilities = DesiredCapabilities.Android();

            WebDriver = new RemoteWebDriver(_capabilities);
        }
Exemplo n.º 20
0
        public BaseTestAllBrowsers(BROWSER_TARGETS target)
        {
            BrowserTarget = target;
            switch (target)
            {
            case BROWSER_TARGETS.FIREFOX:
                BrowserCapabilities = DesiredCapabilities.Firefox();
                break;

            case BROWSER_TARGETS.FIREFOX36:
                BrowserCapabilities = DesiredCapabilities.Firefox();
                BrowserCapabilities.SetCapability(CapabilityType.Version, "3.6");
                break;

            case BROWSER_TARGETS.IE8:
                BrowserCapabilities = DesiredCapabilities.InternetExplorer();
                BrowserCapabilities.SetCapability(CapabilityType.Version, "8");
                break;

            case BROWSER_TARGETS.IE9:
                BrowserCapabilities = DesiredCapabilities.InternetExplorer();
                BrowserCapabilities.SetCapability(CapabilityType.Version, "9");
                break;

            case BROWSER_TARGETS.IE10:
                BrowserCapabilities = DesiredCapabilities.InternetExplorer();
                BrowserCapabilities.SetCapability(CapabilityType.Version, "10");
                break;

            case BROWSER_TARGETS.IE11:
                BrowserCapabilities = DesiredCapabilities.InternetExplorer();
                BrowserCapabilities.SetCapability(CapabilityType.Version, "11");
                break;

            case BROWSER_TARGETS.CHROME:
            {
                ChromeOptions options = new ChromeOptions();
                options.AddExcludedArguments((new string[] { "test-type", "ignore-certificate-errors" }).ToList <string>());
                BrowserCapabilities = (DesiredCapabilities)options.ToCapabilities();
            }
            break;

            case BROWSER_TARGETS.CHROMEINCOGNITO:
            {
                ChromeOptions options = new ChromeOptions();
                options.AddExcludedArguments((new string[] { "test-type", "ignore-certificate-errors" }).ToList <string>());
                options.AddArgument("-incognito");
                BrowserCapabilities = (DesiredCapabilities)options.ToCapabilities();
            }
            break;

            case BROWSER_TARGETS.OPERA:
                BrowserCapabilities = DesiredCapabilities.Opera();
                break;

            case BROWSER_TARGETS.ANDROID:
                BrowserCapabilities = DesiredCapabilities.Android();
                break;

            case BROWSER_TARGETS.IPAD:
                BrowserCapabilities = DesiredCapabilities.IPad();
                break;

            default:
                BrowserCapabilities = new DesiredCapabilities();
                break;
            }

            BrowserCapabilities.IsJavaScriptEnabled = true;
        }
Exemplo n.º 21
0
        /// <summary>
        /// this method creates the generic current instance of the appium driver.
        /// </summary>
        /// <returns></returns>
        public static void InitializeAppiumDriverInstance(string testName)
        {
            DesiredCapabilities cap  = new DesiredCapabilities();
            string capabilitySetting = string.Empty;

            // first try and set common capabilities for both android and iOS
            try
            {
                string   str    = null;
                string[] strArr = null;
                str = ConfigurationManager.AppSettings.Get("PlatformVersion");
                char[] splitchar = { '.' };
                strArr = str.Split(splitchar);
                int majorVersionNumber = Int32.Parse(strArr[0]);


                string keyAppiumIPAddress = string.Empty;
                bool   iOSDeviceTesting   = false;
                DesiredCapabilities caps  = DesiredCapabilities.Android();
                if (ConfigurationManager.AppSettings.Get("IsSauceLabTest").Contains("true") == true)
                {
                    caps.SetCapability("username", "bandipavan");
                    //set your sauce labs access key
                    caps.SetCapability("accessKey", "88ba34b6-e507-4e38-bea2-e74b454ae067");
                    caps.SetCapability("appiumVersion", "1.9.1");
                    caps.SetCapability("deviceName", "Samsung Galaxy S9 WQHD GoogleAPI Emulator"); //Samsung Galaxy S9 WQHD GoogleAPI Emulator, Samsung Galaxy S9 Plus FHD GoogleAPI Emulator, Samsung Galaxy S9 Plus WQHD GoogleAPI Emulator
                    caps.SetCapability("deviceOrientation", "portrait");
                    caps.SetCapability("browserName", "");
                    caps.SetCapability("platformVersion", "9");
                    caps.SetCapability("platformName", "Android");
                    caps.SetCapability("no-reset", "true");
                    caps.SetCapability("full-reset", "false");
                    caps.SetCapability("appPackage", "com.isagenix.qualia");
                    caps.SetCapability("appActivity", "md5936c377d2b4806a004640334b067390d.SplashActivity");
                    caps.SetCapability("app", @"sauce-storage:com.isagenix.qualia.apk.zip"); //https://github.com/saucelabs/sample-app-mobile/releases/download/2.2.0/Android.SauceLabs.Mobile.Sample.app.2.2.0.apk
                }
                else
                {
                    if (ConfigurationManager.AppSettings.Get("PlatformName").Contains("iOS") == true)
                    {
                        iOSDeviceTesting = true;
                    }

                    SetAppiumCapability(ref cap, "device", "Device");
                    SetAppiumCapability(ref cap, "deviceName", "DeviceName");
                    SetAppiumCapability(ref cap, "platformName", "PlatformName");
                    SetAppiumCapability(ref cap, "platformVersion", "PlatformVersion");
                    //SetAppiumCapability(ref cap, "udid", "udid");
                    //SetAppiumCapability(ref cap, "bundleId", "bundleId");
                    //SetAppiumCapability(ref cap, "app", "app");
                    //SetAppiumCapability(ref cap, "xcodeOrgId", "xcodeOrgId");
                    //SetAppiumCapability(ref cap, "xcodeSigningId", "xcodeSigningId");
                    SetAppiumCapability(ref cap, "no-reset", "true");
                    SetAppiumCapability(ref cap, "full-reset", "false");
                    SetAppiumCapability(ref cap, "appPackage", "AppPackage");
                    SetAppiumCapability(ref cap, "appActivity", "AppActivity");
                    //SetAppiumCapability(ref cap, "testobject_api_key", "TestObjectAPIKey");
                    //SetAppiumCapability(ref cap, "phoneOnly", "PhoneOnly");
                    keyAppiumIPAddress = ConfigurationManager.AppSettings.Get("AppiumIPAddress");

                    if (ConfigurationManager.AppSettings.Get("PlatformName").Contains("Android"))
                    {
                        cap.SetCapability("automationName", "uiautomator2");
                    }
                }

                string capURI = string.Empty;
                if (ConfigurationManager.AppSettings.Get("IsSauceLabTest").Contains("true") == true)
                {
                    capURI = @"http://ondemand.saucelabs.com:80/wd/hub";
                    //capURI = "http://" + keyAppiumIPAddress + "/wd/hub";
                    //cap.SetCapability("appiumVersion", "1.7.1");
                    //cap.SetCapability("deviceOrientation", "portrait");
                    //SetAppiumCapability(ref cap, "deviceOrientation", "portrait");
                }
                else
                {
                    capURI = "http://" + keyAppiumIPAddress + ":4723/wd/hub";
                    //capURI = "http://" + keyAppiumIPAddress + ":27015/wd/hub";
                }

                cap.SetCapability(MobileCapabilityType.NewCommandTimeout, 120);

                //if (testName.Length > 0)
                //    cap.SetCapability("testobject_test_name", testName);

                if (iOSDeviceTesting == true)
                {
                    Instance = new IOSDriver <IWebElement>(new Uri(capURI), cap, TimeSpan.FromSeconds(840));
                }
                else if (ConfigurationManager.AppSettings.Get("IsSauceLabTest").Contains("true") == true)
                {
                    Instance = new AndroidDriver <IWebElement>(new Uri(capURI), caps, TimeSpan.FromSeconds(1200)); // 840));
                }
                else
                {
                    Instance = new AndroidDriver <IWebElement>(new Uri(capURI), cap, TimeSpan.FromSeconds(1200)); // 840));
                }
                // 81, 149
                Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
            }
            catch (ConfigurationErrorsException)
            {
            }

            GenericUtilities.Wait(3);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Get a RemoteWebDriver
        /// </summary>
        /// <param name="browser">the Browser to test on</param>
        /// <param name="languageCode">The language that the browser should accept.</param>
        /// <returns>a IWebDriver</returns>
        IWebDriver IWebDriverFactory.GetWebDriver(Browser browser, string languageCode)
        {
            DesiredCapabilities desiredCapabilities;

            //What browser to test on?
            switch (browser.Browserstring.ToLowerInvariant())
            {
            case "firefox":
                desiredCapabilities = DesiredCapabilities.Firefox();
                desiredCapabilities.SetCapability("singleWindow", true);
                desiredCapabilities.SetCapability("handlesAlerts", true);
                break;

            case "chrome":
                desiredCapabilities = DesiredCapabilities.Chrome();
                desiredCapabilities.SetCapability("singleWindow", true);
                desiredCapabilities.SetCapability("handlesAlerts", true);
                desiredCapabilities.SetCapability("--disable-hang-monitor", true);
                break;

            case "internet explorer":
                desiredCapabilities = DesiredCapabilities.InternetExplorer();
                desiredCapabilities.SetCapability("singleWindow", true);
                desiredCapabilities.SetCapability("ie.ensureCleanSession", true);
                desiredCapabilities.SetCapability("enableElementCacheCleanup", false);
                desiredCapabilities.SetCapability("ignoreProtectedModeSettings", true);
                desiredCapabilities.SetCapability("enablePersistentHover", false);
                break;

            case "safari":
                desiredCapabilities = DesiredCapabilities.Safari();
                desiredCapabilities.SetCapability("singleWindow", true);
                desiredCapabilities.SetCapability("handlesAlerts", true);
                break;

            case "android":
                desiredCapabilities = DesiredCapabilities.Android();
                break;

            case "ipad":
                desiredCapabilities = DesiredCapabilities.IPad();
                break;

            case "iphone":
                desiredCapabilities = DesiredCapabilities.IPhone();
                break;

            case "opera":
                desiredCapabilities = DesiredCapabilities.Opera();
                break;

            case "htmlunit":
                desiredCapabilities = DesiredCapabilities.HtmlUnit();
                break;

            case "htmlunitjs":
                desiredCapabilities = DesiredCapabilities.HtmlUnitWithJavaScript();
                break;

            case "phantomjs":
                desiredCapabilities = DesiredCapabilities.PhantomJS();
                break;

            default:
                desiredCapabilities = new DesiredCapabilities();
                desiredCapabilities.SetCapability(CapabilityType.BrowserName, browser.Browserstring);
                break;
            }

            //If version is set, use this version.
            if (!String.IsNullOrEmpty(browser.Versionsstring))
            {
                desiredCapabilities.SetCapability(CapabilityType.Version, browser.Versionsstring);
            }

            return(new RemoteWebDriver(new Uri("http://SELENIUMHUBADDRESS:4444/wd/hub"), desiredCapabilities, new TimeSpan(0, 0, 10)));
        }
Exemplo n.º 23
0
        private static DesiredCapabilities BuildDesiredCapabilities()
        {
            DesiredCapabilities dc;

            if (IsSauceLabsDesktopTest)
            {
                switch (BrowserName.ToLower())
                {
                case "firefox":
                    dc = DesiredCapabilities.Firefox();
                    break;

                case "chrome":
                    dc = DesiredCapabilities.Chrome();
                    break;

                case "safari":
                    dc = DesiredCapabilities.Safari();
                    break;

                case "ie":
                    dc = DesiredCapabilities.InternetExplorer();
                    break;

                default:
                    dc = DesiredCapabilities.InternetExplorer();
                    break;
                }
                dc.SetCapability(CapabilityType.Version, BrowserVersion);
                dc.SetCapability(CapabilityType.Platform, OperatingSystem);
                dc.SetCapability("screen-resolution", Resolution);
            }
            else
            {
                switch (DeviceType.ToLower())
                {
                case "android":
                    dc = DesiredCapabilities.Android();
                    break;

                case "iphone":
                    dc = DesiredCapabilities.IPhone();
                    break;

                default:
                    dc = DesiredCapabilities.IPhone();
                    break;
                }
                dc.SetCapability(CapabilityType.Platform, DevicePlatform);
                dc.SetCapability(CapabilityType.Version, DeviceOsVersion);
                dc.SetCapability("deviceName", DeviceName);
                dc.SetCapability("device-orientation", DeviceOrientation);
            }

            dc.SetCapability(CapabilityType.IsJavaScriptEnabled, JavaScriptEnabled);
            dc.SetCapability(CapabilityType.HandlesAlerts, "dismiss");
            dc.SetCapability(CapabilityType.TakesScreenshot, "true");
            dc.SetCapability("tags", Tags);
            dc.SetCapability("name", TestName);
            dc.SetCapability("username", "seanrand");
            dc.SetCapability("accessKey", "2002db9c-71fb-4f6a-a691-2e249eea98c2");

            return(dc);
        }
Exemplo n.º 24
0
        private static IWebDriver ConnetctToRemoteWebDriver(WebDriverOptions browserOptions)
        {
            DesiredCapabilities caps = null;
            Uri hubUri = new Uri(browserOptions.RemoteUrl);

            switch (browserOptions.BrowserName)
            {
            /*
             * http://stackoverflow.com/questions/17398896/how-to-use-different-version-of-firefox-using-webdriver
             * https://code.google.com/p/selenium/wiki/FirefoxDriver
             * https://code.google.com/p/selenium/wiki/InternetExplorerDriver
             * https://code.google.com/p/selenium/wiki/ChromeDriver#Overriding_the_Chrome_binary_location
             *
             */

            case WebDriverOptions.browser_Firefox:
                path_to_binary      = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                binary_path_propery = "webdriver.firefox.bin";
                caps = DesiredCapabilities.Firefox();
                break;

            case WebDriverOptions.browser_Chrome:
                path_to_driver      = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                driver_path_propery = "webdriver.chrome.driver";
                caps = DesiredCapabilities.Chrome();
                break;

            case WebDriverOptions.browser_InternetExplorer:
                caps                = DesiredCapabilities.InternetExplorer();
                path_to_driver      = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                driver_path_propery = "webdriver.ie.driver";
                break;

            case WebDriverOptions.browser_PhantomJS:
                caps = DesiredCapabilities.PhantomJS();
                break;

            case WebDriverOptions.browser_HtmlUnit:
                caps = DesiredCapabilities.HtmlUnit();
                break;

            case WebDriverOptions.browser_HtmlUnitWithJavaScript:
                caps = DesiredCapabilities.HtmlUnitWithJavaScript();
                break;

            case WebDriverOptions.browser_Opera:
                caps = DesiredCapabilities.Opera();
                break;

            case WebDriverOptions.browser_Safari:
                caps = DesiredCapabilities.Safari();
                break;

            case WebDriverOptions.browser_IPhone:
                caps = DesiredCapabilities.IPhone();
                break;

            case WebDriverOptions.browser_IPad:
                caps = DesiredCapabilities.IPad();
                break;

            case WebDriverOptions.browser_Android:
                caps = DesiredCapabilities.Android();
                break;

            default:
                throw new ArgumentException(String.Format(@"<{0}> was not recognized as supported browser. This parameter is case sensitive", browserOptions.BrowserName),
                                            "WebDriverOptions.BrowserName");
            }
            RemoteWebDriver newDriver = new RemoteWebDriver(hubUri, caps);

            return(newDriver);
        }
Exemplo n.º 25
0
        private DesiredCapabilities ConfigSauceCapabilities()
        {
            DesiredCapabilities capabillities;
            var browserType = _config.Get("BrowserType", "Firefox");

            if (browserType.Equals("IE"))
            {
                capabillities = DesiredCapabilities.InternetExplorer();
            }
            else if (browserType.Equals("Chrome"))
            {
                capabillities = DesiredCapabilities.Chrome();
            }
            else if (browserType.Equals("Android"))
            {
                capabillities = DesiredCapabilities.Android();
            }
            else if (browserType.Equals("Ipad"))
            {
                capabillities = DesiredCapabilities.IPad();
            }
            else if (browserType.Equals("Iphone"))
            {
                capabillities = DesiredCapabilities.IPhone();
            }
            else if (browserType.Equals("Opera"))
            {
                capabillities = DesiredCapabilities.Opera();
            }
            else if (browserType.Equals("Safari"))
            {
                capabillities = DesiredCapabilities.Safari();
            }
            else if (browserType.Equals("InternetExplorer"))
            {
                capabillities = DesiredCapabilities.InternetExplorer();
            }
            else
            {
                capabillities = DesiredCapabilities.Firefox();
            }
            var browserVersion = _config.Get("BrowserVersion");

            if (!string.IsNullOrEmpty(browserVersion))
            {
                capabillities.SetCapability(CapabilityType.Version, browserVersion);
            }
            capabillities.SetCapability(CapabilityType.Platform, _config.Get("BrowserPlatform", "Windows 2008"));
            var versionName = _config.Get("AUTVersion") ?? "Test.Version";

            var buildName = _config.Get("AUTBuild") ?? "Test.Build";

            capabillities.SetCapability(Constants._NAME, _config.Get("SauceName", versionName + "/" + buildName));
            capabillities.SetCapability("username", _config.Get("SauceUserName", "autox"));
            capabillities.SetCapability("accessKey",
                                        _config.Get("SauceAccessKey", "b3842073-5a7a-4782-abbc-e7234e09f8ac"));
            capabillities.SetCapability("idle-timeout", 300);
            capabillities.SetCapability("max-duration", 3600);
            capabillities.SetCapability("command-timeout", 300);
            return(capabillities);
        }
Exemplo n.º 26
0
        public static IWebDriver OpenSauceLabWithUrl(IWebDriver driver, string strUrlToOpen, string strBrowsername, int version, Boolean OpenInNewWindow = false)
        {
            try
            {
                if (strBrowsername == "Firefox")
                {
                    DesiredCapabilities caps = DesiredCapabilities.Firefox();
                    caps.SetCapability(CapabilityType.Platform, "Windows 10");
                    caps.SetCapability(CapabilityType.Version, version);
                    caps.SetCapability("name", "PHPTravels Automation Script - SauceLab");
                    caps.SetCapability("username", "HiteshP");
                    caps.SetCapability("accessKey", "391afdbd-29eb-44e6-a89c-0c4017148b84");
                    driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                }
                else if (strBrowsername == "Chrome")
                {
                    DesiredCapabilities caps = DesiredCapabilities.Chrome();
                    caps.SetCapability(CapabilityType.Platform, "Windows 7");
                    caps.SetCapability(CapabilityType.Version, version);
                    caps.SetCapability("name", "PHPTravels Automation Script - SauceLab");
                    caps.SetCapability("username", "HiteshP");
                    caps.SetCapability("accessKey", "391afdbd-29eb-44e6-a89c-0c4017148b84");
                    driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                }
                if (strBrowsername == "IE")
                {
                    DesiredCapabilities caps = DesiredCapabilities.InternetExplorer();
                    caps.SetCapability(CapabilityType.Platform, "Windows 7");
                    caps.SetCapability(CapabilityType.Version, version);
                    caps.SetCapability("name", "PHPTravels Automation Script - SauceLab");
                    caps.SetCapability("username", "HiteshP");
                    caps.SetCapability("accessKey", "391afdbd-29eb-44e6-a89c-0c4017148b84");
                    driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                }
                if (strBrowsername == "Android")
                {
                    DesiredCapabilities caps = DesiredCapabilities.Android();
                    caps.SetCapability(CapabilityType.Platform, "Linux");
                    caps.SetCapability(CapabilityType.Version, "4.3");
                    caps.SetCapability("deviceName", "Google Nexus 7C Emulator");
                    caps.SetCapability("device-orientation", "landscape");
                    caps.SetCapability("name", "PHPTravels Automation Script - SauceLab");
                    caps.SetCapability("username", "HiteshP");
                    caps.SetCapability("accessKey", "391afdbd-29eb-44e6-a89c-0c4017148b84");
                    driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                }

                if (strBrowsername == "IOS")
                {
                    DesiredCapabilities caps = DesiredCapabilities.IPad();
                    caps.SetCapability(CapabilityType.Platform, "OS X 10.6");
                    caps.SetCapability(CapabilityType.Version, "4");
                    // caps.SetCapability("deviceName", "iPad");
                    caps.SetCapability("device-orientation", "landscape");
                    caps.SetCapability("name", "PHPTravels Automation Script - SauceLab");
                    caps.SetCapability("username", "HiteshP");
                    caps.SetCapability("accessKey", "391afdbd-29eb-44e6-a89c-0c4017148b84");
                    driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps);
                }

                driver.Navigate().GoToUrl(strUrlToOpen);

                Report.AddToHtmlReportPassed("Sauce Lab Open for '" + strUrlToOpen + "' .");
            }
            catch (Exception ex)
            {
                //Console.WriteLine("ex::", ex.Message);
                Report.AddToHtmlReportFailed(driver, ex, "Sauce Lab Open for '" + strUrlToOpen + "' .");
            }

            return(driver);
        }
Exemplo n.º 27
0
        private static void UseRemoteWebDriver()
        {
            try
            {
                if (config.Browser == "android" && config.RemoteWebDriver == "true")
                {
                    DesiredCapabilities browser = DesiredCapabilities.Android();
                    browser.SetCapability(CapabilityType.Platform, "ANDROID");
                    browser.SetCapability("webdriver.mobile.server", config.RemoteHub);
                    browser.SetCapability("browserName", config.Browser);
                    browser.SetCapability(CapabilityType.BrowserName, "android");
                    driverCache = new RemoteWebDriver(new Uri(config.RemoteHub), browser,
                                                      TimeSpan.FromSeconds(120));
                    driverCache.Navigate().GoToUrl("localhost");
                }
                else if (config.RemoteWebDriver == "saucelabs")
                {
                    try
                    {
                        DesiredCapabilities capabillities =
                            BuildDesiredCapabilities.BuildCapabilities(config.Browser, config.Platform,
                                                                       config.BrowserVersion);
                        capabillities.SetCapability("name", KomodoTestSuite.realResult.Scenario);
                        // ScenarioContext.Current["TestId"].ToString());
                        capabillities.SetCapability("username", config.RemoteUserName);
                        capabillities.SetCapability("accessKey", config.RemoteAccessKey);
                        capabillities.SetCapability("browserName", config.Browser);
                        capabillities.SetCapability("version", config.BrowserVersion);
                        capabillities.SetCapability("deviceName", config.DeviceName);
                        capabillities.SetCapability("deviceOrientation", config.DeviceOrientation);
                        capabillities.SetCapability("public", "private");
                        capabillities.SetCapability("deviceName", "");
                        capabillities.SetCapability(CapabilityType.Platform, config.Platform);

                        driverCache = new ScreenShotRemoteWebDriver(
                            new Uri(config.RemoteHub), capabillities);

                        if (config.Platform != "windows")
                        {
                            Thread.Sleep(40000);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (config.RemoteWebDriver == "browserstack")
                {
                    DesiredCapabilities capabillities = null;
                    //browserStackAutomateClient = new BrowserStackAutomateClient(config.RemoteUserName,
                    //    config.RemoteAccessKey);

                    try
                    {
                        capabillities =
                            BuildDesiredCapabilities.BuildCapabilities(config.Browser, config.Platform,
                                                                       config.BrowserVersion);
                        capabillities.SetCapability("name", KomodoTestSuite.realResult.Scenario);
                        capabillities.SetCapability("browserstack.user", config.RemoteUserName);
                        capabillities.SetCapability("browserstack.key", config.RemoteAccessKey);
                        capabillities.SetCapability(CapabilityType.AcceptSslCertificates, true);
                        capabillities.SetCapability("browserName", config.Browser);
                        capabillities.SetCapability("browser_version", config.BrowserVersion);
                        capabillities.SetCapability("device", config.DeviceName);
                        capabillities.SetCapability("deviceOrientation", config.DeviceOrientation);
                        capabillities.SetCapability("public", "private");
                        capabillities.SetCapability("deviceName", "");
                        capabillities.SetCapability("build", config.Build);
                        capabillities.SetCapability(CapabilityType.Platform, config.Platform);
                        capabillities.SetCapability("browserstack.local", config.RemoteLocalByPass);
                        capabillities.SetCapability("project", config.Environment);

                        ExecuteBrowserStackExe();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Set capabilities failed");
                        Console.WriteLine(ex.Message);
                    }



                    try
                    {
                        driverCache            = new ScreenShotRemoteWebDriver(new Uri(config.RemoteHub), capabillities);
                        config.RemoteSessionId = ((ScreenShotRemoteWebDriver)driverCache).getExecutionID();
                        var caps = ((ScreenShotRemoteWebDriver)driverCache).Capabilities;

                        //var session = browserStackAutomateClient.GetSessionAsync(config.RemoteSessionId);
                        //Console.WriteLine("-> BowserStack Session:" + session.automation_session.browser_url);

                        string[] os = { "windows xp", "windows", "any" };
                        if (!os.Contains(config.Platform.ToLower()))
                        {
                            Thread.Sleep(config.RemoteInitializeWaitTime);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Open browser failed");
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(JsonConvert.SerializeObject(config));
                    }
                }
                else if (config.RemoteWebDriver == "testingBot")
                {
                    try
                    {
                        DesiredCapabilities capabillities =
                            BuildDesiredCapabilities.BuildCapabilities(config.Browser, config.Platform,
                                                                       config.Version);

                        capabillities.SetCapability("name", ScenarioContext.Current["TestId"].ToString());
                        capabillities.SetCapability("username", config.RemoteUserName);
                        capabillities.SetCapability("accessKey", config.RemoteAccessKey);
                        capabillities.SetCapability("deviceOrientation", config.DeviceOrientation);
                        capabillities.SetCapability("deviceName", config.DeviceName);
                        capabillities.SetCapability("deviceOrientation", config.DeviceOrientation);
                        driverCache = new ScreenShotRemoteWebDriver(
                            new Uri(config.RemoteHub), capabillities);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    DesiredCapabilities capabillities =
                        BuildDesiredCapabilities.BuildCapabilities(config.Browser, config.Platform,
                                                                   config.Version);
                    driverCache = new ScreenShotRemoteWebDriver(new Uri(config.RemoteHub), capabillities);
                }
            }
            catch (WebDriverException ex)
            {
                Console.WriteLine(ex.Message);
                //throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //throw;
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Checks to see if settings for the remote driver exists.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="browserType">Type of the browser.</param>
        /// <param name="remoteWebDriver">The created remote web driver.</param>
        /// <returns><c>true</c> if the settings exist; otherwise <c>false</c>.</returns>
        private static bool RemoteDriverExists(NameValueConfigurationCollection settings, BrowserType browserType, out IWebDriver remoteWebDriver)
        {
            var remoteUri = GetRemoteDriverUri(settings);

            if (remoteUri == null)
            {
                remoteWebDriver = null;
                return(false);
            }

            DesiredCapabilities capability;

            switch (browserType)
            {
            case BrowserType.IE:
                capability = DesiredCapabilities.InternetExplorer();
                break;

            case BrowserType.FireFox:
                capability = DesiredCapabilities.Firefox();
                break;

            case BrowserType.Chrome:
                capability = DesiredCapabilities.Chrome();
                break;

            case BrowserType.Safari:
                capability = DesiredCapabilities.Safari();
                break;

            case BrowserType.Opera:
                capability = DesiredCapabilities.Opera();
                break;

            case BrowserType.Android:
                capability = DesiredCapabilities.Android();
                break;

            case BrowserType.iPhone:
                capability = DesiredCapabilities.IPhone();
                break;

            case BrowserType.iPad:
                capability = DesiredCapabilities.IPad();
                break;

            case BrowserType.PhantomJS:
                capability = DesiredCapabilities.PhantomJS();
                break;

            default:
                throw new InvalidOperationException(string.Format("Browser Type '{0}' is not supported as a remote driver.", browserType));
            }

            // Add any additional settings that are not reserved
            var reservedSettings = new[] { RemoteUrlSetting };

            foreach (var setting in settings.OfType <NameValueConfigurationElement>()
                     .Where(s => reservedSettings.All(r => !string.Equals(r, s.Name, StringComparison.OrdinalIgnoreCase))))
            {
                capability.SetCapability(setting.Name, setting.Value);
            }

            remoteWebDriver = new RemoteScreenshotWebDriver(remoteUri, capability);
            return(true);
        }
        private static IWebDriver GetDriverForSauceLabs(BrowserType browserType, string browserVersion)
        {
            const string        seleniumVersion = "";
            DesiredCapabilities capabilities;

            var          saucelabsUsername   = Configuration.Configuration.SauceLabsUsername;
            var          saucelabsAccessKey  = Configuration.Configuration.SauceLabsAccessKey;
            var          sauceLabsHubUrl     = Configuration.Configuration.SauceLabsHubUrl;
            var          nodeQueueingTimeout = TimeSpan.FromSeconds(Configuration.Configuration.CommandTimeoutSec);
            const string osPlatform          = "Windows 7";

            switch (browserType)
            {
            case BrowserType.Firefox:
                capabilities = DesiredCapabilities.Firefox();
                if (browserVersion != "default")
                {
                    capabilities.SetCapability(CapabilityType.Version, browserVersion);
                }
                capabilities.SetCapability("platform", osPlatform);
                capabilities.SetCapability("screen-resolution", "1280x1024");
                capabilities.SetCapability("selenium-version", seleniumVersion);
                break;

            case BrowserType.IE:
                capabilities = DesiredCapabilities.InternetExplorer();
                if (browserVersion != "default")
                {
                    capabilities.SetCapability(CapabilityType.Version, browserVersion);
                }
                capabilities.SetCapability("platform", osPlatform);
                capabilities.SetCapability("screen-resolution", "1280x1024");
                capabilities.SetCapability("selenium-version", seleniumVersion);
                capabilities.SetCapability("ie.ensureCleanSession", true);

                if (browserVersion == "8")
                {
                    capabilities.SetCapability("iedriverVersion", "2.45.0");
                }

                break;

            case BrowserType.Chrome:
                capabilities = DesiredCapabilities.Chrome();
                if (browserVersion != "default")
                {
                    capabilities.SetCapability(CapabilityType.Version, browserVersion);
                }
                capabilities.SetCapability("platform", osPlatform);
                var screenResolution = "1280x1024";
                // OSX only supports 1024x768
                if (osPlatform.Contains("OS X"))
                {
                    screenResolution = "1024x768";
                }

                capabilities.SetCapability("screen-resolution", screenResolution);
                capabilities.SetCapability("selenium-version", seleniumVersion);
                break;

            case BrowserType.Safari:
                capabilities = DesiredCapabilities.Safari();
                capabilities = SetSauceOsxBrowserCapabilities(capabilities, browserVersion);
                capabilities.SetCapability("screen-resolution", "1024x768");
                capabilities.SetCapability("selenium-version", seleniumVersion);
                break;

            case BrowserType.Android:
                capabilities   = DesiredCapabilities.Android();
                browserVersion = String.IsNullOrEmpty(browserVersion) ? "4.4" : browserVersion;

                if (browserVersion == "beta")
                {
                    //Sauce real device beta uses appium, max 5 devices concurrently
                    capabilities.SetCapability("platformName", "Android");
                    capabilities.SetCapability("deviceName", "Samsung Galaxy S4 Device");
                    capabilities.SetCapability("platformVersion", "4.3");
                    capabilities.SetCapability("browserName", "Chrome");
                }
                else
                {
                    // We are using Selendroid with Sauce Connect
                    capabilities.SetCapability("platform", "Linux");
                    capabilities.SetCapability("version", browserVersion);
                    capabilities.SetCapability("deviceName", "Android Emulator");
                    capabilities.SetCapability("browserName", "Android");
                    capabilities.SetCapability("javascriptEnabled", true);
                }

                capabilities.SetCapability("appium-version", "");
                capabilities.SetCapability("device-orientation", "portrait");
                capabilities.SetCapability("newCommandTimeout", "60");

                break;

            case BrowserType.iPhone:
                capabilities   = DesiredCapabilities.IPhone();
                browserVersion = String.IsNullOrEmpty(browserVersion) ? "7.1" : browserVersion;
                capabilities.SetCapability("platformName", "iOS");
                capabilities.SetCapability("platformVersion", browserVersion);
                capabilities.SetCapability("browserName", "safari");
                capabilities.SetCapability("deviceName", "iPhone Simulator");
                capabilities.SetCapability("device-orientation", "portrait");
                capabilities.SetCapability("appium-version", "");
                capabilities.SetCapability("newCommandTimeout", "180");
                capabilities.SetCapability("safariAllowPopups", "true");
                break;

            case BrowserType.iPad:
                capabilities   = DesiredCapabilities.IPad();
                browserVersion = String.IsNullOrEmpty(browserVersion) ? "7.1" : browserVersion;
                capabilities.SetCapability("platformName", "iOS");
                capabilities.SetCapability("platformVersion", browserVersion);
                capabilities.SetCapability("browserName", "safari");
                capabilities.SetCapability("deviceName", "iPad Simulator");
                capabilities.SetCapability("device-orientation", "landscape");
                capabilities.SetCapability("safariAllowPopups", "true");
                capabilities.SetCapability("newCommandTimeout", "180");
                capabilities.SetCapability("appium-version", "");
                break;

            default:
                throw new ArgumentException("Unrecognised browser choice '" + browserType +
                                            "' when initialising driver for Saucelabs.");
            }

            // NOTE: Increasing the command-timeout from 180 to 300 due to persistent VM timeouts during periods of high concurrency.
            capabilities.SetCapability("command-timeout", 300);

            capabilities.SetCapability("idle-timeout", 180);
            capabilities.SetCapability("locationContextEnabled", false);
            capabilities.SetCapability("username", saucelabsUsername);
            capabilities.SetCapability("accessKey", saucelabsAccessKey);

            capabilities = ConfigureSauceLabsTunnel(capabilities);

            capabilities.SetCapability("name", ScenarioContext.Current.ScenarioInfo.Title);
            capabilities.SetCapability("tags", ScenarioContext.Current.ScenarioInfo.Tags);

            var driver = new SauceLabsDriver(
                new Uri(sauceLabsHubUrl),
                capabilities,
                nodeQueueingTimeout);

            SaucelabsJobId = driver.JobId.ToString();

            return(driver);
        }
Exemplo n.º 30
0
        public void DebugBSMobile(string strMobileDevice)
        {
            Config            = true;
            configurationbool = true;

            if (strMobileDevice == browsertype.android.ToString())
            {
                // ********************** sauce lab capabilities start **********************

                //Thread.Sleep(4000);
                //devicenameBS = ConfigurationManager.AppSettings.Get("androiddeviceNameBS");
                //this.deviceNameAndroid = ConfigurationManager.AppSettings.Get("androiddevice");
                //this.environment = ConfigurationManager.AppSettings.Get("environment");
                //DesiredCapabilities capability = DesiredCapabilities.Android();
                //capability.SetCapability("browserName", "Chrome");
                //capability.SetCapability("platformVersion", "6.1");
                //capability.SetCapability(MobileCapabilityType.BrowserName, MobileBrowserType.Chrome);
                //capability.SetCapability("username", "Sunil21318"); // supply sauce labs username
                //capability.SetCapability("accessKey", "d056215a-a397-414c-923f-e42e0be236b6");  // supply sauce labs account key
                //capability.SetCapability("deviceName", "Android Emulator");
                //capability.SetCapability("tunnel-identifier", Environment.GetEnvironmentVariable("TRAVIS_JOB_NUMBER"));
                //capability.SetCapability("build", Environment.GetEnvironmentVariable("TRAVIS_BUILD_NUMBER"));
                //capability.SetCapability("deviceReadyTimeout", TimeSpan.FromSeconds(120));
                //capability.SetCapability("androidDeviceReadyTimeout", TimeSpan.FromSeconds(120));
                //capability.SetCapability("avdLaunchTimeout", TimeSpan.FromSeconds(120));
                //capability.SetCapability("appWaitDuration", TimeSpan.FromSeconds(120));
                //capability.SetCapability("avdReadyTimeout", TimeSpan.FromSeconds(120));
                //capability.SetCapability("idleTimeout", 120);
                //driver = new RemoteWebDriver(new Uri("http://*****:*****@ondemand.saucelabs.com/wd/hub"), capability, TimeSpan.FromSeconds(120));
                //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(200));
                //driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(200));

                // ********************** sauce lab capabilities end **********************



                //  ********************** browser stack capabilities start **********************

                Browser = "Chrome";
                Env     = "Android";

                devicenameBS           = ConfigurationManager.AppSettings.Get("androiddeviceNameBS");
                this.deviceNameAndroid = ConfigurationManager.AppSettings.Get("androiddevice");
                this.environment       = ConfigurationManager.AppSettings.Get("environment");
                DesiredCapabilities capability = DesiredCapabilities.Android();
                ChromeOptions       chrOpts    = new ChromeOptions();
                chrOpts.AddArguments("test-type");
                chrOpts.AddArguments("--disable-extensions");
                chrOpts.AddArgument("incognito");
                chrOpts.AddArgument("no-sandbox");
                capability = (DesiredCapabilities)chrOpts.ToCapabilities();
                capability.SetCapability("browserName", "android");
                capability.SetCapability("browserstack.user", browserstack_user); // browser stack username
                capability.SetCapability("browserstack.key", browserstack_key);   // browser stack account key
                capability.SetCapability("deviceName", devicenameBS);
                capability.SetCapability("browserName", "chrome");
                capability.SetCapability("platform", MobilePlatform.Android);
                capability.SetCapability("browserstack.debug", true);
                capability.SetCapability("project", Environment.GetEnvironmentVariable("BS_AUTOMATE_PROJECT"));
                capability.SetCapability("build", Environment.GetEnvironmentVariable("BS_AUTOMATE_BUILD"));
                capability.SetCapability("browserstack.localIdentifier", Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER"));
                capability.SetCapability("deviceReadyTimeout", TimeSpan.FromSeconds(200));
                capability.SetCapability("androidDeviceReadyTimeout", TimeSpan.FromSeconds(200));
                capability.SetCapability("avdLaunchTimeout", TimeSpan.FromSeconds(200));
                capability.SetCapability("appWaitDuration", TimeSpan.FromSeconds(200));
                capability.SetCapability("avdReadyTimeout", TimeSpan.FromSeconds(200));
                capability.SetCapability("idleTimeout", 300);
                driver = new RemoteWebDriver(new Uri(ConfigurationManager.AppSettings.Get("server")), capability, TimeSpan.FromSeconds(200));
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(200));

                // ********************** browser stack capabilities end **********************
            }
            else if (strMobileDevice == browsertype.ios.ToString())
            {
                Browser = "Safari";
                Env     = "IOS";
                Thread.Sleep(4000);
                devicenameBS           = ConfigurationManager.AppSettings.Get("iosdeviceNameBS");
                this.deviceNameAndroid = ConfigurationManager.AppSettings.Get("iosdevice");
                this.environment       = ConfigurationManager.AppSettings.Get("environment");
                DesiredCapabilities desiredCap = DesiredCapabilities.IPhone();
                desiredCap.SetCapability("browserstack.user", browserstack_user);
                desiredCap.SetCapability("browserstack.key", browserstack_key);
                desiredCap.SetCapability("platform", "MAC");
                desiredCap.SetCapability("browserName", "iPhone");
                desiredCap.SetCapability("browserstack.debug", true);
                desiredCap.SetCapability("device", devicenameiphone);
                desiredCap.SetCapability("project", Environment.GetEnvironmentVariable("BS_AUTOMATE_PROJECT"));
                desiredCap.SetCapability("build", Environment.GetEnvironmentVariable("BS_AUTOMATE_BUILD"));
                desiredCap.SetCapability("browserstack.localIdentifier", Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER"));
                desiredCap.SetCapability("newCommandTimeout", TimeSpan.FromSeconds(120));
                desiredCap.SetCapability("idleTimeout", TimeSpan.FromSeconds(120));
                driver = new RemoteWebDriver(new Uri(ConfigurationManager.AppSettings.Get("server")), desiredCap, TimeSpan.FromSeconds(120));
                // driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(200));
            }
        }