Run a feature file in different browsers at the same time - Selenium cucumber maven framework

631 views Asked by At

I am using Selenium Cucumber Maven framework with Junit. I need to run the same feature file in different browsers at the same time. Also I need to run the file using command line . Could you guys please help me with a solution since Iam a beginner . @BeforeClass of the TestRunner File is below.

@BeforeClass
public static void before() {   
browserName = System.getProperty("browserName");
if(browserName==null)
    {
        browserName= "chrome";
    }

if (browserName.equalsIgnoreCase("Chrome")) 
{
    System.setProperty("webdriver.chrome.driver", "E:\\ChromeDriverNew\\chromedriver.exe");
    driver=new ChromeDriver(); 
} 
else if (browserName.equalsIgnoreCase("Firefox")) 
{
    System.setProperty("webdriver.gecko.driver","E:\\geckoNew\\geckodriver.exe");
     driver = new FirefoxDriver();
} 

else {
    System.out.println("Error Message----> "
            + "browser name not mentioned properly");
    System.exit(0);
}      
   driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);   

}

What are the changes needed to be done in TestRunner file ? It would be a great help if you guys helped me since Iam a beginner. Thanks in advance .

1

There are 1 answers

0
vijay Ingale On

Are you using Jenkins to trigger the command if Yes then use below line of command and configure the browser and can hit this for multiple different browser mvn clean test -Dsurefire.suiteXmlFiles=testng.xml -DBrowser="Chrome"

If you wanted to send browser report specific for different browsers to the your to your project which will create specific browser with there report

mvn clean test -Dsurefire.suiteXmlFiles=testng.xml -DBrowser="Chrome" -Dcucumber.options="--plugin com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:target/Chrome/Extent-reports/Extentreport.html --plugin html:target/Chrome/cucumber-html-reports"