Issue with building pom - maven

I have tried to run example of the project but unsuccessfully (problem with compilation project). Here is the link to this project https://github.com/serenity-bdd/serenity-demos/tree/master/jbehave-webtests
Now I'm trying to make an easy project to learn how to use Serenity with Jbehave but I have problem to create pom.xml. My pom is according to this project https://github.com/serenity-bdd/serenity-demos/tree/master/junit-webtests (I know it is not the best solution). I'm not pretty good in Maven. Here is 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>serenity-maven-jbehave</groupId>
<artifactId>imdb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<serenity.version>1.1.25-rc.3</serenity.version>
<serenity.maven.version>1.1.25-rc.3</serenity.maven.version>
<serenity.jbehave.version>1.8.0</serenity.jbehave.version>
<webdriver.driver>firefox</webdriver.driver>
</properties>
<!-- Define the Bintray repos for convenience -->
<repositories>
<repository>
<id>serenity</id>
<name>bintray</name>
<url>http://dl.bintray.com/serenity/maven</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>serenity</id>
<name>bintray-plugins</name>
<url>http://dl.bintray.com/serenity/maven</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.lambdaj</groupId>
<artifactId>lambdaj</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>core</artifactId>
<version>1.0.47</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-jbehave</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<parallel>classes</parallel>
<threadCount>5</threadCount>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<configuration>
<includes>
<include>src/main/java/*.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>1.1.25-rc.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here is HomePage.
package pages;
import org.openqa.selenium.WebElement;
import net.serenitybdd.core.annotations.findby.By;
import net.serenitybdd.core.annotations.findby.FindBy;
import net.serenitybdd.core.pages.PageObject;
import net.thucydides.core.annotations.DefaultUrl;
#DefaultUrl("https://www.imdb.com")
public class HomePage extends PageObject {
#FindBy(xpath="#navUserMenu.css_nav_menu.js_nav_item")
WebElement downArrowButton;
#FindBy(css="#first_name.reg_thick")
WebElement firstNameInput;
#FindBy(css="#last_name.reg_thick")
WebElement lastNameInput;
#FindBy(css="#year.reg_thick")
WebElement yearOfBirthInput;
#FindBy(css="#gender_m.reg_radio")
WebElement genderMaleRadioButton;
#FindBy(css="#postal.reg_thick")
WebElement zipPostalCodeInput;
#FindBy(css="#email.reg_thick")
WebElement emailInput;
#FindBy(css="#password1.reg_thick")
WebElement passwordInput;
#FindBy(css="#password2.reg_thick")
WebElement passwordConfirmInput;
#FindBy(css="div.reg_right input.btn2.large.primary")
WebElement RegisterButton;
public static String userName;
public void showMoreOptions(){
WebElement downArrow = getDriver().findElement(By.cssSelector("div[id='nb_personal'] span[class='downArrow']"));
downArrow.click();
}
public void clickRegisterButton() {
WebElement register = getDriver().findElement(By.linkText("Register"));
register.click();
}
public void fillRequiredFields(String firstName, String lastName, String email, String password) throws InterruptedException {
firstNameInput.sendKeys(firstName);
lastNameInput.sendKeys(lastName);
String yearOfBirth= String.valueOf(randomWithRange(1950, 1999));
yearOfBirthInput.sendKeys(yearOfBirth);
genderMaleRadioButton.click();
String zipPostalCode = String.valueOf(randomWithRange(10000, 99999));
zipPostalCodeInput.sendKeys(zipPostalCode);
userName= "usermail" + System.currentTimeMillis();
email = userName + "#mailinator.com";
emailInput.sendKeys(email);
passwordInput.sendKeys(password);
passwordConfirmInput.sendKeys(password);
RegisterButton.click();
Thread.sleep(5000);
}
public int randomWithRange(int min, int max) {
int range= (max-min) +1;
return (int) ((Math.random() * range) + min);
}
}
Here is ImdbSteps
package steps;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import net.thucydides.core.annotations.Steps;
import net.thucydides.core.steps.ScenarioSteps;
import pages.HomePage;
public class ImdbSteps extends ScenarioSteps {
private static final long serialVersionUID = 1L;
#Steps
HomePage homePage;
#Given("I am on the imdb site")
public void userWantsVisitSite() {
homePage.open();
}
#When ("I am cliking on register button")
public void userIsClickingRegisterButton() {
homePage.showMoreOptions();
homePage.clickRegisterButton();
}
#Then ("I am filling required fields")
public void userIsFillingRequiredFields(String firstName, String lastName, String email, String password) throws InterruptedException {
homePage.fillRequiredFields(firstName, lastName, email, password);
}
}
Edit:
How should I build pom.xml base on code above? I tried to build this pom.xml with the instruction in link belove
http ://thucydides.info/docs/serenity-staging/#introduction
but I haven't succeed.
Could someone give me a link to the workable project which uses Serenity, Jbehave and Maven? Or any clue how to solve this problem.Thank to in advance.

Related

My Spring boot mvc project runs on STS but not running after building jar/war

The pom.xml
4.0.0
<groupId>com.birol</groupId>
<artifactId>EMS_WEB</artifactId>
<version>1.0.1-SNAPSHOT</version>
<name>EMS_WEB</name>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- 2fa -->
<dependency>
<groupId>org.jboss.aerogear</groupId>
<artifactId>aerogear-otp-java</artifactId>
<version>${aerogear.version}</version>
<scope>compile</scope>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>${javax.el.version}</version>
</dependency>
<!-- Password Validation -->
<dependency>
<groupId>org.passay</groupId>
<artifactId>passay</artifactId>
<version>${passay.version}</version>
</dependency>
<!-- Spring Data JPA dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- DB dependencies -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- User Agent parser -->
<dependency>
<groupId>com.github.ua-parser</groupId>
<artifactId>uap-java</artifactId>
<version>${uap-java.version}</version>
</dependency>
<!-- maxmind dependency -->
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>${geoip2.version}</version>
</dependency>
<!-- test -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>${logstash-logback-encoder.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.1-GA</version>
</dependency>
</dependencies>
<build>
<finalName>EMS_WEB</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<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.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<systemPropertyVariables>
<!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<java-version>1.8</java-version>
<javax.servlet.jsp-api.version>2.3.2-b01</javax.servlet.jsp-api.version>
<javax.el.version>2.2</javax.el.version>
<jstl.version>1.2</jstl.version>
<guava.version>20.0</guava.version>
<passay.version>1.0</passay.version>
<logstash-logback-encoder.version>4.8</logstash-logback-encoder.version>
<aerogear.version>1.0.0</aerogear.version>
<uap-java.version>1.4.0</uap-java.version>
<geoip2.version>2.15.0</geoip2.version>
</properties>
The error i am getting. this does not happen when i run it on STS as a spring boot project. But after building war , the war wont run
web - 2022-04-30 00:59:20,572 [main] WARN o.s.b.w.s.c.GbHi8bXd2f26Vj8NqmcnHFztp53C1pSdpVjsf9ANBCtpYHvWau - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'registrationListener': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'passwordEncoder'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'secSecurityConfig': Unsatisfied dependency expressed through field 'myAuthenticationSuccessHandler';
Main class. should i add component scanner to this?
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
#Bean
public RequestContextListener requestContextListener() {
return new RequestContextListener();
}
}
RegistrationListener.java . Am i missing any tags/annotations?
#Component
public class RegistrationListener implements
ApplicationListener<OnRegistrationCompleteEvent> {
#Autowired
private IUserService service;
#Autowired
private MessageSource messages;
#Autowired
private JavaMailSender mailSender;
#Autowired
private Environment env;
// API
#Override
public void onApplicationEvent(final OnRegistrationCompleteEvent event) {
this.confirmRegistration(event);
}
private void confirmRegistration(final OnRegistrationCompleteEvent event) {
final User user = event.getUser();
final String token = UUID.randomUUID().toString();
service.createVerificationTokenForUser(user, token);
final SimpleMailMessage email = constructEmailMessage(event, user, token);
mailSender.send(email);
}
//
private SimpleMailMessage constructEmailMessage(final OnRegistrationCompleteEvent event, final User user, final String token) {
final String recipientAddress = user.getEmail();
final String subject = "Registration Confirmation";
final String confirmationUrl = event.getAppUrl() + "/registrationConfirm?token=" + token;
String message= "Your SECRET for Google Authenticator: "+user.getSecret()+"\n";
message+= messages.getMessage("message.regSuccLink", null, "You registered successfully. To confirm your registration, please click on the below link.", event.getLocale());
final SimpleMailMessage email = new SimpleMailMessage();
email.setTo(recipientAddress);
email.setSubject(subject);
email.setText(message + " \r\n" + confirmationUrl);
email.setFrom(env.getProperty("support.email"));
return email;
}
}
IUserService.java Tried both with and without the #Service annotation
#Service
public interface IUserService {
User registerNewUserAccount(UserDto accountDto);
User getUser(String verificationToken);
void saveRegisteredUser(User user);
void deleteUser(User user);
void createVerificationTokenForUser(User user, String token);
VerificationToken getVerificationToken(String VerificationToken);
VerificationToken generateNewVerificationToken(String token);
void createPasswordResetTokenForUser(User user, String token);
User findUserByEmail(String email);
PasswordResetToken getPasswordResetToken(String token);
Optional<User> getUserByPasswordResetToken(String token);
Optional<User> getUserByID(long id);
void changeUserPassword(User user, String password);
boolean checkIfValidOldPassword(User user, String password);
String validateVerificationToken(String token);
String generateQRUrl(User user) throws UnsupportedEncodingException;
User updateUser2FA(boolean use2FA);
List<String> getUsersFromSessionRegistry();
NewLocationToken isNewLoginLocation(String username, String ip);
String isValidNewLocationToken(String token);
void addUserLocation(User user, String ip);
}

Asciidoctor "Snippets" is missing in Maven

When I run the test case then requests and responses of adoc type will be created and displayed in JSON format under the generated-snippets directory. when I run this mvn command mvn clean package to create jar and HTML type of index under the generated-docs then following warning has occurred
when I open the index.html via browser then Unresolved directive in index.adoc is displayed instead of JSON result as a response.
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle/ojdbc6 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>config-demo</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>product</doctype>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
index.adoc
= Nafaz Benzema Getting Started With Spring REST Docs
This is an example output for a service running at http://localhost:9090:
==GET API Example
.request
include::{snippets}/getAllProduct/http-request.adoc[]
.response
include::{snippets}/getAllProduct/http-response.adoc[]
As you can see the format is very simple, and in fact you always get the same message.
Controller Test class
#ExtendWith({RestDocumentationExtension.class, SpringExtension.class})
#WebMvcTest
#AutoConfigureRestDocs(outputDir = "/target/generated-snippets")
public class ProductControllerTest {
#Autowired
private WebApplicationContext webApplicationContext;
#MockBean
private ProductService productService;
private MockMvc mockMvc;
List<Product> products =null;
#BeforeEach
public void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider documentationContextProvider) {
this.mockMvc = MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.apply(MockMvcRestDocumentation.documentationConfiguration(documentationContextProvider))
.build();
products=getProducts();
}
#Test
public void getAllProduct() throws Exception {
String expectedProduct=new ObjectMapper().writeValueAsString(products);
Mockito.when(productService.getAllProduct()).thenReturn(products);
MvcResult result= mockMvc.perform(get("/products")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
.andExpect(content().json(expectedProduct))
.andDo(document("{methodName}",preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())))
.andReturn();
String actualProduct=result.getResponse().getContentAsString();
Assertions.assertEquals(expectedProduct,actualProduct);
}
private List<Product> getProducts()
{
Product product_1=new Product();
product_1.setProductId(1001);
product_1.setProductName("Penguin-ears");
product_1.setNumberOfUnitInCartoon(20);
product_1.setPriceOfCartoon(175.00);
product_1.setUrlOfImage("https://i.ibb.co/pLdM7FL/shutterstock-306427430-scaled.jpg");
Product product_2=new Product();
product_2.setProductId(1002);
product_2.setProductName("Horseshoe");
product_2.setNumberOfUnitInCartoon(5);
product_2.setPriceOfCartoon(825);
product_2.setUrlOfImage("https://i.ibb.co/MRDwnqj/horseshoe.jpg");
return new ArrayList<>(Arrays.asList(product_1,product_2));
}
}
The solution has been found. We have to add spring-restdocs-asciidoctor dependency inside the plugin which it belongs.
Remove spring-restdocs-asciidoctor dependency from the global dependency management space and add it inside the plugin
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>product</doctype>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
</dependencies>
</plugin>

Getting Parser Error: inconsistent cell count within the table - while running tests in Parallel - Selenium Cucumber Maven framework with Junit

I have configured Selenium-cucumber maven framework with Junit. After adding the cucumber-jvm-parallel plugin & maven-surefire plugin , commented the statements inside #CucumberOptions which we have written inside TestRunnerTest.java file .After configuring like this, run through CLI . Then my test script fails. But Runners are created automatically for the feature file.
POM file is shown below :
<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>selcuc</groupId>
<artifactId>DemoEurasia</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CucumberParallel</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.cucumber>3.0.2</version.cucumber>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy_MM_dd_HH_mm</maven.build.timestamp.format>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<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-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency> -->
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>acceptance-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/*IT.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>validate</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>stepDefinition</glue>
<outputDirectory>target/generated-test-sources/cucumber</outputDirectory>
<featuresDirectory>src/test/resources/</featuresDirectory>
<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
<format>html</format>
<strict>true</strict>
<monochrome>true</monochrome>
<tags>"~#ignore"</tags>
<filterFeaturesByTags>true</filterFeaturesByTags>
</configuration>
</execution>
</executions>
TestRunnerTest.java is shown below :
package testRunner;
#RunWith(Cucumber.class)
#CucumberOptions(
// features = "src/test/resources/1login.feature"
// , tags= {"#Login or #quickSearch"}
// , glue= {"stepDefinition"}
// , plugin = { "com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"},
monochrome = true
public class TestRunnerTest {
public static WebDriver driver;
public static String timeStamp = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a").format(new Date());
public static String browserName;
private static TestRunnerTest sharedInstance = new TestRunnerTest();
private TestRunnerTest() { }
public static TestRunnerTest getInstance() {
return sharedInstance;
}
#BeforeClass
public static void before() {
browserName = System.getProperty("browserName");
if(browserName==null)
{
browserName= "firefox";
}
if (browserName.equalsIgnoreCase("Chrome"))
{
System.setProperty("webdriver.chrome.driver", "E:\\ChromeDriverNew\\chromedriver.exe");
driver=new ChromeDriver();
}
else if (browserName.equalsIgnoreCase("Firefox"))
{
System.setProperty("webdriver.gecko.driver","E:\\geckoNew\\geckodriver.exe");
driver = new FirefoxDriver();
}
else {
System.out.println("Error Message----> "
+ "browser name not mentioned properly");
System.exit(0);
}
driver.manage().window().maximize();
// driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#AfterClass
public static void after() {
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
{
try {
Reporter.loadXMLConfig(new File("config/report.xml"));
Files.move(Paths.get("target/cucumber-reports"), Paths.get("target/cucumber-reports_ "+
LocalDateTime.now().format(DateTimeFormatter.ofPattern("L-d-YYYY h-m-s")) + "_" + browserName),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
});
if(driver!=null)
driver.quit();
}
}
Run this in CLI mvn test.
Then getting the below error:
# DemoEurasia ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.901 s
[INFO] Finished at: 2018-09-27T15:11:17+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.temyers:cucumber-jvm-parallel-plugin:2
.1.0:generateRunners (generateRunners) on project DemoEurasia: Execution generat
eRunners of goal com.github.temyers:cucumber-jvm-parallel-
plugin:2.1.0:generateR
unners failed: Parser errors:
[ERROR] (17:3): inconsistent cell count within the table
I don't know where I am wrong. It would be a great help if you guys helped me. Could you please help me guys. Thanks in advance
That happens because some of all the features of the Scenario Outline the Examples table is not complete
for example
Examples:
| user | password | rememberAccount |
| user01 |
absolutely all pipelines ( | ) must be completed:
Examples:
| user | password | rememberAccount |
| user01 | | |

Maven/ TestNg can't find allure #step annotation

Having a problem to implement allure #Step annotation into my maven project (tetsng, java).
(Updated) Sharing pom file:
eproject 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>src</groupId>
<artifactId>AutomationTestSuit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src\main\resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src\test\resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</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.21.0</version>
<configuration>
<suiteXmlFiles>
<file>${project.basedir}/suites/smoke.xml</file>
</suiteXmlFiles>
<systemPropertyVariables>
<environment.properties>/environment.properties</environment.properties>
</systemPropertyVariables>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>e
I'm trying to add Step annotation to the page class but it gets the failure:
package com.pages.login_page;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
public class LoginPageElements {
private WebDriver driver;
#FindBy(how = How.ID, using = "test")
private WebElement logonID;
#FindBy(how = How.ID, using = "test")
private WebElement logonPassword;
#FindBy(how = How.ID, using = "test")
private WebElement logonSubmit;
public LoginPageElements(WebDriver driver)
{
this.driver = driver;
PageFactory.initElements(driver,this);
}
#Step("login step") //step is underlined on this place with can't resolve symbol Step error
public void Login_as(String sUsername, String sPassword) {
logonID.sendKeys(sUsername);
logonPassword.sendKeys(sPassword);
logonSubmit.click();
}
#Step error example
the same problem I'm having with #Attachments while implementing it inside of MytestListener class:
see the screenshot
Please help me to figure out the problem.
I noticed that you are using out dated version of Allure. Here is correct import
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.6.0</version>
</dependency>
With Allure 2 you do not need to configure Listener, but you need to configure AspectJ instead. Here you can find example for Maven + TestNG: https://docs.qameta.io/allure/#_testng
THE PROBLEM was with the idea community version. It appears that it doesn't support aspectj plugin. If someone will struggle with same issue please tale a look: https://www.jetbrains.com/help/idea/java-compiler.html
I my case the problem was in <scope>test</scope>.
I removed it from dependancy:
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>LAST_VERSION</version>
<scope>test</scope>
</dependency>
and #Step annotation starts to be recognized.

Allure not attaching to html report

I am trying to attach a screen shot to my allure report however I am failing miserably.
#Test (priority = 1, description="SS1 Verify the login section")
#Description ("Verify that user mngr116116 can logon to the system")
public void login()
{
page = new BankingLandingPage();
System.out.println("Test Case One in " + getClass().getSimpleName()
+ " with Thread Id:- " + Thread.currentThread().getId());
page.enterUser("mngr116116");
page.enterPass("ytUhUdA");
page.submitBtn();
page.saveImageAttach();
}
The saveImageAttach code in the Page class is as follows:
#Attachment
public byte[] saveImageAttach() {
try {
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
return screenshot;
} catch (Exception e) {
e.printStackTrace();
}
return new byte[0];
}
What am I missing?
Report screen shot attached
enter image description here
Probably of note I have the following method also in my page class and it works a treat:
public void screenShot(String title) throws Exception {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String png = ("src/main/resources/screenshot/" + title + ".png");
FileUtils.copyFile(scrFile, new File(png));
}
So it would appear to be how I am implementing #Attachment
<?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>org.framework</groupId>
<artifactId>framework</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<aspectj.version>1.8.13</aspectj.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.0-BETA21</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<properties>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<!-- those are the two default values, you can probably skip them -->
<forkCount>7</forkCount>
<reuseForks>true</reuseForks>
<!-- that's what made it work -->
<parallel>classes</parallel>
<threadCount>10</threadCount>
<includes>
<include>src/test/java/testsuite/*class</include>
</includes>
</properties>
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.20.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.8</version>
</plugin>
</plugins>
</reporting>
</project>
adding my pom as well in case that sheds any light
after save screenshot into file in screenShot(..) convert file in ByteArray. Example (kotlin):
fun returnScreenshot(screenshotPath: String): ByteArray {
val screenFile = File(screenshotPath)
val screenFileInBytes = ByteArray(screenFile.length().toInt())
val fis = FileInputStream(screenFile)
fis.read(screenFileInBytes)
fis.close()
return screenFileInBytes
}
then return this screenshot in ByteArray with #Attachment.
Example (java):
public interface ReportInterface {
String screenshotPath();
#Attachment(value = "current screenshot", type = "image/png")
default public byte[] showCurrentScreen() {
return ScreensHelperKt.returnScreenshot(screenshotPath());
}
After implement your test class by this ReportInterface and implement screenshotPath() to return screenshot path.
Call screenShot(String title) and showCurrentScreenshot() in test body or in teardown, or after failed test(with testRule). But make sure that showCurrentScreenshot() is runble anyway.
Hope, it helps.
try running the following code instead:
#Attachment(value = "screenshot", type = "image/png")
public byte[] saveScreenshotPNG (WebDriver driver) {
return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
}

Resources