Ejemplo n.º 1
0
 public override void OnTestStart(TestMethodInstance instance, ITestResult result)
 {
     if (instance.Attr.GetType() == typeof(BeforeSuiteWebTestAttribute))
     {
         SetUpAndStartBrowsers(instance, result);
     }
 }
Ejemplo n.º 2
0
 public override void OnTestFinished(TestMethodInstance instance, ITestResult result)
 {
     if (instance.Attr.GetType() == typeof(BeforeSuiteWebTestAttribute))
     {
         CloseBrowser(WebContext.WebDriver);
     }
 }
Ejemplo n.º 3
0
        public override void OnTestPassed(TestMethodInstance instance, ITestResult result)
        {
            GetTimer().Stop();
            var md = instance.GetMetadata();

            WriteTestOutcome(instance, "PASSED", ConsoleColor.Green);
        }
Ejemplo n.º 4
0
        public override void OnTestSkipped(TestMethodInstance instance, ITestResult result)
        {
            GetTimer().Stop();
            if (result.Exception != null)
            {
                StringBuilder exceptionText = new StringBuilder();
                exceptionText.AppendFormat("{1} EXCEPTION:  {0}", result.Exception.GetType().Name, Environment.NewLine);
                if (result.Exception.Message != null)
                {
                    exceptionText.AppendFormat("{1} MESSAGE:    {0}", result.Exception.Message, Environment.NewLine);
                }
                if (result.Exception.Source != null)
                {
                    exceptionText.AppendFormat("{1} SOURCE:     {0}", result.Exception.Source, Environment.NewLine);
                }

                if (result.Exception.GetType().Name == "InconclusiveException")
                {
                    WriteTestOutcome(instance, "INCONCLUSIVE", ConsoleColor.Yellow, additional: exceptionText.ToString());
                }
                else
                {
                    WriteTestOutcome(instance, "SKIPPED", ConsoleColor.DarkMagenta, additional: exceptionText.ToString());
                }
            }
            else
            {
                WriteTestOutcome(instance, "SKIPPED", ConsoleColor.DarkMagenta);
            }
        }
Ejemplo n.º 5
0
 public override void OnTestFailed(TestMethodInstance instance, ITestResult result)
 {
     if (instance.Attr.GetType() == typeof(BeforeSuiteWebTestAttribute))
     {
         WebContext.Screenshot();
     }
 }
Ejemplo n.º 6
0
 public WebDriverContext(IWebDriver driver, TestMethodInstance instance, ITestResult result, string output)
 {
     Driver   = driver;
     Instance = instance;
     Result   = result;
     Output   = output;
 }
Ejemplo n.º 7
0
 public override void OnTestFinished(TestMethodInstance instance, ITestResult result)
 {
     if (instance.Attr.GetType() == typeof(BeforeSuiteWebTestAttribute))
     {
         (WebContext.WebDriver as IJavaScriptExecutor).ExecuteScript("window.onbeforeunload = null;");
         WebContext.WebDriver.Quit();
     }
 }
Ejemplo n.º 8
0
        public override void OnTestStart(TestMethodInstance instance, ITestResult result)
        {
            var timer = GetTimer();

            timer.Reset();

            ReportToSeleneSync(instance, result, SeleneApiEndpoints.TestStarted, GetTimer().Elapsed, this.Configuration);

            timer.Start();
        }
Ejemplo n.º 9
0
 public override void OnTestFinished(TestMethodInstance instance, ITestResult result)
 {
     if (instance.Attr.GetType() == typeof(WebDriverTestAttribute) ||
         instance.Attr.GetType() == typeof(ChromeUiTestAttribute) ||
         instance.Attr.GetType() == typeof(IeUiTestAttribute) ||
         instance.Attr.GetType() == typeof(AllBrowserUiTestAttribute)
         )
     {
         CloseBrowser(WebContext.WebDriver);
     }
 }
Ejemplo n.º 10
0
 public override void OnTestFailed(TestMethodInstance instance, ITestResult result)
 {
     if (instance.Attr.GetType() == typeof(WebDriverTestAttribute) ||
         instance.Attr.GetType() == typeof(ChromeUiTestAttribute) ||
         instance.Attr.GetType() == typeof(IeUiTestAttribute) ||
         instance.Attr.GetType() == typeof(AllBrowserUiTestAttribute)
         )
     {
         Screenshot();
     }
 }
