I have a test case and need to execute based on the browser name i.e. IE or Chrome. In this test case some part will depend on browser type.
How will I get the brows
For those using C# you can do the following to detect browser when using either the local browser driver or remotewebdriver:
public static bool IsSafari(IWebDriver driver)
{
// Using remotewebdriver e.g. browserstack
if (SomeConfig.UsingRemoteWebDriver)
return GetRemoteDriverBrowserName(driver) == "safari";
// Using local browser driver
return driver.GetType() == typeof(SafariDriver);
}
public static bool IsInternetExplorer(IWebDriver driver)
{
// Using remotewebdriver e.g. browserstack
if (SomeConfig.UsingRemoteWebDriver)
return GetRemoteDriverBrowserName(driver) == "internet explorer";
// Using local browser driver
return driver.GetType() == typeof(InternetExplorerDriver);
}
private static string GetRemoteDriverBrowserName(IWebDriver driver)
{
return ((RemoteWebDriver)driver).Capabilities.GetCapability("browserName").ToString().ToLower();
}