How would I initialize the browser if I want to test on multiple browsers using Page Object Model Page Factory?
Currently I have iniatialized the browsers in my Base Class like this.
// initialise driver/browser
public void initDriver() throws MalformedURLException{
if(CONFIG.getProperty("browser").equals("firefox")){
cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox"); // chrome,iexplore
cap.setPlatform(Platform.ANY);
}else if (CONFIG.getProperty("browser").equals("chrome")){
cap = DesiredCapabilities.chrome(); // no need path of chrome exe
cap.setBrowserName("chrome");
cap.setPlatform(Platform.ANY);
}else if (CONFIG.getProperty("browser").equals("iexplore")){
cap = DesiredCapabilities.internetExplorer(); // no need path of chrome exe
cap.setBrowserName("iexplore");
cap.setPlatform(Platform.WINDOWS);
}
if(driver == null){
driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);
}
String waitTime=CONFIG.getProperty("default_implicitWait");
driver.manage().timeouts().implicitlyWait(Long.parseLong(waitTime), TimeUnit.SECONDS);
}
This however only runs my test my test only on one of the browsers.
This is my testng.xml file
<suite name="Selenium Grid with webdriver" >
<listeners>
<listener class-name="Codes.listener.TestsListenerAdapter" />
</listeners>
<test name="Login test">
<classes>
<class name="Codes.testCases.LoginTest" ></class>
</classes>
</test>
</suite>
Your browser initialization seems ok but I am wondering , why cap
is not initialized when driver == null
You should improve your testng.xml
in following way:
To Run the test methods parallely:
<suite name="Selenium Grid with webdriver" parallel="methods" thread-count="5" >
<listeners>
<listener class-name="Codes.listener.TestsListenerAdapter" />
</listeners>
<test name="Login test">
<classes>
<class name="Codes.testCases.LoginTest" ></class>
</classes>
</test>
</suite>
Similarly you can define parallel = "classes"
or parallel = "tests"
to choose the parallel execution level.
As @Priyanshu mentioned, you need to change your testng.xml. I believe that you have updated your testng.xml but as per your above testng.xml file you have only one <class>
in <test>
, so in your cases parallel="methods"
(I assume you wanna execute different test scripts in parallel and not different methods of same test script) or parallel="classes"
will not work. Change it to parallel="tests"
and then try running it like this :-
<suite name="Selenium Grid with webdriver" parallel="tests" thread-count="5" >
<listeners>
<listener class-name="Codes.listener.TestsListenerAdapter" />
</listeners>
<test name="Login test">
<classes>
<class name="Codes.testCases.LoginTest" ></class>
</classes>
</test>
<test name="Login test2">
<classes>
<class name="Codes.testCases.LoginTest2" ></class>
</classes>
</test>
<test name="Login test3">
<!-- class etc.. etc.. -->
</test>
</suite>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.