I am using Selenium WebDriver with Java & TestNG framework. I want to use Firefox, IE, Chrome in one single code at a time for doing cross-browser testing. I can only initialize Firefox as
driver = new FirefoxDriver();
but cannot initialize other browsers in the same way. For example:
driver = new InternetExplorerDriver();
gives the error InternetExplorerDriver cannot be resolved.
driver = new ChromeDriver();
gives the error ChromeDriver cannot be resolved.
How can I initialize IE and Chrome and execute my tests in all the desired browser ?
解决方案
For C#
Add
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
Create a config file which will contain browser name.
Implement a method for interaction with the config file
And you can use below code for initialize browsers:
string browser = GetConfigProperty("browser"); //Get browser name from the config
switch (browser)
{
case "chrome":
driver = new ChromeDriver();
break;
case "firefox":
driver = new FirefoxDriver();
break;
case "InternetExplorer":
driver = new InternetExplorerDriver();
break;
}
good luck!