我已经用Cucumber + Maven建立了一些硒测试。我曾经将JUnit用作测试框架,但是由于我想使用不同的参数多次运行测试,因此我尝试使用TestNG,它可以让您在每次运行之前定义参数,因此每个Cucumber场景在不同的浏览器上都会执行两次。
我没有收到错误消息,但是除了
我的@BeforeTest
中的TestRunner.class
注解
因此,我认为错误必须在@Test
s
我的testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automationsuite" parallel="tests">
<test name="ChromeTest">
<parameter name="browserName" value="Chrome" />
<classes>
<class name="runner.TestRunner" />
</classes>
</test>
<!-- <test name="IETest">
<parameter name ="browserName" value="IE"/>
<classes>
<class name="runner.TestRunner" />
</classes>
</test> -->
</suite>
我的TestRunner类
package runner;
@CucumberOptions(
strict = true,
features ="Features/myInfineon_Login/InternalTesting/int_myInfineon_Login_Chrome.feature",
glue = {"stepsDefinitions"},
plugin = { "pretty", "json:target/cucumber-reports/cucumber.json",
"html:target/cucumber-reports",
"junit:target/cucumber-reports/xml-report.xml"
})
public class TestRunner /*extends AbstractTestNGCucumberTests*/{
private TestNGCucumberRunner testNGCucumberRunner;
private static TestContext tcon;
@BeforeClass(alwaysRun = true)
public void setUpClass() {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}
@Parameters({ "browserName" })
@BeforeTest
public static void setUpScenario(String browser) {
tcon = new TestContext();
tcon.setupBrowserDriver(browser);
}
@Test(groups = "cucumber scenarios", description = "Runs Cucumber Scenarios", dataProvider = "scenarios")
public void runThisScenario(PickleEventWrapper pickleEvent, CucumberFeatureWrapper cucumberFeature) throws Throwable{
testNGCucumberRunner.runScenario(pickleEvent.getPickleEvent());
System.out.println("driver in test: " + tcon.getWebDriver());
}
@DataProvider
public Object[][] scenarios() {
if (testNGCucumberRunner == null) {
return new Object[0][0];
}
return testNGCucumberRunner.provideScenarios();
}
@AfterClass(alwaysRun = true)
public void tearDownClass() {
testNGCucumberRunner.finish();
}
}
我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myinfineon</groupId>
<artifactId>myinfineon-testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>C:\Program Files\Java\jdk1.8.0_181\lib\tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>com.crossbrowsertesting</groupId>
<artifactId>CBT_Helper</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>4.4.0</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>0.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>4.1.3</version>
<exclusions>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>gherkin-jvm-deps</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<!-- <scope>compile</scope> -->
</dependency>
<!-- https://mvnrepository.com/artifact/org.apiguardian/apiguardian-api -->
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
<version>1.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
这些是我应用的唯一更改,在此之前一切正常。
当我检查例如通过System.out.println()
,TestRunner
类似乎能够读取场景和功能,但是它们没有被执行。当我尝试在Test
类的TestRunner
注释中添加更多代码时,它可以正常工作,但是似乎无法识别我的StepsDefinitions
及其中包含的方法。
我在这里没有找到任何东西,因为如上所述,我没有收到错误消息。
这是日志的一部分:
[JsonMessageSender] Sending message [TestResultMessage ==>
suite:Automationsuite, test:ChromeTest, class:runner.TestRunner,
method:runThisScenario, parameters:"MyScenario";"MyFeature";]
[BaseMessageSender] Received ACK:>ACK
[BaseMessageSender] Received ACK:>ACK
对此将提供任何帮助!