示例#1
0
        /*
         * --dll="../../../iSIMSAddStudent/bin/debug/iSIMSSearchStudent.dll" --hub=http://bedcsscmssl01:4444/wd/hub  --reporter="C:\WIP\SIMS 8 UK\Src\iSIMSSeleniumTestFrameWork\HtmlReport\bin\Debug\HtmlReport.dll" --maxThreads=15 --output="c:/report"
         */
        static int Main(string[] args)
        {
            Environment.Initialise(new WebDriverRunner.webdriver.WebContext(), new TestRunner.SeSugar.SeSettings(), new TestRunner.SeSugar.SeLogger());

            Configuration config = null;
            Runner        runner = null;

            try
            {
                config = Configuration.Create(args);

                Environment.Settings.AutomatedRunId = config.AutomatedRunId;
                Environment.Settings.SeleneApiUrl   = config.SeleneApiUrl;

                bool scanWasAlreadyRunning = config.SecurityScan && Zap.IsRunning(config.ProxyOverride);
                if (!scanWasAlreadyRunning)
                {
                    startSecurityScan(config);
                }

                // Now run the tests
                runner = new Runner(config);
                runner.LoadTests();
                runner.RunTests();
                runner.GenerateReports();

                stopSecurityScanAndGenerateReport(config, scanWasAlreadyRunning);

                // Return the exit code
                return(runner.GetExitCode());
            }
            catch (System.Exception e)
            {
                lock (ConsoleLock.WriterLock)
                {
                    if (config != null)
                    {
                        WriteErrorToConsole(e);
                        WriteErrorToFile(config, e);
                    }
                    else
                    {
                        WriteErrorToConsole(e);
                        WriteErrorToConsole(
                            new System.Exception("There was an issue with the configuration parameters. Please check them."));
                    }
                }
                return((int)WebDriverRunner.Runner.ExitCode.UnknownError);
            }
            finally
            {
                if (config != null && config.PauseOnExit)
                {
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadLine();
                }
            }
        }
示例#2
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);
        }
示例#3
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);
        }