0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
user6618310
  • 39
  • 1
  • 5
  • 14
  • How are you executing the tests? Can you add the runner? Refer to this for running cucumber with testng - https://github.com/cucumber/cucumber-jvm/tree/master/testng/src/main/java/cucumber/api/testng – Grasshopper Apr 09 '18 at 14:57
  • 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 JUnit – user6618310 Apr 09 '18 at 15:24

1 Answers1

0

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.

diabolist
  • 3,990
  • 1
  • 11
  • 15
  • i don't understand clearly what you mean ? with cucumber i can't run features in parallel in different browser !!! – user6618310 Apr 11 '18 at 14:13
  • Cucumber has features which contain scenarios. You are talking about running a scenario with 3 different browsers. To do this you have to run the scenario with the first browser, then run the scenario with the second browser etc.. You can run things in parallel by having each scenario run in a separate thread or fork. This isn't something Cucumber does its something other code does by interacting with the operating system and running separate instances of cucumber: one for each browser. – diabolist Apr 11 '18 at 15:35