Ejemplo n.º 1
0
        public IWebDriver RunOnRemoteMachine()
        {
            // TODO: Take this setting from TestContext
            Configuration.SystemUnderTest = TestDefaults.Default.DefaultSystemUnderTest;// Configuration.lab_five;

            Environment.Initialise(new WebContext(), new SeSettings(), new SeLogger());
            string className = testContext.FullyQualifiedTestClassName;
            string testName  = testContext.TestName;
            // NOTE: You might have to use AppDomain.CurrentDomain.GetAssemblies() and then call GetTypes on each assembly if this code
            //       resides in a baseclass in another assembly.
            Type       currentlyRunningClassType = instance.GetType().Assembly.GetTypes().FirstOrDefault(f => f.FullName == className);
            MethodInfo currentlyRunningMethod    = currentlyRunningClassType.GetMethod(testName);
            // Replace WorkItemAttribute with whatever your attribute is called...
            IEnumerable <WebDriverTestAttribute> webDriverAttributes = currentlyRunningMethod.GetCustomAttributes(typeof(WebDriverTestAttribute), true) as IEnumerable <WebDriverTestAttribute>;
            WebDriverTestAttribute webDriverAttr = webDriverAttributes.FirstOrDefault();
            string browserName = webDriverAttr.Browsers[0];

            if (String.IsNullOrEmpty(browserName))
            {
                if (webDriverAttr is ChromeUiTestAttribute)
                {
                    browserName = BrowserDefaults.Chrome;
                }
                else if (webDriverAttr is IeUiTestAttribute)
                {
                    browserName = BrowserDefaults.Ie;
                }
                //                else if (webDriverAttr is )
                //                    browserName = BrowserDefaults.Firefox;
                //                else if (webDriverAttr is )
                //                    browserName = BrowserDefaults.Firefox;
            }
            Assert.IsNotNull(browserName, "No browser name");

            // Set the user
            string domainuser = WindowsIdentity.GetCurrent() == null
                ? null
                : WindowsIdentity.GetCurrent().Name;

            char[] delimiterChars    = { '\\' };
            var    words             = domainuser.Split(delimiterChars);
            var    user              = words[1];
            DesiredCapabilities caps = null;

            BrowserManager manager = new BrowserManager(webDriverAttr);
            Proxy          proxy   = manager.CheckAndSetUpProxy();

            caps = manager.ChooseRequiredBrowser(caps, browserName, proxy);

            // Set common capabilities
            caps.SetCapability("user", user);
            caps.SetCapability("method", testName);
            //Set BrowserStack Details
            caps.SetCapability("os", BrowserStack.Default.OsName);            //eg. "Windows"
            caps.SetCapability("os_version", BrowserStack.Default.OsVersion); // eg. "7"
            caps.SetCapability("browser", BrowserStack.Default.BrowserName);
            caps.SetCapability("browser_version", BrowserStack.Default.BrowserVersion);
            caps.SetCapability("project", BrowserStack.Default.ProjectName);
            caps.SetCapability("resolution", BrowserStack.Default.ScreenResolution); //1280x1024
            caps.SetCapability("browserstack.user", BrowserStack.Default.BrowserStackUser);
            caps.SetCapability("browserstack.key", BrowserStack.Default.BrowserStackKey);
            caps.SetCapability("browserstack.debug", "true");
            caps.SetCapability("build", "EdwinSmokeTest");
            caps = this.SetExtraBrowserStackCaps(caps, browserName);
            // Create the test method instance
            TestMethodInstance testMethodInstance = new TestMethodInstance(webDriverAttr,
                                                                           new Dictionary <string, object>(), null, instance, currentlyRunningMethod);
            // And a result
            ITestResult result = new UnitTestResult(testMethodInstance);

            var        stackUrl = new Uri(BrowserStack.Default.BrowserStackHub);
            IWebDriver driver   = new RemoteWebDriver(stackUrl, caps, configuration.BrowserResponseTimeout);

            {
                WebDriverContext webDriverContext = new WebDriverContext(driver, testMethodInstance, result, configuration.Output);
                WebContext.Set(webDriverContext);
                testMethodInstance.SetMetadata(WebContext.BrowserKey, browserName);
            }
            return(driver);
        }
Ejemplo n.º 2
0
        public IWebDriver RunOnCurrentMachine()
        {
            // TODO: Take this setting from TestContext
            Configuration.SystemUnderTest = TestDefaults.Default.DefaultSystemUnderTest;// Configuration.lab_five;

            Environment.Initialise(new WebContext(), new SeSettings(), new SeLogger());
            string className = testContext.FullyQualifiedTestClassName;
            string testName  = testContext.TestName;
            // NOTE: You might have to use AppDomain.CurrentDomain.GetAssemblies() and then call GetTypes on each assembly if this code
            //       resides in a baseclass in another assembly.
            Type       currentlyRunningClassType = instance.GetType().Assembly.GetTypes().FirstOrDefault(f => f.FullName == className);
            MethodInfo currentlyRunningMethod    = currentlyRunningClassType.GetMethod(testName);
            // Replace WorkItemAttribute with whatever your attribute is called...
            IEnumerable <WebDriverTestAttribute> webDriverAttributes = currentlyRunningMethod.GetCustomAttributes(typeof(WebDriverTestAttribute), true) as IEnumerable <WebDriverTestAttribute>;
            WebDriverTestAttribute webDriverAttr = webDriverAttributes.FirstOrDefault();
            string browserName = webDriverAttr.Browsers[0];

            if (String.IsNullOrEmpty(browserName))
            {
                if (webDriverAttr is ChromeUiTestAttribute)
                {
                    browserName = BrowserDefaults.Chrome;
                }
                else if (webDriverAttr is IeUiTestAttribute)
                {
                    browserName = BrowserDefaults.Ie;
                }
            }
            Assert.IsNotNull(browserName, "No browser name");

            // Set the user
            string domainuser = WindowsIdentity.GetCurrent() == null
                ? null
                : WindowsIdentity.GetCurrent().Name;

            char[] delimiterChars    = { '\\' };
            var    words             = domainuser.Split(delimiterChars);
            var    user              = words[1];
            DesiredCapabilities caps = null;

            BrowserManager manager = new BrowserManager(webDriverAttr);
            Proxy          proxy   = manager.CheckAndSetUpProxy();

            caps = manager.ChooseRequiredBrowser(caps, browserName, proxy);
            // Set common capabilities
            caps.SetCapability("user", user);
            caps.SetCapability("method", testName);



            // Now sort out the driver
//            IEnumerable<object[]> param = FindParameters(instance, currentlyRunningMethod, webDriverAttr);
//
//            // do the param fit in the method ?
//            IEnumerable<object[]> enumerable = param as IList<object[]> ?? param.ToList();



            // Create the test method instance
            TestMethodInstance testMethodInstance = new TestMethodInstance(webDriverAttr,
                                                                           new Dictionary <string, object>(), null, instance, currentlyRunningMethod);

            // And a result
            ITestResult result = new UnitTestResult(testMethodInstance);


            // Now run the remote web driver based on all the parameters
            IWebDriver driver = new RemoteWebDriver(configuration.Hub, caps, configuration.BrowserResponseTimeout);

            {
                WebDriverContext webDriverContext = new WebDriverContext(driver, testMethodInstance, result,
                                                                         configuration.Output);
                WebContext.Set(webDriverContext);
                testMethodInstance.SetMetadata(WebContext.BrowserKey, browserName);
            }
            return(driver);
        }