The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Selenium is a protocol focused on automating the actions of a browser, and as such, it doesn't encompass the notions of a "test" that "passes" or "fails." Because of this, you need to include a section in your code that explicitly gets the status of the test, and then sends it to the Sauce Labs dashboard. 

Code Block
languagec#
titleC# Code for Reporting Test Results to the Sauce Labs Dashboard
linenumberstrue
collapsetrue
 [TearDown]
        public void Cleanup()
        {
            // Gets the status of the current test
            bool passed = TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Passed;
            try
            {
                // Logs the result to Sauce Labs
                ((IJavaScriptExecutor)driver).ExecuteScript("sauce:job-result=" + (passed ? "passed" : "failed"));
            }
            finally
            {
                // Terminates the remote webdriver session
                driver.Quit();
            }
            
        }