I'm looking for the recommended/nicest way to make Selenium tests execute in several browsers one after another. The website I'm testing isn't big, so I don't need a parallel solution yet.
I have the usual test set-up methods with [SetUp]
, [TearDown]
, and [Test]
. The SetUp one, of course, instantiates a new ISelenium
object with whatever browser I want to test with.
So what I want to do is programmatically say: this test will be run on Chrome, IE, and Firefox in sequence. How do I do that?
EDIT:
This might help a bit. We're using CruiseControl.NET to start the NUnit tests after a successful build. Is there any way to pass a parameter to the NUnit executable, and then use that parameter in the test? This way we could have NUnit run several times with different browser parameters.
Create an XML which will help us in parameterizing the browser name and don't forget to mention parallel="tests" in order to execute in all the browsers simultaneously. Execute the script by performing right-click on the XML file and select 'Run As' >> 'TestNG' Suite as shown below.
With Parallel Testing, you can run the same test on different browser/device combinations i.e. cross-browser testing, or run different tests on the same or different browser/device combinations. Parallel Testing will help you reduce the run time of your test suite, resulting in faster build times and faster releases.
Selenium is able to run tests in parallel, but CrossBrowserTesting makes it even simpler - allowing you to test across multiple browsers and mobile devices with just a few extra lines of code.
We can run multiple test cases using TestNG test suite in Selenium webdriver. To execute test cases simultaneously, we have to enable parallel execution in TestNG. A TestNG execution is driven by the TestNG xml file. To trigger parallel execution we have to use the attributes – parallel and thread-count.
NUnit 2.5+ now supports Generic Test Fixtures which make testing in multiple browsers very straightforward. http://www.nunit.org/index.php?p=testFixture&r=2.5
Running the following example will execute the GoogleTest twice, once in Firefox and once in IE.
using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.IE; using System.Threading; namespace SeleniumTests { [TestFixture(typeof(FirefoxDriver))] [TestFixture(typeof(InternetExplorerDriver))] public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new() { private IWebDriver driver; [SetUp] public void CreateDriver () { this.driver = new TWebDriver(); } [Test] public void GoogleTest() { driver.Navigate().GoToUrl("http://www.google.com/"); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("Bread" + Keys.Enter); Thread.Sleep(2000); Assert.AreEqual("bread - Google Search", driver.Title); driver.Quit(); } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With