I'm stuck in running parallel execution. Need help & use-full thought.
My Driver class:
#Parameters({"environment","browser"})
#BeforeClass(alwaysRun = true)
public void startUp(String environment, String browser) {
switch (browser) {
case "firefox":
System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
driver = new FirefoxDriver();
break;
case "chrome":
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedirver";
driver = new ChromeDriver();
break;
default:
driver = new FirefoxDriver();
}
switch (environment) {
case "fb":
driver.get("https://facebook.com");
break;
case "yahoo":
driver.get("https://yahoo.com");
break;
case "google":
driver.get("https://google.com");
break;
}
Xml File:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Login Feature" parallel="classes" thread-count="2">
<test name="fbe chrome" >
<parameter name="browser" value="chrome"/>
<parameter name="environment" value="google"/>
<classes><class name="framework.google.googlepage"></class></classes>
</test>
<test name="faceboo firefox">
<parameter name="browser" value="firefox"/>
<parameter name="environment" value="google"/>
<classes><class name="framework.google.googlepage"></class></classes>
</test>
</suite>
I am using page object model and extending Driver Factory to Test Class
When I use parallel= "classes" thread-count="2"
it's run 1 after another class and in a different browser. [Not together/sametime]
When I use parallel="tests" Thread-count= "2"
Both browser open at the same time, 1 browser stop working and another browser does double click, double sendkeys. Work only 1 browser with both browser sets of data.
I want to run tests parallelly with a different browser same time.
Need help as my code is not working.
Related
I want to run a cucumber feature in different browsers;
So, now I'm able to open the 3 browsers in parallel chrome, ff and ie but they can't continue the other steps in features !
My method is :
#Parameters("myBrowser")
#BeforeClass
#Given("^openaaaBrowser<myBrowser>$")
public void openaaaBrowser(#Optional("optional value") String myBrowser) throws InterruptedException {
WebDriver driver;
if (myBrowser.equalsIgnoreCase("ie")) {
System.setProperty("webdriver.ie.driver","C:\\Driver\\IEDriverServer\\IEDriverServer_32bits.exe");
driver = new InternetExplorerDriver();
}
if (myBrowser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver","D:\\Drive\\chromedriver_win32\\chromedriver.exe");
driver= new ChromeDriver();
}
if (myBrowser.equalsIgnoreCase("firefox")){
System.setProperty("webdriver.gecko.driver","D:\\Drive\\geckodriver-v0.20.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}}
My testng.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SuiteSopraHR" parallel="tests">
<test name="testff">
<parameter name="myBrowser" value="firefox" />
<classes>
<class name="com.soprahr.foryou.automation.steps.StepDefinitionConnect"/>
</classes>
</test> <!-- Test -->
<test name="testie">
<parameter name="myBrowser" value="ie" />
<classes>
<class name="com.soprahr.foryou.automation.steps.StepDefinitionConnect"/>
</classes>
</test> <!-- Test -->
<test name="testchrome">
<parameter name="myBrowser" value="chrome" />
<classes>
<class name="com.soprahr.foryou.automation.steps.StepDefinitionConnect"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
and I have those methods
#Test(priority=1)
#When("^Open browser$")
public void openBrowser() throws InterruptedException {
StepDefinition.DRIVER.get(URL);
Thread.sleep(N_3000);
StepDefinition.waitForJQueryProcessing(StepDefinition.DRIVER, N_30);
}
#Test(priority=2)
#Then("^Se connecter à l'environnement via ID '(.*)'$")
public void letThisOneConnect(final String Id) throws Throwable {
Thread.sleep(N_3000);
Utilities utilities = new Utilities();
TestCase testCase = utilities.getMyTestCase(Id);
StepDefinition.deleteAndEnterTextById(ID_LOGIN_INPUT_4YOU, testCase.getLogInId());
StepDefinition.deleteAndEnterTextById(ID_PASSWORD_INPUT_4YOU, testCase.getLogInPassword());
StepDefinition.clickButtonById(ID_LOGIN_BUTTON_4OU);
}
The problem here and I don't understand why it can't the #test methods
If you want to run a scenario with different browsers you have to run the scenario multiple times. i.e. if you have 3 browsers then you end up with 3 scenario instances.
You can't do is run one scenario in 3 browsers.
The simplest way to get your parallelism do this to take it out of Cucumber. If you ran in series you might have
cucumber features/my_feature BROWSER=chrome
cucumber features/my_feature BROWSER=firefox
cucumber features/my_feature BROWSER=ie
Now you could use your CI platform to run each of these commands in a separate instance. Then you'll get your parallelism, and all you have to do with Cucumber is get it to use an environment variable to control which driver and browser to use.
You won't succeed in getting Cucumber to work with more than one browser for a particular scenario instance.
I'm working in a big project, i want to run eature cucumber in parallel in different browser
I have the featuren the step definition ? the webdriverfactory and the shared preferences.
I have this method in webfactory and it works and i write the testng.xml
public WebDriver driver;
public static WebDriver get() {
WebDriver driver = null ;
System.setProperty("webdriver.chrome.driver","D:\\Drive\\chromedriver_win32\\chromedriver.exe");
driver= new ChromeDriver();
return(driver);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SuiteSopraHR" parallel="tests">
<test name="testie">
<!-- <parameter name="myBrowser" value="ie" /> -->
<classes>
<class name="com.driver.WebDriverFactory"/>
</classes>
</test> <!-- Test -->
<test name="testchrome">
<!-- <parameter name="myBrowser" value="chrome" /> -->
<classes>
<class name="com.driver.WebDriverFactory"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
I don't know how to change the other method because it didn't has any parameter to pass and it return a web driver.
when I have changed all the other method in other classes have a problem with it
any suggestion please.
and is the cucumber-jvm can run feature in parallel in different browser ??? or in console ???
You can indeed run Cucumber features and scenarios in parallel using Courgette-JVM
When you run your tests, you can set a System property that would target the browser you wish to use in parallel.
Another useful library to manage your driver binaries is WebDriver Binary Downloader
You can then specify the browser to use at runtime using:
System.setProperty("browser", "chrome");
or
VM option -Dbrowser="chrome"
private WebDriver driver;
public void createDriver() {
final String browser = System.getProperty("browser", "chrome").toLowerCase();
switch (browser) {
case "chrome":
WebDriverBinaryDownloader.create().downloadLatestBinaryAndConfigure(BrowserType.CHROME);
driver = new ChromeDriver();
case "firefox":
WebDriverBinaryDownloader.create().downloadLatestBinaryAndConfigure(BrowserType.FIREFOX);
driver = new FirefoxDriver();
default:
throw new RuntimeException("Invalid browser specified!");
}
}
We are using QAF-Gherkin-client, where you can configure it using one or more xml test nodes. You can run scenarios in parallel as well. You don't need to write any code for driver management or other functional testing common needs.
<suite name="AUT Test Automation" verbose="0" parallel="methods">
<test name="Tests on chrome">
<parameter name="driver.name" value="chromeDriver"/>
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
<test name="Tests FF">
<parameter name="driver.name" value="firefoxDriver"/>
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
</suite>
I think, you need to add switch construction in your method and parameter - type of browser from testng.xml.
Also, as I know, parallel execution will work only with a non-static Driver.
I'm trying to execute one test script on two android devices simultaneously using Selenium and TestNG. But I'm unable to achieve it. The test script executes first on one device and then starts executing on other android device.Here is the TestNg.xml which i have used:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test suite" parallel="methods" thread-count="2">
<test name="Regression 1">
<parameter name="devname" value="adb:SM-G900H" />
<classes>
<class name="Parallel.EribankTetsng"/>
</classes>
</test>
<test name="Regression 2">
<parameter name="devname" value="adb:GT-I9300" />
<classes>
<class name="Parallel.EribankTetsng"/>
</classes>
</test>
</suite>
EribankTestng.java: The below is the test script which is export from seetest automation to selenium. we are connecting two android devices to same machine and trying to execute parallely using Testng. only after the execution is completed one device, the execution is getting started on the second device.
public class EribankTetsng
{
private String host = "localhost";
private int port = 8889;
private String projectBaseDirectory = "D:\\Vijaya Seetest";
protected Client client = null;
#BeforeTest
public void setUp(){
client = new Client(host, port, true);
client.setProjectBaseDirectory(projectBaseDirectory);
client.setReporter("xml", "reports", "LoginEribank");
}
#Test(groups = {"seetest"})
#Parameters("devname")
public void testLoginEribank(String devname){
client.setDevice(devname);
client.launch("com.experitest.ExperiBank/.LoginActivity", true, false);
client.elementSendText("Eribank", "Username", 0, "company");
client.elementSendText("Eribank", "passwordTextField", 0, "company");
client.click("Eribank", "Login", 0, 1);
client.click("Eribank", "Logout", 0, 1);
}
#AfterTest
public void tearDown(){
client.generateReport(false);
client.releaseClient();
}
}
I am beginner in selenium webdriver. so for parallel execution normally we do changes in xml file like parallel="methods" thread-count="3" and my doubt is:
Is the parallel execution possible without selenium grid?
or only testNG is enough?
Yes, you may run UI tests in parallel without grid, or using only selenium grid node directly, without hub. Each thread in TestNG will open additional browser window, but you will get unpredictable issues in case when you application will manage all connections from you host as one user session.
Yes, using #Parameters ("browser") of TestNg..sample code as below...
#Parameters ("browser")
public void test(String browserName) {
if(browserName.equalsIgnoreCase("firefox")){
driver = new FirefoxDriver();
} else if (browserName.equalsIgnoreCase("chrome")){
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\chromedriver.exe" );
driver = new ChromeDriver();
}
}
write your test after that in your testng.xml use parallel option also mention the parameter value.. sample code as below..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite789787" parallel="tests">
<test name="FFTest98798">
<parameter name="browser" value="firefox"/>
<classes>
<class name ="crossbrowsertest.VerifyTitle" >
</class>
</classes>
</test> <!-- Test -->
<test name="ChromeTest8999">
<parameter name="browser" value="chrome"/>
<classes>
<class name ="crossbrowsertest.VerifyTitle" >
</class>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
hope this helps
I am facing a problem of Selenium Grid and TestNG. My test scripts will NOT quite the browser until all the test class are executed.
I've configed 5 Chrome instance running on my Selenium Grid, then below is my xml file
<suite name="BrowserTest">
<test name="Test1" >
<parameter name="browserName" value="chrome"/>
<classes>
<class name= "Pagetest" />
</classes>
</test>
<test name="Test2" >
<parameter name="browserName" value="firefox"/>
<classes>
<class name= "Pagetest" />
</classes>
</test>
<test name="Overview Page Test on ie, English" >
<parameter name="browserName" value="ie"/>
<classes>
<class name= "Pagetest" />
</classes>
</test>
</suite>
Here is my test scripts
public class Pagetest {
private WebDriver browser;
public PateTest( String browser){
// create a browser instance.
}
#AfterClass (or #afterTest)
public void afterTest() throws Exception {
System.out.println("this test is done");
this.browser.quit();
}
#Test
public void test1(){
this.browser.get("www.google.com");
// doing some login stuff
}
}
Now when I am running my test, testNG will create 3 chrome webdirver instance one by one (with running the test). but after the 1st test is done, the browser instance of 1st test is not quited until all 3 tests are done, then all the 3 chrome instance are quited almost at the same time. What I want is after the 1st test is done, it's browser instance is quited, then the 2nd test case is started, did I do something wrong or how should I change my code?
Try using threadlocal it would help when you are even running tests in parallel
public ThreadLocal<WebDriver> driver=null;
#beformethod()
public void setUp
{
driver = new ThreadLocal<WebDriver>();
driver.set(new ChromeDriver());
return driver.get();
}
#AfterMethod
public void closeBrowser() {
{
driver.get().quit();
}