I'm learning how to use cucumber in java and selenium webdriver. I have the architecture in place and I'm down to one very specific problem.
#When("^I login with the parameters \"([^\"]*)\" and \"([^\"]*)\" and \" ([^\"]*)\"")
public void I_login_with_the_parameters(String arg1, String arg2, String arg3) throws Throwable{
if (arg1.equals("PRO")) {
arg1 = "PRO";
}
if (arg2.equals("testleader")) {
arg2 = "testleader";
}
if (arg3.equals("Chrome")) {
arg3 = "Chrome";
}
assertTrue (codebase.Beoordeling_Login.correctinloggen(arg1, arg2, arg3));
}
I don't understand why this code works, and when I leave out the if statements I get a null pointer exception, like this:
#When("^I login with the parameters \"([^\"]*)\" and \"([^\"]*)\" and \"([^\"]*)\"")
public void I_login_with_the_parameters(String arg1, String arg2, String arg3) throws Throwable{
assertTrue (codebase.Beoordeling_Login.correctinloggen(arg1, arg2, arg3));
}
gets me:
java.lang.NullPointerException
at codebase.LoginPortal.inloggen(LoginPortal.java:14)
at codebase.Beoordeling_Login.correctinloggen(Beoordeling_Login.java:12)
at steps.InloggenSteps.I_login_with_the_parameters(InloggenSteps.java:32)
at ✽.When I login with the parameters "PRO" and "testleader" and "Chrome" (featurefiles/inloggen.feature:9)
When I put back the if statements it runs like I would expect, so I know that arg1, arg2 and arg3 strings are actually strings and can be used.
Why won't it let me use them in my login method and I have to re-set the strings in an ugly fashion?
edit 1:
public class LoginPortal { public WebDriver inloggen(String Omgeving, String Rol, String Browser) {
String InlogUrl = null; WebDriver driver = anroepDriver.roepdriver(Browser);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
complete code on github: https://github.com/Yourtestprofessionals/YourCucumber
edit2: cheers for the replies so far. my problem is still not solved though.
EDIT
Here is my modified pom.xml. I went back to selenium-java version 2.53.1. I also added surefire and specified Java 1.8 (Oracle). Try this pom and let me know.
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.czeczotka.bdd</groupId>
<artifactId>cucumber-jvm-maven</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>cucumber-jvm-maven</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.53.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<additionalClasspathElements>
<!-- ${basedir} needed in classpath so that log4j can find the log4j.properties file -->
<additionalClasspathElement>${basedir}</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.19.1</version>
</dependency>
</dependencies>
</plugin>
<!-- Specifying the maven-compiler-plugin allows us to set default JDK -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
I last point. I am using ChromeDriver 2.25.426923.
EDIT 2
I modified your runner. I replaced format with plugin.
package runner;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "html:target/cucumber"},
glue = "steps",
features = "classpath:featurefiles/nieuwe_bevinding.feature"
)
public class RunInloggerTest {
}
I would be surprised if this would actually solve your problem but trying won't hurt; have you tried using the regex 'wildcard': '.*'?
Like this:
#When("^I login with the parameters \"(.*)\" and \"(.*)\" and \"(.*)\"")
Related
I understand that it is not possible to get data from the resources.
Permission in services for interacting with the desktop in services is given.
simple tests pass:
enter image description here
enter image description here
enter image description here
enter image description here
enter image description here
enter image description here
enter image description here
In Jenkins I crawl the parameterized assembly line:
-Dbrowser=${browser} -Dsurefire.suiteXmlFiles=${surefire.suiteXmlFiles} -Denvironment=${environment} clean test
error code
java.lang.ExceptionInInitializerError
at service.InstanceCreator.getDataEstimateForm(InstanceCreator.java:24)
at test.GoogleCloudTest.checkEmailEstimateCost(GoogleCloudTest.java:17)
at java.util.ArrayList.forEach(ArrayList.java:1259)
Caused by: java.lang.NullPointerException
at java.util.ResourceBundle$CacheKey.calculateHashCode(ResourceBundle.java:654)
at java.util.ResourceBundle$CacheKey.<init>(ResourceBundle.java:584)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1333)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:782)
at service.TestDataReader.<clinit>(TestDataReader.java:6)
... 35 more
... Removed 32 stack frames
class for reading keys
public class TestDataReader {
private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(System.getProperty("environment"));
public static String getTestData(String key) {
return resourceBundle.getString(key);
}
}
service class
public class InstanceCreator {
private static final String NUMBER_OF_INSTANCES = "testdata.instanceCreator.number";
private static final String OPERATION_SYSTEM = "testdata.instanceCreator.os";
private static final String MACHINE_CLASS = "testdata.instanceCreator.machine-class";
private static final String SERIES_ID = "testdata.instanceCreator.series-id";
private static final String MACHINE_TYPE = "testdata.instanceCreator.machine-type";
private static final String NUMBER_OF_GPUS = "testdata.instanceCreator.number-of-gpus";
private static final String TYPE_GPU = "testdata.instanceCreator.type-gpu";
private static final String LOCAL_SSD = "testdata.instanceCreator.local-ssd";
private static final String DATA_CENTER_LOCATION = "testdata.instanceCreator.datacenter";
private static final String COMMITTED_USAGE = "testdata.instanceCreator.committed-sage";
public static InstanceForm getDataEstimateForm() {
return new InstanceForm(
TestDataReader.getTestData(NUMBER_OF_INSTANCES),
TestDataReader.getTestData(OPERATION_SYSTEM),
TestDataReader.getTestData(MACHINE_CLASS),
TestDataReader.getTestData(SERIES_ID),
TestDataReader.getTestData(MACHINE_TYPE),
TestDataReader.getTestData(NUMBER_OF_GPUS),
TestDataReader.getTestData(TYPE_GPU),
TestDataReader.getTestData(LOCAL_SSD),
TestDataReader.getTestData(DATA_CENTER_LOCATION),
TestDataReader.getTestData(COMMITTED_USAGE));
}
}
test
public class GoogleCloudTest extends CommonConditions {
#Test(description = "get a letter with the results of processing the request")
public void checkEmailEstimateCost() {
new InstanceCreator();
InstanceForm instanceForm = InstanceCreator.getDataEstimateForm();
String verificationCalculationResultsReceivedEmail = new GoogleCloudHomePage(driver)
.openPage()
.fillSearchInput()
.openCalculator()
.activationComputeEngine()
.fillComputeEngineForm(instanceForm)
.pressAddToEstimate()
.saveResultEstimate()
.pressButtonEmailEstimate()
.openNewTab()
.openPage()
.copyEmailAddress()
.comeBackToCalculator()
.enterEmail()
.pressButtonSendEmail()
.returnToPageEmail()
.pressCheckMailButton()
.thisComparisonResultsReceivedEmailWithDataSite();
Assert.assertEquals(verificationCalculationResultsReceivedEmail, ProcessData.getCurrentPriceInCalculator()
, "the data received by mail does not coincide with the data received in the calculator");
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
<groupId>org.example</groupId>
<artifactId>frameworklasttask</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M5</version>
<type>maven-plugin</type>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
From the screenshots above, you need to correct the following:
'Trigger/call builds on other projects' section
File Name in Child Projects section you have mvn test -P -Dbrowser=${browser} -Dsurefire.suiteXmlFiles=${surefire.suiteXmlFiles} -Denvironment=${environment} clean test - remove this, as this section is to declare files within sub-projects of your main project "frameworklasttask", not the maven command
Now on the next section, where you have declared the maven version '3.8.1'
Update clean test to clean test -Dbrowser=${browser} -Dsurefire.suiteXmlFiles=${surefire.suiteXmlFiles} -Denvironment=${environment}.properties
For the moment, I have discarded the -P part of the maven command as a tag is missing from the configuration you have provided so far.
I only found a solution like this. Nothing else in this project build configuration works !!! Proven by 4 days of searching!
enter image description here
I want to use Java code in the web. For this I want to convert Java to WASM and use this wasm-file in JavaScript. For converting Java to WebAssembly, I am using TeaVM.
First, I created an archetype with this command: mvn archetype:generate -DarchetypeGroupId=org.teavm.flavour -DarchetypeArtifactId=teavm-flavour-application -DarchetypeVersion=0.2.0
In addition, I added these two dependencies (according to http://blog.dmitryalexandrov.net/webassembly-for-java-developers/):
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${teavm.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-interop</artifactId>
<version>${teavm.version}</version>
</dependency>
and added the following in the plugin section:
<targetType>WEBASSEMBLY</targetType>
<optimizationLevel>FULL</optimizationLevel>
<heapSize>8</heapSize>
My Java file:
#BindTemplate("templates/client.html")
public class Client extends ApplicationTemplate {
private String userName = "ABC";
public static void main(String[] args) {
Client client = new Client();
client.bind("application-content");
}
#Export(name = "getUserName")
public String getUserName() {
return userName;
}
}
But when I am doing mvn clean package, I am getting to following error (but a wasm file is created):
my complete pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>my.company</groupId>
<artifactId>java_wasm</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<flavour.version>0.2.0</flavour.version>
<teavm.version>0.6.0</teavm.version>
<jackson.version>2.5.4</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${teavm.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-metaprogramming-impl</artifactId>
<version>${teavm.version}</version>
</dependency>
<dependency>
<groupId>org.teavm.flavour</groupId>
<artifactId>teavm-flavour-widgets</artifactId>
<version>${flavour.version}</version>
</dependency>
<dependency>
<groupId>org.teavm.flavour</groupId>
<artifactId>teavm-flavour-rest</artifactId>
<version>${flavour.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${teavm.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-interop</artifactId>
<version>${teavm.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated/js</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>${teavm.version}</version>
<executions>
<execution>
<id>web-client</id>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>my.company.Client</mainClass>
<minifying>true</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied>
<optimizationLevel>ADVANCED</optimizationLevel>
<targetType>WEBASSEMBLY</targetType>
<optimizationLevel>FULL</optimizationLevel>
<heapSize>8</heapSize>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
How can I create a complete WASM without errors? Thank you in advance!
Wasm backend of TeaVM does not support JSO interop layer. It also supports subset of features available in JavaScript backend. So there's no way to make TeaVM Flavour work in Wasm, instead your should prefer JavaScript target. If you want to learn how to deal with Wasm BE, you can take a look at example.
Wasm has proven to be extremely inappropriate to run Java, so I recommend to use JavaScript BE of TeaVM. Also, please note that official site (htts://teavm.org) lists links where you can get help (google groups, gitter, direct email). I don't follow StackOverflow questions about TeaVM and don't receive notifications from SO.
I hope my second question on SO is well scripted. I am trying to automate test cases using Gherkin, TestNG and Selenium in Java. Using a Maven project with Intellij.
I am able to launch my Test Case when I launch them in the .feature file but when I use the testng.xml file or the Test Runner class, it somehow ignores the Test Case.
I have already checked the project settings which seems to be properly configured. Also checked that I have proper dependencies in my pom.xml (I hope I do)
My test.feature
Feature: Xray Jira
#TEST_01 #STC
Scenario: Xray Jira Testing
Given The user login to the application
When the credentials are entered
Then the homepage is viewed
My test Runner
package Runners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
#CucumberOptions(
features = "src/test/resources/",
glue = {"src/test/Steps/"},
plugin = {
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json"
})
public class UITest extends AbstractTestNGCucumberTests {
}
My step definition - the following code in the step definitions are
working when I launch the test case from the feature file
package Steps;
import Pages.BasePage;
import Pages.HomePage;
import Pages.LoginPage;
import Helper.ConfigFileReader;
import io.cucumber.java.en.*;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
public class MyStepdefs extends BasePage {
private WebDriver driver = null;
private Hooks lHooks;
public MyStepdefs(Hooks lHooks) {
this.driver = lHooks.driver;
}
#Given("The user login to the application")
public void the_user_login_to_the_application() {
LoginPage loginObject = new LoginPage(driver);
resultValue = loginObject.VerifyUrl();
Assert.assertTrue(resultValue);
}
#When("the credentials are entered")
public void the_credentials_are_entered() {
ConfigFileReader config = new ConfigFileReader();
String userID = config.getUserID();
String userPassword = config.getUserPassword();
LoginPage loginObject = new LoginPage(driver);
loginObject.enterName(userID);
loginObject.enterPassword(userPassword);
loginObject.clickLoginButton();
HomePage lHome = new HomePage(driver);
resultValue=lHome.verifyMenuIsDisplayed();
Assert.assertTrue(resultValue);
}
#Then("the homepage is viewed")
public void the_homepage_is_viewed() {
HomePage homeObject = new HomePage(driver);
resultValue=homeObject.verifyMenuIsDisplayed();
Assert.assertTrue(resultValue);
}
My POM.xml
//Below is my POM.xml I usually followed different tutorials online to get the dependencies. I had issues with compatibility of different version of the dependencies. I was able to correct them. Not sure if it is still the problem
<?xml version="1.0" encoding="UTF-8"?>
<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>execute_auto</groupId>
<artifactId>execute_auto</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>5.0.0</version>
</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/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.7.1</version>
</dependency>
<!-- Web driver manager dependency -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.2</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
<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.21.0</version>
<configuration>
<suiteXmlFiles>testng.xml</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.15.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>POC-language-testing</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My expected result should be that the test is passed. But it is always ignored when launched via testng.xml or the runner class. I would be more than glad if anyone could he be of help
PS: My final objective is to automate and launch test cases on Intellij with Cucumber and Java using Page Object Model. This should update the test cases on Xray in Jira. If anyone has any useful link with respect to such functionalities, it would be much appreciated.
The glue element should be a package name, not a directory. So if your steps are in the package Steps then the glue should be Steps.
Additionally TestNG swallows the message in the SkipException exceptions thrown by Cucumber so you should add the summary plugin to see why Cucumber skipped the test (most likely due to an undefined step because you didn't have the glue configured properly).
#CucumberOptions(
features = "src/test/resources/",
glue = {"Steps"},
plugin = {
"summary"
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json"
})
public class UITest extends AbstractTestNGCucumberTests {
}
As an aside: You should not include transitive dependencies in your pom. You can and should remove the cucumber-core, gherkin and cucumber-jvm-deps dependencies.
I have a java config.properties file which reads as follows:
mosURL=${mosURL}
mopURL=${mopURL}
I am wanting to pass in the values to ${mosURL} and ${mopURL} when I initiate my build with Maven. These properties are environment specific URL's.
My POM file is below and you can see I have set up property profiles for each environment. (EDIT. POM Example now contains suggestted changes mentioned in Anser below.) I have set env-uat as my default by having <activeByDefault>true</activeByDefault> present in the env-uat section.
But when I run mvn test everyting starts off as expected but when the test fails when attempting to use the URL and I get an error to inform me that no URL is present. So somewhere the link of passing from pom.xml into config.properties isnt working.
I can run "mvn help:active-profiles" from command and I can see the following:
The following profiles are active:
- env-uat (source: com.mycompany.app:my-app:1)
Is there a missing link that I dont know about?
EDIT: I can run mvn resources:resources and when I look at the generated .properties file in the target/classes folder I can see that all the properties are listed correctly as I would expect. But they are not being passed into my java propeties.config file when I run 'mvn test'.
I have started reading about Spring and wondering if I need to configure something with Spring to get these values form Maven into my Java file? The Maven population of the properties look fine.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<mosURL>https://mos-uat.mywebsiteurlishere.com</mosURL>
<mopURL>https://mop-uat.mywebsiteurlishere.com/</mopURL>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans-xpath</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.5.2.jre9-preview</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<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.22.0</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<exclude>**/*TPOS_Run_All.java</exclude>
</includes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>env-dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<mosURL>https://mos-dev.mywebsiteurlishere.com</mosURL>
<mopURL>https://mop-dev.mywebsiteurlishere.com/</mopURL>
</properties>
</profile>
<profile>
<id>env-uat</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<mosURL>https://mos-uat.mywebsiteurlishere.com</mosURL>
<mopURL>https://mop-uat.mywebsiteurlishere.com/</mopURL>
</properties>
</profile>
</profiles>
</project>
The problem here should be connected to the "default" value of your variables.
Try adding the properties in the global properties declaration, on the top of your pom
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
//add them here aswell
<mosURL>https://mos-dev.mywebsiteurlishere.com</mosURL>
<mopURL>https://mop-dev.mywebsiteurlishere.com/</mopURL>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
I have the same configuration as yours, and the only difference seems to be this one.
Hope this helps
I'm posting this as an answer in case it's useful to anyone who may stumble across this in future.
After a discussion with the CI developer we decided that holding system specific values in my framework was the wrong approach. The property values are best held outside of Maven and let the CI environment pass them in on build. So I stripped out all environment specific properties from my POM.
I then created a separate class with static return methods to hold each of my config values such as below:
public class Config {
public static String getUrl1() {
return System.getProperty("url1");
}
public static String getUrl2() {
return System.getProperty("url2");
}
}
My code that would read these properties would be as simple as:
String strUrl1 = Config.getUrl1();
I would pass in the actual value from Maven comand such as:
mvn clean test -Durl1=https://url1goeshere.com/ -Durl2=https://url2goeshere
So it is then up to our CI developers to hold and pass in my specific variables. We are holding the environment values in Octopus which will then pass it to placeholders in TeamCity that will then construct and pass a command to Maven. So when we deploy to Dev through Octopus it will know to pass in the Dev parameters and so on for other environments.
I am using the Java implementation of Selenium WebDriver (version 2.53.0) to run some automated tests against a web application. The tests are written in Behaviour Driven Testing format using the Java implementation of Cucumber (version 1.2.3). I use Maven (version 3.3.9) to import all my dependencies and also to build and run the tests. The tests are organised into different categories using Cucumber tags. For example, I can run one category of tests tagged with #JohnnyBravo from the command line using the following commands:
cd path_to_Maven_POM_file
mvn clean test -Dcucumber.options="--tags #JohnnyBravo"
After doing some research, I found out that you can use the Maven SureFire plugin to rerun failed tests by adding "-Dsurefire.rerunFailingTestsCount=2" to the Maven command above according to this link. I then tried to rerun that category of tests using the command below while ensuring that some of them will definitely fail so as to see if they will be rerun or not:
mvn clean test -Dcucumber.options="--tags #JohnnyBravo" -Dsurefire.rerunFailingTestsCount=2
Unfortunately, the failed tests did not rerun. What am I doing wrong here ?
My POM file is shown below:
<?xml version="1.0" encoding="UTF-8"?>
<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.company</groupId>
<artifactId>regression-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<cucumber.version>1.2.3</cucumber.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.pojosontheweb</groupId>
<artifactId>monte-repack</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>src/test/resources/chromedriver/chromedriver.exe</webdriver.chrome.driver>
</systemPropertyVariables>
<!--<testFailureIgnore>true</testFailureIgnore>-->
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The Cucumber JUnit test runner class is shown below:
import com.cucumber.listener.ExtentCucumberFormatter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.HashMap;
#RunWith(Cucumber.class)
#CucumberOptions(
monochrome = false,
plugin = {
"pretty",
"html:C:/Test_Output_Data/Results/HTML/",
"json:C:/Test_Output_Data/Results/results.json",
"com.cucumber.listener.ExtentCucumberFormatter"
},
features = {"src/test/resources/"},
tags = {
"#JohnnyBravo",
//"#AgentUI", "#Smoke",
//"#GenUI", "#Smoke",
//"#GenUI", "#Regression",
}
)
public class GeneralRunnerTest {
#BeforeClass
public static void setup() {
ExtentCucumberFormatter.initiateExtentCucumberFormatter();
ExtentCucumberFormatter.loadConfig(new File("src/test/resources/extent-config.xml"));
ExtentCucumberFormatter.addSystemInfo("Browser Name", "Firefox");
ExtentCucumberFormatter.addSystemInfo("Browser version", "46.0.1");
ExtentCucumberFormatter.addSystemInfo("Selenium version", "2.53.0");
HashMap<String, String> systemInfo = new HashMap<>();
systemInfo.put("Cucumber Version", "1.2.3");
systemInfo.put("Extent Cucumber Reporter Version", "1.1.0");
ExtentCucumberFormatter.addSystemInfo(systemInfo);
}
}
Check if you are using the right version for your cucumber dependencies.
On the page for this feature on the surefire website, it says
Since of 2.21.0 the provider surefire-junit47 can rerun scenarios created by cucumber-jvm 2.0.0 and higher.
Also check if you're using the same junit provider that they've mentioned. I'm not sure which is the default provider.