0
votes

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

1
How are you executing the tests? Can you add the runner? Refer to this for running cucumber with testng - github.com/cucumber/cucumber-jvm/tree/master/testng/src/main/…Grasshopper
I don't use a runner and cucumber-JVM is for runing not in different browser in parallel ? i try it. I use the runner for testing with JUnituser6618310

1 Answers

0
votes

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.