/// <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)
		{
			//What browser to test on?s
			IWebDriver webDriver;
			switch (browser.Browserstring.ToLowerInvariant())
			{
				case "firefox":
					var firefoxProfile = new FirefoxProfile();
					firefoxProfile.SetPreference("intl.accept_languages", languageCode);
					webDriver = new FirefoxDriver(firefoxProfile);
					break;
				case "chrome":
					ChromeOptions chromeOptions = new ChromeOptions();
					chromeOptions.AddArguments("--test-type", "--disable-hang-monitor", "--new-window", "--no-sandbox", "--lang=" + languageCode);
					webDriver = new ChromeDriver(chromeOptions);
					break;
				case "internet explorer":
					webDriver = new InternetExplorerDriver(new InternetExplorerOptions { BrowserCommandLineArguments = "singleWindow=true", IntroduceInstabilityByIgnoringProtectedModeSettings = true, EnsureCleanSession = true, EnablePersistentHover = false });
					break;
				case "phantomjs":
					webDriver = new PhantomJSDriver(new PhantomJSOptions() {});
					break;
				default:
					throw new NotSupportedException("Not supported browser");
			}

			return webDriver;
		}
Esempio n. 2
0
        private TestResult HandleTest(WorkItem workItem)
        {
            TestResult    testResult = new TestResult();
            ITestable     testable   = null;
            List <string> log        = new List <string>();

            try
            {
                log.Add("Test on " + _nodename);

                /**1: Load Testclass **/
                Console.WriteLine(@"Testing {0} {1} ({2}/{3})", workItem.Testcase.Name, workItem.Browser.Name, workItem.Testsystem.Name, workItem.Language.Languagecode);
                testable = LoadTestable(workItem);
                if (testable == null)
                {
                    return new TestResult {
                               TestState = TestState.NotAvailable
                    }
                }
                ;

                /**2: Wait for branch get ready **/
                WaitOnWebExceptions(workItem);

                /**3: Prepare Test **/
                Browser browser = new Browser()
                {
                    Browserstring  = workItem.Browser.Browserstring,
                    Versionsstring = workItem.Browser.Versionsstring
                };
                testable.SetupTest(WebDriverInitStrategy.SeleniumLocal, browser, workItem.Testsystem.Url,
                                   workItem.Language.Languagecode);

                /**4: Run Test **/
                testable.Test();

                testResult.TestState = TestState.Success;
            }
            catch (NotSupportedException notSupportedException)
            {
                Error error = CreateErrorFromException(notSupportedException);
                testResult.TestState = TestState.NotSupported;
                testResult.Error     = error;
            }
            catch (TaskCanceledException taskCanceledException)
            {
                Error error = CreateErrorFromException(taskCanceledException);
                testResult.TestState = TestState.Canceled;
                testResult.Error     = error;
            }
            catch (Exception exception)
            {
                ServerErrorModel serverException = null;
                try
                {
                    if (testable != null)
                    {
                        serverException = testable.CheckForServerError();
                    }
                }
                catch
                {
                    //Error catching serverException
                }
                Error error = CreateErrorFromException(exception);
                if (serverException != null)
                {
                    error.Type = serverException.Type;

                    error.Message        = serverException.Message;
                    error.InnerException = serverException.InnerException;
                    //objError.StackTrace = serverException.StackTrace; Keep error stacktrace.
                }
                testResult.TestState = TestState.Error;
                testResult.Error     = error;
                if (testable != null)
                {
                    testResult.Screenshot = testable.SaveScreenshot("");
                }
            }
            finally
            {
                if (testable != null)
                {
                    testable.TeardownTest();
                    log.AddRange(testable.GetLogLastTime());
                }

                testResult.Log = log;
            }
            return(testResult);
        }
