I use a list of IWeb driver to perform tests on all browsers, line by line:
[ClassInitialize]
public static void ClassInitialize(TestContext context) {
drivers = new List<IWebDriver>();
firefoxDriver = new FirefoxDriver();
chromeDriver = new ChromeDriver(path);
ieDriver = new InternetExplorerDriver(path);
drivers.Add(firefoxDriver);
drivers.Add(chromeDriver);
drivers.Add(ieDriver);
baseURL = "http://localhost:4444/";
}
[ClassCleanup]
public static void ClassCleanup() {
drivers.ForEach(x => x.Quit());
}
..and then am able to write tests like this:
[TestMethod]
public void LinkClick() {
WaitForElementByLinkText("Link");
drivers.ForEach(x => x.FindElement(By.LinkText("Link")).Click());
AssertIsAllTrue(x => x.PageSource.Contains("test link"));
}
..where I am writing my own methods WaitForElementByLinkText and AssertIsAllTrue to perform the operation for each driver, and where anything fails, to output a message helping me to identify which browser(s) may have failed:
public void WaitForElementByLinkText(string linkText) {
List<string> failedBrowsers = new List<string>();
foreach (IWebDriver driver in drivers) {
try {
WebDriverWait wait = new WebDriverWait(clock, driver, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(250));
wait.Until((d) => { return d.FindElement(By.LinkText(linkText)).Displayed; });
} catch (TimeoutException) {
failedBrowsers.Add(driver.GetType().Name + " Link text: " + linkText);
}
}
Assert.IsTrue(failedBrowsers.Count == 0, "Failed browsers: " + string.Join(", ", failedBrowsers));
}
The IEDriver is painfully slow but this will have 3 of the main browsers running tests 'side by side'