Cucumber-JVM: Cucumber After hook executed two times/twice - selenium

I"m implemnet Cucumber Testng for learning purposes. I"m realizes that #After hook method is executed twice. I can confirm it with debugging set and test report output. I"m only execute 1 feature file and my test report has two same class names.
Do you guys know why?
There is warning in the feature file called Multiple Definitions "Volare Collector Home Page opens in browser".
Please help. Thanks.
Please download my source code from this link.

Related

cucumber - "Test ignored" error while running Runner in IntelliJ

I am trying to run a simple example of cucumber-Junit in Intellij, but not geting error "Test ignored". (I have installed cucumber for Java plugin)
My feature file, Runner class, Stepdefinition class and java class look as below:
I also tried to restructure the stepdefinition and feature file in multiple ways but it did not help.
1) Does the error mean, it is not finding stepdefinition file (Feature1Steps.java) ? if yes, how do I make it find it ?
2) I am not able to run feature file (Feature1.feature) either. It says : "Test Framework quit unexpectedly"
3) I have tried 1) and 2) with both the latest Cucumber for Java plugin and an older one (183.4284.148). But that did not solve the issue.
Could someone please help me here ?
Well, I did change multiple things and would like to post it here..
1) The words in scenario in feature file and step definition file are case sensitive so I corrected it. (in feature file when I write "Given that I have a Calculator", then in step definition file also I should write ( #Given("^that I have a Calculator$")). Earlier I had small c (calculator) in first step of my step definition file.
2) I just put stepdefinition file and Runnerclass files in the same package and feature file in resources folder. see screenshot below:
After having this structure I do not require to specify glue at all in Cucumber options in Runner class. I just require to specify where my feature file exists. see below:
3) now I am using cucumber version 4.2.0. But that did not make any difference I think.
I hope this helps others.
Move the .feature file to resources/com/example.
From the Cucumber docs:
"If Cucumber is telling you that your steps are undefined, when you have defined step definitions, this means that Cucumber cannot find your step definitions. You’ll need to make sure to specify the path to your step definitions (glue path) correctly.
By default Cucumber-JVM will search in the package (or sub-packages) of the runner class. You can also tell Cucumber-JVM explicitly which packages (and sub-packages) to search, with:
#CucumberOptions(glue = {"<package>", "<package>", "<etc>"})
public class RunCucumberTest{}"
"
(Sidenote: you are using a very old version of Cucumber. v5 is about to be released.)

Selenium, questions about code re-factoring

With Selenium IDE I generate a sample script for test the log to a website and a value in the website after logging. So my script is (Java) :
#test
public void mytest() throws Exception{
// Load the home page
...
// complete the log form
...
// check if the log work
...
// Logged : click on some element in the page
...
// Logged ; check the information X (if one HTML element contains child or not
...
}
I use JUnit for run the test class from a main class. My question is : What is the best way for re-factoring my code ? I would like create one class by "step", is it possible ? by example :
Class for load page and check there isn't error 404
Class for complete the log form, submit and check if the user is logged
Class for navigate in the website and get the information I want
Is it the best way? There isn't a real goal. Just, I want know how organize the code for a maximum of reuse (sorry for my bad English x) )
There are couple of reasons why you do not want to use Selenium IDE, do the recording for the test cases and refactor the code afterwards. Most of the time selenium IDE will provide you the selectors that are not stable enough. For rerunning the tests you want to make sure the selectors are stable enough and will not possibly depend on html structure. Second, as the test suite getting larger you want to reduce the code duplication as much as possible. Using Selenium IDE there is no way to understand which code blocks can be reused.
So, bottom line is for a good test suite start building a framework from scratch instead of using Selenium IDE. There are a lot of example out there how to start. I have one with TestNG here if that helps.

How to integrate Galen reports in Jenkins