Ejemplo n.º 11
0
 public override void OnTestStart(TestMethodInstance instance, ITestResult result)
 {
     if (instance.Attr.GetType() == typeof(WebDriverTestAttribute) ||
         instance.Attr.GetType() == typeof(ChromeUiTestAttribute) ||
         instance.Attr.GetType() == typeof(IeUiTestAttribute) ||
         instance.Attr.GetType() == typeof(AllBrowserUiTestAttribute)
         )
     {
         SetUpAndStartBrowsers(instance, result);
     }
 }
Ejemplo n.º 12
0
 private void Screenshot(TestMethodInstance instance)
 {
     if (instance.Attr.GetType() == typeof(BeforeSuiteWebTestAttribute))
     {
         try
         {
             WebContext.Screenshot();
         }
         catch (Exception e)
         {
             Reporter.Log("Couldn't take screenshot " + e.Message);
         }
     }
 }
Ejemplo n.º 13
0
        public override void OnTestStart(TestMethodInstance instance, ITestResult result)
        {
            if (instance.Attr.GetType() == typeof(BeforeSuiteWebTestAttribute))
            {
                DesiredCapabilities cap;
                var    browser     = instance.GetMetadata(WebContext.BrowserKey) as string;
                string userDataDir = instance.Attr.UserDataDir;
                if (browser.Equals("chrome"))
                {
                    var options = new ChromeOptions();
                    options.AddArgument("--explicitly-allowed-ports=95");
                    options.AddArgument("--lang=en-gb");
                    if (userDataDir != null)
                    {
                        options.AddArguments("--user-data-dir=" + userDataDir);
                    }
                    cap = options.ToCapabilities() as DesiredCapabilities;
                }
                else
                {
                    cap = DesiredCapabilities.InternetExplorer();
                    cap.SetCapability("nativeEvents", false);
                }


                var domainuser = WindowsIdentity.GetCurrent() == null
                    ? null
                    : WindowsIdentity.GetCurrent().Name;

                char[] delimiterChars = { '\\' };
                var    words          = domainuser.Split(delimiterChars);
                var    user           = words[1];
                cap.SetCapability("user", user);
                cap.SetCapability("method", instance.ToString());
                IWebDriver driver = new RemoteWebDriver(Configuration.Hub, cap);
                if (driver != null)
                {
                    driver.Manage().Window.Size = new Size(1280, 1024);
                    var webDriverContext = new WebDriverContext(driver, instance, result,
                                                                Configuration.Output);
                    WebContext.Set(webDriverContext);
                    instance.SetMetadata(WebContext.BrowserKey, browser);
                }
            }
        }
Ejemplo n.º 14
0
 public override void OnTestSkipped(TestMethodInstance instance, ITestResult result)
 {
     GetTimer().Stop();
     if (result.Exception != null)
     {
         if (result.Exception.GetType().Name == "InconclusiveException")
         {
             ReportToSeleneSync(instance, result, SeleneApiEndpoints.TestInconclusive, GetTimer().Elapsed, this.Configuration, true);
         }
         else
         {
             ReportToSeleneSync(instance, result, SeleneApiEndpoints.TestSkipped, GetTimer().Elapsed, this.Configuration, true);
         }
     }
     else
     {
         ReportToSeleneSync(instance, result, SeleneApiEndpoints.TestSkipped, GetTimer().Elapsed, this.Configuration);
     }
 }
Ejemplo n.º 15
0
        public override void OnTestStart(TestMethodInstance instance, ITestResult result)
        {
            lock (ConsoleLock.WriterLock)
            {
                Console.WriteLine();
                Console.WriteLine("-------------------------------------------------------------------------------");
                Console.BackgroundColor = ConsoleColor.DarkGray;
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(" STARTED ");
                Console.ResetColor();
                Console.WriteLine();
                Console.WriteLine("{0} TEST:       {1}{0} ASSEMBLY:   {2}", Environment.NewLine, instance, instance.GetMethod().Module.Assembly.GetName().Name);
                Console.WriteLine("-------------------------------------------------------------------------------");
                Console.WriteLine();
            }

            var timer = GetTimer();

            timer.Reset();
            timer.Start();
        }
