internal static void SauceLabsTearDown(IWebDriver driver) { var jobId = WebDriverFactory.SaucelabsJobId; var client = new Client(Configuration.Configuration.SauceLabsUsername, Configuration.Configuration.SauceLabsAccessKey); // We need to quit the driver before finalising the sauce job, // otherwise Sauce won't consider the session complete. if (driver != null) { driver.Quit(); } WaitUntilSauceJobComplete(client, jobId); client.SetJobPublic(jobId); if (TestFinalizer.GetCurrentTestStatus().Equals(TestFinalizer.TestStatus.Failed)) { client.SetJobPassStatus(jobId, false); var job = client.GetJob(jobId); if (String.IsNullOrEmpty(job.Error)) { client.SetError(jobId, ScenarioContext.Current.TestError.Message); } WebDriverEventLog.Add(job.ToDebugInfo()); } else { client.SetJobPassStatus(jobId, true); WebDriverEventLog.Add(String.Format("Report: {0}{1}", "https://saucelabs.com/jobs/", jobId)); } }
public static void TearDown() { if (Driver == null) { WebDriverEventLog.Add(DriverDiedMessage); return; } WebDriverEventLog.Add(GetFinalUrlMessage()); switch (WebDriverFactory.GetTestExecutionEnvironment()) { case WebDriverFactory.TestExecutionEnvironment.Local: LocalFinalizer.LocalTearDown(Driver); break; case WebDriverFactory.TestExecutionEnvironment.Grid: GridFinalizer.GridTearDown(Driver); break; case WebDriverFactory.TestExecutionEnvironment.SauceLabs: SaucelabsFinalizer.SauceLabsTearDown(Driver); break; default: throw new ArgumentException("Could not tear down the session for this execution environment"); } }
public void AfterScenario() { try { TestFinalizer.TearDown(); } finally { Console.WriteLine(WebDriverEventLog.ToString()); } }
private static void TakeScreenshot(IWebDriver driver) { try { ScreenshotCreator.CreateErrorScreenshot(driver); } catch (Exception ex) { WebDriverEventLog.Add(ex.Message); } }
private static void WaitUntilSauceJobComplete(Client client, string jobId) { try { TestFinalizer.WaitUntil(d => client.IsJobComplete(jobId)); } catch (TimeoutException) { const string jobTimeoutMessage = "Timed out waiting for the Saucelabs job to finish. " + "This normally means that the connection has been lost."; WebDriverEventLog.Add(jobTimeoutMessage); } }