Reputation: 3591
I am running selenium tests with multiple browser parallelly using selenium grid. Here is how i define tests with test fixture
public class ChromeDriver : RemoteWebDriver
{
public ChromeDriver() : base(new Uri("http://12.8.4.211:4444/wd/hub"), new ChromeOptions())
{
}
}
public class FirefoxDriver : RemoteWebDriver
{
public FirefoxDriver() : base(new Uri("http://12.8.4.211:4444/wd/hub"), new FirefoxOptions())
{
}
}
[TestFixture]
[TestFixture(typeof(ChromeDriver))]
[TestFixture(typeof(FirefoxDriver))]
[Parallelizable(ParallelScope.Fixtures)]
public class MyTests<TWebDriver> : SeleniumTestFixture<TWebDriver> where TWebDriver : IWebDriver, new(){
//Here goes my tests
}
But when i see result xml produced by nunit then I don't see name of browser in xml. How can i get name of browser in xml. Also i store screenshot and i am saving those result on hard disk depending on testname like below
var screenshot = ((ITakesScreenshot)WebDriver).GetScreenshot();
screenshot.SaveAsFile(Path.Combine(dir, $"{TestContext.CurrentContext.Test.MethodName}.png"), ScreenshotImageFormat.Png);
So when test runs it will save screenshot based on testname. But issue is that when i run test with multiple browser then screenshot will be overridden as it will have same name independent of browser. It should store based on browser name so somehow i need to get name of browser and append to screenshot name.
can anyone help me?
Upvotes: 1
Views: 181
Reputation: 6042
Save your files under NUnit's test name, rather than the method name. That will include the name of the browser driver passed in in your TestFixture attributes.
You can access that under:
TestContext.CurrentContext.Test.Name
Upvotes: 1
Reputation: 14135
you should be able to get the browser name using desired capabilities.
IWebDriver.DesiredCapabilities("BrowserName")
Here is the link for more information. https://seleniumhq.github.io/selenium/docs/api/dotnet/html/T_OpenQA_Selenium_Remote_DesiredCapabilities.htm
Upvotes: 0
Reputation: 1
There is a way here instead of using testname as screenshot name, you can handle it by concatenating Browsername(use static variable) and testname.
For E.g Testname: ABC and Browser-name: GoogleChrome for test-execution in Google Chrome so now screenshot name can be saved as GoogleChrome_ABC and parallelly when it is being executed in Mozilla Firefox Browser-name: Firefox and screenshot will be saved as Firefox_ABC.
Upvotes: 0