Running features cucumber in parallel in different

2019-08-22 02:06发布

问题:

How can i run cucumber features using testNG and selenium or cucumber-JVM i'm new in this but after my researsh i think that cucumber jvm doesn't work in paralell for me i added also the surefire plugin

now i try to test with TESTNG my testNg.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="run test in parallel Suite" parallel="tests" verbose="1" configfailurepolicy="continue" thread-count="2">

  <listeners>

        <listener classname="com.driver.LocalWebDriverListener" />
    </listeners>
    <test name="Tests in FF">
        <parameter name="browserName" value="firefox" />
        <classes>
            <class name="com.runner.RunnerTestInFirefox" />
        </classes>
    </test>
    <test name="Tests in Chrome" >
        <parameter name="browserName" value="chrome" />    
 <classes>
            <class name="com.runner.RunnerTestInChrome"/>
        </classes>
    </test>
</suite> <!-- Suite -->

and i create 2 class runner one for chrome and the other for firefox:

package com.runner;

    import org.junit.runner.RunWith;

    import cucumber.api.CucumberOptions;
    import cucumber.api.junit.Cucumber;
    import cucumber.api.testng.AbstractTestNGCucumberTests;

    @RunWith(Cucumber.class)
    @CucumberOptions(
             features = {"/features"},
             glue={"stepsdefinition"})
    public class RunnerTestInChrome extends AbstractTestNGCucumberTests {

    }

when i run my test the browser chrome is open and closed but i don't why it didn't take the url and the steps in the feature!

回答1:

Afaik Cucumber does not support parallel execution, You might need to use an additional plugin or need to use gherkin with qaf. qaf is built upon TestNG for functional test automation, providing browser management, resource management, data-driven capability, detailed reports with screenshot and command-log...

When using gherkin with qaf, your configuration file may look like:

<suite name="run test in parallel Suite" parallel="tests" verbose="1" configfailurepolicy="continue" thread-count="2">
      <test name="Tests in FF">
            <parameter name="driver.name" value="firefoxDriver" />           
            <classes>
                  <class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
            </classes>
      </test>
      <test name="Tests in Chrome">
            <parameter name="driver.name" value="chromeDriver"/>                      
            <classes>
                  <class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
            </classes>
      </test>
</suite>

NOTE: If you want to run scenarios in parallel set parallel="methods" and thread-count accordingly.

You can start by walk-through step by step tutorial