I've started to use Galen framework to test the layout of my website pages and I also have my other test, written in Selenium, integrated into Jenkins.
I'm using Java+JUnit+Maven and I would like to know if anyone has managed to integrate the Galen reporting into Jenkins and how.
Because for the moment I am using something like:
assertThat(layoutReport.errors(), is(0));
which tells me if there were errors in the tests but not where.
Thanks!
P.S. If someone with reputation could make the tag galen-framework so that we can group these type of questions, it would be great :D
In your case you could use Galen for generating HTML reports as it normally does when you run tests with it. Though you will have to manage the creation of GalenTestInfo objects.
Here is how the HTML report generation works. Imagine you have somewhere obtainAllTests method defined which returns a list of all executed tests.
List<GalenTestInfo> tests = obtainAllTests();
new HtmlReportBuilder().build(tests, "target/galen-html-reports");
Somewhere in your code you could create a GalenTestInfo and add it to some collection:
GalenTestInfo testInfo = GalenTestInfo.fromString("Here goes the name of your test");
Once you have done the layout checking and obtained LayoutReport object you could add this report to the report of the test. Here is how you can do it:
LayoutReport layoutReport = Galen.checkLayout(driver,
specPath, includedTags, null,
new Properties(), null);
testInfo.getReport().layout(layoutReport, "A title for your layout check");
You can find more insights in this project https://github.com/galenframework/galen-sample-java-tests. It has a basic setup for Galen tests in Java + TestNG + Maven. The reports in it are collected in a singleton GalenReportsContainer. There is also a reporter implemented in GalenReportingListener which takes all those tests from GalenReportsContainer and generates HTML reports.
You can see a full example for Java (TestNG and JUnit) and JavaScript here:
https://github.com/hypery2k/galen_samples.
I use the HTML Plugin together with Jenkins, see example here

Sonarqube API single class test coverage

I am trying to retrieve the unit test code coverage for individual classes through the SonarQube API (Sonar version 4.1.2). Everything is working fine, and I can see the metrics okay when I go directly to the sonar dashboard and go to the coverage tab for a class:
93.9% by unit tests Line coverage: 97.9% (285/291) Branch coverage: 85.0% (113/133)
Can anyone tell me the correct call to retrieve this same/similar information through the sonar API interface please? I've already had a look at the documentation at http://docs.sonarqube.org/display/SONAR/Metric+definitions and can get test coverage metrics back at project level but I can't see how to construct a query for individual classes.
I think this is what you are after
[hostname]/api/resources?resource=[com.test]:[module-name]:[fully qualified class]&metrics=coverage,branch_coverage
I have added an example below.
http://sonar-server/api/resources?resource=com.test:module:com.test.service.impl.CheckServiceImpl&metrics=coverage,branch_coverage
I looked at the page you shared and used this also :
http://docs.codehaus.org/pages/viewpage.action?pageId=229743280
api/measures/component_tree is your friend
result = session.get(
SONAR_BASE + "api/measures/component_tree",
params={"baseComponentId": COMPONENT, "metricKeys": "coverage" )
)
gets you coverage down to the file level. You should be able to only get the files with the "leaves" strategy.

Issue with the karate parallel runner

I wanted to see if anyone else might have observed the same issue. I looked in the project for any open/closed issues that might be like this but did not notice any.
I noticed that when I use the Karate Parallel runner (which we have been using for a while now), that every GET, POST, DELETE request gets called 2x, observed in the karate logs which came in the console.
When I do not use the Karate Parallel runner only a single request is made.
I noticed this when performing a POST to create a data source in our application. When I went to the applications UI to verify the new data source was created, I saw 2 of them. This leads me down the path to research further what might be happening.
Using Karate v0.9.5 with Junit 5
minimalistic Example -
https://drive.google.com/file/d/1UWnNtxGO7gr-_Z80MLJbFkaAmuaVGlAD/view?usp=sharing
Steps To Run The Code -
Extract ZIP
cd GenericModel
mvn clean test -Dtest=UsersRunner
Check the console logs API scenario get executed 2X
Note - It works fine for me for karate V0.9.4 with Junit 5
You mixed up parallel runner and JUnit runner and ended up having both in one test method. Please read the documentation: https://github.com/intuit/karate#junit-5-parallel-execution
Note that you use the normal #Test annotation not the #Karate.Test one.