Ejemplo n.º 16
0
        private void WriteTestOutcome(TestMethodInstance instance, string message, ConsoleColor backgroundColour, ConsoleColor foregroundColour = ConsoleColor.Black, string additional = null)
        {
            lock (SeleneLock.WriterLock)
            {
                Console.WriteLine();
                Console.WriteLine("-------------------------------------------------------------------------------");
                Console.BackgroundColor = backgroundColour;
                Console.ForegroundColor = foregroundColour;
                Console.Write(" {0} ", message);
                Console.ResetColor();
                Console.WriteLine();
                Console.WriteLine("{0} TEST:       {1}{0} ASSEMBLY:   {2}{0} TIME TAKEN: {3}", Environment.NewLine, instance, instance.GetMethod().Module.Assembly.GetName().Name, GetTimer().Elapsed);

                if (additional != null)
                {
                    Console.WriteLine(additional);
                }

                Console.WriteLine("-------------------------------------------------------------------------------");
                Console.WriteLine();
            }
        }
Ejemplo n.º 17
0
        public override void OnTestFailed(TestMethodInstance instance, ITestResult result)
        {
            GetTimer().Stop();

            if (result.Exception != null)
            {
                StringBuilder exceptionText = new StringBuilder();
                exceptionText.AppendFormat("{1} EXCEPTION:  {0}", result.Exception.GetType().Name, Environment.NewLine);
                if (result.Exception.Message != null)
                {
                    exceptionText.AppendFormat("{1} MESSAGE:    {0}", result.Exception.Message, Environment.NewLine);
                }
                if (result.Exception.Source != null)
                {
                    exceptionText.AppendFormat("{1} SOURCE:     {0}", result.Exception.Source, Environment.NewLine);
                }
                WriteTestOutcome(instance, "FAILED", ConsoleColor.Red, additional: exceptionText.ToString());
            }
            else
            {
                WriteTestOutcome(instance, "FAILED", ConsoleColor.Red);
            }
        }
Ejemplo n.º 18
0
        static async Task ReportToSeleneAsync(TestMethodInstance instance, ITestResult result, string apiPath, TimeSpan timeTaken, Configuration config, bool reportException)
        {
            using (var client = new SeleneApiClient(config.SeleneApiUrl))
            {
                var browserObj = instance.GetMetadata("browser");
                var browser    = browserObj != null?browserObj.ToString() : string.Empty;

                TestInfo test = new TestInfo
                {
                    Assembly       = instance.GetMethod().Module.Assembly.GetName().Name,
                    AssemblyRunId  = config.AssemblyRunId,
                    AutomatedRunId = config.AutomatedRunId,
                    Team           = config.Team,
                    Test           = instance.GetMethod().Name,
                    Timestamp      = DateTime.Now,
                    TimeTaken      = timeTaken != null ? timeTaken : TimeSpan.FromMilliseconds(0),
                    Notification   = apiPath.Split('/')[1],
                    Id             = instance.TestId,
                    Browser        = browser == "chrome" ? "Chrome" : browser == "internet explorer" ? "IE" : string.Empty
                };

                if (reportException && result.Exception != null)
                {
                    test.ExceptionName    = result.Exception.GetType().Name;
                    test.ExceptionMessage = result.Exception.Message;
                    test.ExceptionSource  = result.Exception.Source;
                }
                else
                {
                    test.ExceptionName = test.ExceptionMessage = test.ExceptionSource = string.Empty;
                }

                HttpResponseMessage response = await client.PostAsJsonAsync(apiPath, test);

                SeSugar.Environment.Logger.LogLine("Call to Selene {0} responded with {1} ({2}).", apiPath, response.StatusCode, (int)response.StatusCode);
            }
        }
Ejemplo n.º 19
0
 public override void OnTestFinished(TestMethodInstance instance, ITestResult result)
 {
     CloseBrowser(WebContext.WebDriver);
 }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
 static void ReportToSeleneSync(TestMethodInstance instance, ITestResult result, string apiPath, TimeSpan timeTaken, Configuration config, bool reportException = false)
 {
     AsyncHelpers.RunSync(() => ReportToSeleneAsync(instance, result, apiPath, timeTaken, config, reportException));
 }
