Getting 0 Scenarios 0 Steps after running the Test Runner file - junit

Below is the Test Runner File
package runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features="D:/InstalledSoftwares/Eclipse_Photon/workspace/March26/src/test/resources/features/login.Feature",
glue= {"D:/InstalledSoftwares/Eclipse_Photon/workspace/March26/src/test/java/stepDefinitions/LoginSteps.java"})
public class TestRunner {
}
Below is the Feature File-
Feature: Create Account on Facebook
Scenario: Check First Name
Given: User is already on Login Page
When: Enter First Name
And: Enter Last Name
Then: Check if value of First Name is there
Below is the Step Definition-
package stepDefinitions;
import cucumber.api.java.en.Given;
public class LoginSteps {
#Given("^User is already on Login Page$")
public void User_is_already_on_Login_Page()
{
}
}
Below is the Snapshot of Eclipse.
This is how my Project structures look like

Related

Cucumber runner class, parallel execution

I've integrated Cucumber with JUnit / Browserstack. When the cucumber runner class is executed in parallel (by Browserstack code) it generates the same report three times with the same name (effectively being overwritten each time).
Is there way this can be parameterised, so at runtime the report is generated with a unique name?
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "html:target/cukes/htmlreport.html",
"json:target/cucumber/jsonReports/",
},
glue = "/testFrameworks/cucumberSelenium/steps",
tags = "#sunny_day",
features = "src/test/resources/features/cucumber"
)
public final class CucumberRunner {
}

Field personRepositary in () required a bean of type () that could not be found

I am trying to run a spring developed web app and I'm getting the following error.
My folder structure is as follows.
Here is my PersonRepositary.java code which is inside the repositary folder.
package com.travelx.travelx.repositary;
import org.springframework.data.repository.CrudRepository;
import com.travelx.travelx.models.Person;
public interface PersonRepositary extends CrudRepository<Person, Integer> {
}
The RegisterController.java file which is in the controllers folder is ac follows.
package com.travelx.travelx.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.travelx.travelx.models.Person;
import com.travelx.travelx.repositary.PersonRepositary;
#RestController
#RequestMapping("register")
public class RegisterController {
#Autowired
private PersonRepositary personRepositary;
#PostMapping("login")
public String registerPerson(#RequestBody Person person) {
personRepositary.save(person);
return "You are Registered!";
}
}
And the TravelXApplication.java file which is in the controllers is below.
package com.travelx.travelx.controllers;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
#SpringBootApplication
#ComponentScan
#EntityScan
#EnableJpaRepositories
public class TravelxApplication {
public static void main(String[] args) {
SpringApplication.run(TravelxApplication.class, args);
}
}
I'm trying to make a web page where a person can register to a site. Here, I'm using xampp as my platform to handle the back end. As shown in the image, the controllers, repositories and and models are implemented in separate folders. I'm new to Spring. So no matter how hard I to find what the problem is, I cant seem to find it. Can some one help me please?
--------------UPDATE------------------
I've moved my TravelXApplication.java to the com.travelx.travelx and now this error is gone.Spring works fine. However when I open my form, insert data and try to save it, the browser gives me the following error.
How do I solve it?
Your PersonRepositary is not registered as a bean in your Spring context. In practice, this means that Spring is not be able to inject it in your RegisterController.
I suspect that #EnableJpaRepositories, #EntityScan and #ComponentScan are unnecessary in your main application class and are actually causing Spring automatic configuration to be overridden. Try deleting these three annotations from TravelxApplication.
Here's the answer to why it should still work without annotations.
Update: just noticed that your TravelxApplication is located in the controllers package, but then it won't have visibility to your repository. Make sure to move your main class to the com.travelx.travelx package.

Host apple-app-association-file in tomcat web server

We have a requirement of enabling universal link in our application. We have a java based web application(spring) and a iOS app. To enable universal link as per apple we need to create a json file apple-app-association-file and host this file in the server.
Now java web app is deployed in tomcat in windows server and apche 2.4 is being used as web server. Please let me know how to host the apple-app-association-file in the tomcat or web server or inside the war file(inside the code), we are using maven structure.
according to docs, we need to remove the file extentsion and file should be access as below:
url of web app: https://xyz.example.com
where xyz.example.com is mapped to a web app which is there in webapp folder in tomcat.(localhost:8080/webApp)
apple-app-association-file to be accessed as: https://xyz.example.com/apple-app-association-file
now as the extension is not there how can i host it.Do i need to make the code changes and treated it as servle request. Even if i do so it wont be a good idea to execute a servet just to access a file
Also, it's also important that the file is served with the correct MIME-type, for Universal Links it can be served as application/json. How to set mime type in tomcat or java web app(spring)
First rename file to apple-app-site-association.json, then write next Spring configuration:
#EnableWebMvc
public class WebClientConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/.well-known/*")
.addResourceLocations("/path/to/your/static/resources")
.resourceChain(true)
.addResolver(new PathResourceResolver() {
#Override
protected Resource getResource(String resourcePath, Resource location) throws IOException {
if (resourcePath.equals("apple-app-site-association")) {
return location.createRelative("apple-app-site-association.json");
}
return super.getResource(resourcePath, location);
}
});
}
}
As described here: developer.apple.com
You can place the file at the root of your server or in the .well-known subdirectory.
Then the file will be served with the correct MIME-type "application/json" and accessed as: https://xyz.example.com/.well-known/apple-app-association-file
The Solution from pITer Simonov works for me! But i had to add the root path
inside
< servlet-mapping > (in web.xml)
like this:
< url-pattern >/</url-pattern >
After that, the resource handler work fine!
I did it with a standard REST controller + endpoint.
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
#RestController
#RequestMapping("/.well-known")
#Slf4j
public class WebClientConfig {
#GetMapping(value = "/apple-app-site-association",
produces = MediaType.APPLICATION_JSON_VALUE)
public String addResourceHandlers() {
String json = "";
InputStream inputStream = getClass().getResourceAsStream("/apple-app-association.json");
try(InputStream stream = inputStream) {
json = StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
} catch (IOException ioe) {
log.error("Apple app association could not be retrieved! iOS app will be impacted. Error: " +
ioe.getMessage());
}
return json;
}
}
Note: the apple-app-asociation.json file is under src/main/resources

running testrunner with cucumber

I am having problem running testrunner with cucumber. I need someone to help me check the #CucumberOptions. Thank you
package stepDefinition;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith (Cucumber.class)
#CucumberOptions (features = "Feature"
,glue={"stepDefinition"})
public class testRunner {
}
#RunWith(Cucumber.class) is for JUnit integration.
If you want to use Cucumber with TestNG, you have to extends your class with AbstractTestNGCucumberTests.
You should have a look on https://github.com/lionhearth/cucumber-testng which is a perfect sample.
Here is my Test. I have both step definitions/featurefiles in src as packages. Also, i downloaded the cucumber plugin yet i can't see the colors showing in my features. How do reference feature and step definitions #cucumberoptions.
package stepDefinition;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class aptitudeTest {
#Given ("^I have successfully ([^\"]*)$")
public void I_have_(String str)
{
if (str.equals("registered"))
{
System.out.println("registered Automation");
}
if (str.equals("unregistered"))
{
System.out.println("unregistered");
}
}
#When ("^I enter my valid ([^\"]*)$")
public void I_enter_(String str)
{
if (str.equals("credentials"))
{
System.out.println("credentials Automation");
}
if (str.equals("details"))
{
System.out.println("details");
}
}
#Then ("^I should see the welcome([^\"]*)him $")
public void I_should_(String str)
{
if (str.equals("message"))
{
System.out.println("message Automation");
}
if (str.equals("information"))
{
System.out.println("infomation");
}
}
}
Here is my feature
Feature: Login to account
#tester
Scenario:I should see a message when i successfully logged in
Given I have successfully registered
When I enter my valid credentials
Then I should see the welcome message
Given I have successfully unregistered
When I enter my valid detail
Then I should see the welcome message

JUnit NoClassDefFoundError

I'm new at JUnit and use inteliji idea.
import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.util.Date;
import static org.junit.Assert.*;
public class TestQuote {
#Test
public void testQuote() {
Date date = new Date(System.currentTimeMillis());
Quote quote=new Quote("a",date,200.0,300.0,100.0,107.0,1.0);
assertNull("Object is null",quote);
assertEquals("Symbol is ok",quote.getSymbol(),"a");
assertEquals("Date is ok",quote.getDate(),System.currentTimeMillis());
assertEquals("Open price is ok",quote.getOpenPrice(),200.0);
assertEquals("High price is ok",quote.getHighPrice(),300.0);
assertEquals("Low price is ok",quote.getLowPrice(),100.0);
assertEquals("Close price is ok",quote.getClosePrice(),107.0);
}
}
Here is code of my test class. JUnit.jar is added to classpath but when i run it it says:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
Any sollutions?
BTW main program work OK.
Go to the JUnit web site: http://junit.org/
Then click on "Download and install Guide" : https://github.com/junit-team/junit/wiki/Download-and-Install
Then read:
Download the following JARs and put them on your test classpath:
junit.jar
hamcrest-core.jar