Recently I have been struggling with flaky UI tests in Selenium. After doing a lot of research on ways to make tests a lot more robust (explicit waits, etc.) I came across some people here on stack overflow that were suggesting soak testing the selenium scripts to try and work out all the small, seemingly random, failures that I was getting. I seems like a great idea but there doesn't appear to be a whole lot of resources on how to accomplish this. My Current thought process is to find some way to write unit tests in MSTest that take the Selenium tests I have, run them multiple times and log the results. But so far I've had no luck with that approach. Specifically, I've tried something like this:
[TestClass]
public abstract class MSTestClass
{
public TestContext TestContext { get; set; }
[AssemblyInitialize]
public static void SetupAssembly(TestContext testContext)
{
}
[TestInitialize]
public void SetupTest()
{
//pull the browser type variable out of the test.runsettings file via the TestContext object
string browserType = TestContext.Properties["Browser"].ToString();
//Start a new Browser for the current test
Browser.Start(browserType);
//Resize the Browser to your application's target width
Browser.ResizeTo(1440, 900);
//pull the site URl from the AppSettings file
string siteURL = System.Configuration.ConfigurationManager.AppSettings["URL"];
Browser.Visit(siteURL);
}
[TestMethod]
public void Test()
{
}
[TestCleanup]
public void CleanupTest()
{
Browser.Shutdown();
}
}
[TestClass]
public class ExampleSoakTests
{
[TestMethod]
public void ActualSoakTest()
{
ExampleTest testClass = new ExampleTest();
for(int i = 0; i<10; i++)
{
try
{
testClass.SetupTest();
testClass.ActualTest();
testClass.CleanupTest();
Log.Success();
}
catch(Exception e)
{
Log.Exception(e);
}
}
}
}
The issue that I have been having with the above code is that the TestContext property doesn't get initialized. I'm assuming that this is because the test method wasn't called by the Visual Studio Test Runner?
In conclusion any help with my current approach or any ideas on other ways to go about Soak Testing my Selenium Scripts would be a great help.