Ejemplo n.º 22
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.º 23
0
 public override void OnTestFailed(TestMethodInstance instance, ITestResult result)
 {
     GetTimer().Stop();
     ReportToSeleneSync(instance, result, SeleneApiEndpoints.TestFailed, GetTimer().Elapsed, this.Configuration, true);
 }
Ejemplo n.º 24
0
 public override void OnTestFinished(TestMethodInstance instance, ITestResult result)
 {
 }
Ejemplo n.º 25
0
        public void SetUpAndStartBrowsers(TestMethodInstance instance, ITestResult result)
        {
            // Check the proxy settings
            Proxy useProxy = null;

            if (!string.IsNullOrEmpty(Configuration.ProxyOverride))
            {
                string proxy = Configuration.ProxyOverride;
                useProxy              = new Proxy();
                useProxy.HttpProxy    = proxy;
                useProxy.FtpProxy     = proxy;
                useProxy.SslProxy     = proxy;
                useProxy.IsAutoDetect = false;
                useProxy.Kind         = ProxyKind.Manual;
            }
            // Now set the browser capabilities/options
            DesiredCapabilities cap;
            var    browser     = instance.GetMetadata(WebContext.BrowserKey) as string;
            string userDataDir = instance.Attr.UserDataDir;

            if (browser.Equals("chrome"))
            {
                ChromeOptions options = new ChromeOptions();
                options.SetLoggingPreference(LogType.Browser, LogLevel.All);
                options.AddArgument("--incognito");
                options.AddArgument("--explicitly-allowed-ports=95");
                options.AddArgument("--lang=en-GB");
                options.AddArgument("--disable-popup-blocking");
                options.AddArgument("--disable-extensions");
                options.AddArgument("--enable-javascript");
                options.AddArgument("--disable-web-security");
                options.AddArgument("--disable-plugins");
                options.AddArgument("--start-maximized");
                options.AddArgument("--enable-logging");
                options.AddArgument("--allow-running-insecure-content");
                options.AddArgument("--javascript-harmony");
                if (userDataDir != null)
                {
                    options.AddArguments("--user-data-dir=" + userDataDir);
                }
                if (useProxy != null)
                {
                    options.Proxy = useProxy;
                }
                cap = options.ToCapabilities() as DesiredCapabilities;
            }
            else
            {
                // Please think carefully before changeing this
                //https://code.google.com/p/selenium/wiki/InternetExplorerDriver
                InternetExplorerOptions IEOptions = new InternetExplorerOptions();
                IEOptions.UsePerProcessProxy = true;
                if (useProxy != null)
                {
                    IEOptions.Proxy = useProxy;
                }
                cap = IEOptions.ToCapabilities() as DesiredCapabilities;
                //cap = DesiredCapabilities.InternetExplorer();
                cap.SetCapability("nativeEvents", true);
                cap.SetCapability("ignoreZoomSetting", true);
            }


            var domainuser = WindowsIdentity.GetCurrent() == null
                ? null
                : WindowsIdentity.GetCurrent().Name;

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

            cap.SetCapability("user", user);
            cap.SetCapability("method", instance.ToString());
            IWebDriver driver = new RemoteWebDriver(Configuration.Hub, cap, Configuration.BrowserResponseTimeout);

            {
                WebDriverContext webDriverContext = new WebDriverContext(driver, instance, result,
                                                                         Configuration.Output);
                WebContext.Set(webDriverContext);
                instance.SetMetadata(WebContext.BrowserKey, browser);
            }

            driver.Manage().Window.Maximize();
        }
Ejemplo n.º 26
0
 public virtual void OnTestSkipped(TestMethodInstance instance, ITestResult result)
 {
 }
Ejemplo n.º 27
0
 public override void OnTestSkipped(TestMethodInstance instance, ITestResult result)
 {
 }
Ejemplo n.º 28
0
 public virtual void OnTestFinished(TestMethodInstance instance, ITestResult result)
 {
 }
Ejemplo n.º 29
0
 public UnitTestResult(TestMethodInstance instance)
 {
     _watch.Start();
     Instance = instance;
     _uuid    = Guid.NewGuid().ToString();
 }