/// <summary> /// Construct a browser from a browser type. /// </summary> /// <param name="brand">The browser type.</param> /// <returns>Returns a new web browser instance.</returns> private static WebBrowser Construct(WebBrowserBrand brand) { switch (brand) { case WebBrowserBrand.InternetExplorer: return(new InternetExplorer()); case WebBrowserBrand.Chrome: return(new Chrome()); case WebBrowserBrand.Firefox: return(new Firefox()); case WebBrowserBrand.OutOfBrowser: throw new NotImplementedException("Out-of-Browser support not yet implemented."); case WebBrowserBrand.Opera: case WebBrowserBrand.Safari: throw new NotImplementedException(string.Format(CultureInfo.CurrentUICulture, "The requested brand {0} is not current implemented.")); default: throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "The requested brand {0} is not supported.")); } }
/// <summary> /// Construct a browser from a browser type. /// </summary> /// <param name="brand">The browser type.</param> /// <returns>Returns a new web browser instance.</returns> private static WebBrowser Construct(WebBrowserBrand brand) { switch (brand) { case WebBrowserBrand.InternetExplorer: return new InternetExplorer(); case WebBrowserBrand.Chrome: return new Chrome(); case WebBrowserBrand.Firefox: return new Firefox(); case WebBrowserBrand.OutOfBrowser: throw new NotImplementedException("Out-of-Browser support not yet implemented."); case WebBrowserBrand.Opera: case WebBrowserBrand.Safari: throw new NotImplementedException(string.Format(CultureInfo.CurrentUICulture, "The requested brand {0} is not current implemented.")); default: throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "The requested brand {0} is not supported.")); } }
/// <summary> /// Creates a web browser instance. /// </summary> /// <param name="brand">The web browser type.</param> /// <returns>Returns a new web browser instance.</returns> public static WebBrowser Create(WebBrowserBrand brand) { WebBrowser wb = Construct(brand); return(wb); }
/// <summary> /// Creates a web browser instance. /// </summary> /// <param name="brand">The web browser type.</param> /// <returns>Returns a new web browser instance.</returns> public static WebBrowser Create(WebBrowserBrand brand) { WebBrowser wb = Construct(brand); return wb; }
public override bool Execute() { // There's nothing to do if we have no source files if (TestPages == null || TestPages.Length == 0) { return(true); } // Process the files bool succeeded = true; try { for (int i = 0; i < TestPages.Length; i++) { string testPath = TestPages[i].ItemSpec; FileInfo testApplication = new FileInfo(testPath); // Make sure they didn't pass a directory as an item if (Directory.Exists(testPath)) { Log.LogError("Cannot move item {0} because it is a directory!", testPath); succeeded = false; continue; } // Make sure the source exists if (!testApplication.Exists) { Log.LogError("Cannot process file {0} that does not exist!", testPath); succeeded = false; continue; } string testName = GetTestName(testApplication.Directory); if (!string.IsNullOrEmpty(TagExpression)) { testName += " (" + TagExpression + ")"; } string name = TestResultsFile; if (string.IsNullOrEmpty(name)) { int k = 1; name = "TestResults.trx"; while (File.Exists(Path.Combine(testApplication.DirectoryName, name))) { name = string.Format(CultureInfo.InvariantCulture, "TestResults{0}.trx", k++); } } FileInfo log = new FileInfo(Path.Combine(testApplication.DirectoryName, name)); WebBrowserBrand wbb = WebBrowserFactory.ParseBrand(Browser); TestRunOptions tro = new TestRunOptions { // StartupUri = testApplication.Name, Browser = wbb, LocalPath = testApplication.DirectoryName, TagExpression = TagExpression, }; tro.Page = testApplication.Name; tro.Log = log.FullName; if (wbb == WebBrowserBrand.Custom) { tro.SetCustomBrowser(Browser); } TestRun tr = new TestRun( new TestServiceOptions(), tro); tr.Run(); // Interpret results string pass = null; string total = null; if (log.Exists) { DisplayTestResults(log, ref total, ref pass); if (DeleteLogFiles) { log.Delete(); } } else { Log.LogWarning( "The log file {0} was never written by the test service for the {1} test.", log.FullName, testName); } if (tr.Total == 0) { Log.LogWarning("There were 0 reported scenarios executed. Check that the tag expression is appropriate."); } else if (tr.Failures == 0) { Log.LogMessage( MessageImportance.High, "Unit tests ({0}): {1}{2}", testName, pass != null ? " " + pass + " passing tests" : "", total != null ? " " + total + " total tests" : ""); } else { succeeded = false; LogFailureMessage( "Unit test failures in test " + testName + ", " + tr.Failures.ToString(CultureInfo.CurrentUICulture) + " failed scenarios out of " + tr.Total.ToString(CultureInfo.CurrentUICulture) + " total scenarios executed."); } } } catch (Exception ex) { Log.LogErrorFromException(ex); succeeded = false; } return(succeeded); }