Esempio n. 3
0
        private TestResult HandleTest(WorkItem workItem)
        {
            TestResult testResult = new TestResult();
            ITestable testable = null;
            List<string> log = new List<string>();
            try
            {
                log.Add("Test on " + _nodename);

                /**1: Load Testclass **/
                Console.WriteLine(@"Testing {0} {1} ({2}/{3})", workItem.Testcase.Name, workItem.Browser.Name, workItem.Testsystem.Name, workItem.Language.Languagecode);
                testable = LoadTestable(workItem);
                if (testable == null)
                    return new TestResult { TestState = TestState.NotAvailable };

                /**2: Wait for branch get ready **/
                WaitOnWebExceptions(workItem);

                /**3: Prepare Test **/
                Browser browser = new Browser()
                {
                    Browserstring = workItem.Browser.Browserstring,
                    Versionsstring = workItem.Browser.Versionsstring
                };
                testable.SetupTest(WebDriverInitStrategy.SeleniumLocal, browser, workItem.Testsystem.Url,
                                      workItem.Language.Languagecode);

                /**4: Run Test **/
                testable.Test();

                testResult.TestState = TestState.Success;
            }
            catch (NotSupportedException notSupportedException)
            {
                Error error = CreateErrorFromException(notSupportedException);
                testResult.TestState = TestState.NotSupported;
                testResult.Error = error;
            }
            catch (TaskCanceledException taskCanceledException)
            {
                Error error = CreateErrorFromException(taskCanceledException);
                testResult.TestState = TestState.Canceled;
                testResult.Error = error;
            }
            catch (Exception exception)
            {
                ServerErrorModel serverException = null;
                try
                {
                    if (testable != null)
                        serverException = testable.CheckForServerError();
                }
                catch
                {
                    //Error catching serverException
                }
                Error error = CreateErrorFromException(exception);
                if (serverException != null)
                {
                    error.Type = serverException.Type;
                    error.Message = serverException.Message;
                    error.InnerException = serverException.InnerException;
                    //objError.StackTrace = serverException.StackTrace; Keep error stacktrace.

                }
                testResult.TestState = TestState.Error;
                testResult.Error = error;
                if (testable != null)
                    testResult.Screenshot = testable.SaveScreenshot("");

            }
            finally
            {
                if (testable != null)
                {
                    testable.TeardownTest();
                    log.AddRange(testable.GetLogLastTime());
                }

                testResult.Log = log;
            }
            return testResult;
        }
		/// <summary>
		/// Start a Test and throw exception in errorcase
		/// </summary>
		/// <param name="typeName">typename of testcase to load</param>
		/// <param name="testsystem">string with the testsystem</param>
		/// <param name="language">string with the language</param>
		/// <param name="browser"></param>
		internal void InitializeTest(string typeName, string testsystem, string language, Browser browser)
		{
			TestHeader = String.Format("Testcase: {0} ({1}, {2}) on {3}", typeName, language, browser, testsystem);

			_testable = _testcaseProvider.GetTestableFromTypeName(typeName);
			_testable.GetLogLastTime();
			_testable.SetupTest(WebDriverInitStrategy.SeleniumLocal, browser, testsystem, language);
			try
			{
				_testable.Test();
			}
			catch (TaskCanceledException)
			{
				//Test is canceled. Do normal teardown
			}

			_testable.TeardownTest();
		}
		/// <summary>
		/// Setup our test
		/// </summary>
		/// <param name="webDriverInitStrategy">the webDriver init strategy</param>
		/// <param name="browser">the template to test on</param>
		/// <param name="baseURL">the baseURL of our testsystem</param>
		/// <param name="languageCode">the languageCode to test on</param>
		/// <param name="timeOut">A optional timeout</param>
		void ITestable.SetupTest(WebDriverInitStrategy webDriverInitStrategy,  Browser browser, string baseURL, string languageCode, int timeOut)
		{
			RunBeforeTestStartMethods();

			TestStatusManager.IsCanceled = false;
			/*if (timeOut != 0)
				Settings.Default.TestTimeout = timeOut;*/


			IWebDriverFactory webDriverFactory;
			switch (webDriverInitStrategy)
			{
				case WebDriverInitStrategy.SeleniumGrid:
					webDriverFactory = new RemoteWebDriverFactory();
					break;
				case WebDriverInitStrategy.SeleniumLocal:
					webDriverFactory = new LocalWebDriverFactory();
					break;
				default:
					webDriverFactory = new LocalWebDriverFactory();
					break;
			}

			_webDriver = webDriverFactory.GetWebDriver(browser, languageCode);
			SetupTest(_webDriver, baseURL, languageCode);
		}
		/// <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));

		}