I have set up some Selenium tests with Cucumber + Maven. I used to use JUnit as testing framework, but as I want to run the tests multiple times with different parameters, I looked into using TestNG that lets you define parameters before each run, so each Cucumber scenario gets executed a couple of times on different browsers. I do not get an error message, but nothing is executed besides the @BeforeTest
annotation within my TestRunner.class
So I assume the error must be within the run of the @Test
s
My 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>
My TestRunner class
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();
}
}
my 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>
These are the only things I applied changes to and before that everything ran fine. When I check e.g. via System.out.println()
, the TestRunner
class does seem the be able to read the scenarios and features, but they do not get executed. When I try put some more code in the Test
annotation within the TestRunner
class, it works fine, but it does not seem to recognize my StepsDefinitions
and the methods contained within it.
I didnt find anything on here, because as mentioned, I dont get an error message..
This is part of the log:
[JsonMessageSender] Sending message [TestResultMessage ==>
suite:Automationsuite, test:ChromeTest, class:runner.TestRunner,
method:runThisScenario, parameters:"MyScenario";"MyFeature";]
[BaseMessageSender] Received ACK:>ACK
[BaseMessageSender] Received ACK:>ACK
Any help on this would be greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire