At the moment my tests are running only in Firefox, because that is the driver which initialize at last. I need to run my tests on both Firefox and Chrome. Parallel or serially. But it should be automatic.
Below is my example test-code:.
namespace TestOne
{
[TestClass]
public class UnitTest1
{
public static IWebDriver driver;
[TestInitialize]
public void BeforeEveryTest()
{
driver = new ChromeDriver();
driver = new FirefoxDriver();
}
[TestMethod]
public void NavigateToGoogle()
{
driver.Navigate().GoToUrl("http://google.com");
}
[TestCleanup]
public void RunAfterEveryTest()
{
driver.Quit();
}
}
}
What are the options to run this test for both Chrome and Firefox? When using the C# testing tools (e.g. mstest.exe or vstest.console.exe)
-
1Changed the question a bit to make it a bit more clear, not sure why this is being voted as unclear. The question is simple, how to run C# Selenium tests against multiple browsers.Niels van Reijmersdal– Niels van Reijmersdal2017年03月30日 09:12:50 +00:00Commented Mar 30, 2017 at 9:12
-
1It is almost funny that question from member of "closing mafia" is almost closed by "closing mafia".Peter M. - stands for Monica– Peter M. - stands for Monica2017年03月30日 12:55:27 +00:00Commented Mar 30, 2017 at 12:55
-
I got the error NullReferenceException when using TestContext.Properties["browser"].ToString() on BaseClass. Could you have any oter solution?Vinh– Vinh2017年10月17日 10:43:13 +00:00Commented Oct 17, 2017 at 10:43
1 Answer 1
I think you can use a .RunSettings
as described in the MSDN documentation.
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<TestRunParameters>
<Parameter name="browser" value="chrome" />
</TestRunParameters>
</RunSettings>
If you make a file for Firefox and Chrome you can run the tests from the command-line with VStest.Console like this:
vstest.console myTestDll.dll /Settings:Chrome.RunSettings /Logger:trx
vstest.console myTestDll.dll /Settings:Firefox.RunSettings /Logger:trx
Your test would look like this:
[TestInitialize]
public void BeforeEveryTest()
{
if ( TestContext.Properties["browser"].ToString() == "chrome" ) {
driver = new ChromeDriver();
} else {
driver = new FirefoxDriver();
}
}
-
in here every time i have to change the browser name by editing the .RunSettings file.But i want it to be get automatically .One browser after another.ChathuD– ChathuD2017年03月30日 16:10:45 +00:00Commented Mar 30, 2017 at 16:10
-
1You make two run setting files. Add the two commands to a batch or powershell script. Then execute that one script to run them after each other.Niels van Reijmersdal– Niels van Reijmersdal2017年03月30日 18:01:41 +00:00Commented Mar 30, 2017 at 18:01
Explore related questions
See similar questions with these tags.