BDD-JAVA- Is it possible to generate cucumber html reports with only scenario titles with out steps - cucumber

I am currently using an HTML formatter to generate the Cucumber HTML report. The report is pretty, but I want the reports to be generated with all scenarios only with the title so that my report is not huge and easy to know which scenarios failed.
To clarify more, when cucumber HTML report is generated. I am seeing headers are divided into Steps (Passed, Failed, Skipped, Pending, Undefined), Scenarios(Passed, Failed, Skipped, Pending, Undefined), Feature. I just wanted to customize and print only Scenarios and remove steps section
enter image description here
public class HtmlFormatter extends CucumberJSONFormatter {
private static final String TIMESTAMP_FORMAT = "d MMM yyyy HH:mm:ss:SSS z";
public HtmlFormatter(Appendable out) {
super(out);
}
#Override
public void done() {
super.done();
final List<String> jsonFiles = new ArrayList<>();
final ConfigReader configReader = new ConfigReader();
final File reportOutputDirectory = new File("reports/html");
final int numThreads = Integer.valueOf(configReader.getProperty("maxThreads", "4"));
//in case running from single feature file
if (Main.isFeatureFileExecution()) {
final String singleFeatureFileExecutionReportPath = "reports/"+configReader.getProperty( "repo","RepoNameNotFound" ) +"/json/report.json";
if (new File(singleFeatureFileExecutionReportPath).exists()) {
jsonFiles.add(singleFeatureFileExecutionReportPath);
}
}
String projectName = “X”;
boolean runWithJenkins = true;
boolean parallelTesting = true;
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
configuration.setParallelTesting(parallelTesting);
configuration.setRunWithJenkins(runWithJenkins);
if (!jsonFiles.isEmpty()) {
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
Reportable result = reportBuilder.generateReports();
}
}

Write your own custom reporter based on the HTML reporter. As you are just trying to remove a small bit of functionality from the reporter this shouldn't be to difficult. Then use your reporter when running cucumber.

Related

Is it possible to see scenarios in feature files in the runner window while running parallel in karate?

When I run my tests with a parallel runner, I can't see scenarios in the feature files in which one failed or successful. I want to see these scenarios on the runner window in IntelliJ Idea. I am using parallel runner for cucumber reports.
Here is my code
#Test
public void testParallel() {
List<String> features = Arrays.asList("classpath:features");
Results results = Runner.path(features)
.outputCucumberJson(true).tags("~#ignore")
.karateEnv("deee")
.parallel(1);
generateReport(results.getReportDir());
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
List<String> jsonPaths = new ArrayList<>(jsonFiles.size());
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "deee");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
The parallel runner does not integrate with the IDE view. It is designed for CI execution.
This other answer may explain the difference and why: https://stackoverflow.com/a/65578167/143475

How is the parallel runner running the feature files

I have set the following code in my java file:
#CucumberOptions(tags = {"~#ignore"})
public class ExamplesTest {
#BeforeClass
public static void before() {
System.setProperty("karate.env", "dev");
}
#Test
public void testParallel() {
String karateOutputPath = "target/surefire-reports";
KarateStats stats = CucumberRunner.parallel(getClass(), 1, karateOutputPath);
generateReport(karateOutputPath);
assertTrue("there are scenario failures", stats.getFailCount() == 0);
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
List<String> jsonPaths = new ArrayList(jsonFiles.size());
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "demo");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
As you can see, i have set the thread count to 1 , but even if i increase it i see no difference in the execution time.
I am not very sure how the parallel run is happening.
Can someone please explain.
Currently the unit of parallelization is at the feature file level. This means:
if you have 1 feature there is no effect
if you have multiple features but one of them takes a very long time, the test will run for that amount of time

Intellij Idea Live Template to create field and method at same time

How to create field variable automatically when I create method used that field. I've create template like this:
void $METHOD_NAME$() {
$FIELD_NAME$ = true;
}
when I type field name (e.g. mState) in method will create field as:
private boolean mState = false;
Hope someone help. Sorry my bad.
Given the screenshot of your template, you can also create a field with the following live template:
private boolean $param$ = false;
#Override
public void onBackPressed() {
if ($param$) super.onBackPressed();
android.widget.Toast.makeText(this, "$message$",
android.widget.Toast.LENGTH_SHORT).show();
$param$ = true;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
$param$ = false;
}
}, 100);
}
Where $param$ and $message$ are regular variables without anything special.
However, like I said in the comment on your question, I suggest to split it up in several smaller templates.
Consider to split it up in:
field + method with just:
private boolean $param$ = false;
#Override
public void onBackPressed() {
if ($param$) super.onBackPressed();
$param$ = true;
}
Then create a template for the message:
android.widget.Toast.makeText(this, "$message$", android.widget.Toast.LENGTH_SHORT).show();
And last but not least, create a template for the postDelayed:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
$END$
}
}, $delay$);
Note: the $delay$ as a bonus you can even give it a default value or create a list of predefined values for ease of use.
Note2: Instead of $param$ = false; I've replaced it with $END$. This will position your cursor here once you've selected the delay. Now you can type mState = false manually here, or whatever code you need in the context at that moment. This makes the template much more flexible and easier to use.
PS. I suppose you want to call super.onBackPressed() only when the value is false (on the first invocation). In that case use if (!$param$) instead.
// Update:
In order to group the newly added field with the other fields and not halfway somewhere in your class between other methods, rearrange the code
via the menu with: Code -> rearrange code.
To customise this, check your arrangement settings under: settings -> code style -> <language> -> arrangement

How to get the Gherkin feature description runtime in java

I need to report the feature description for the scenario that is being executes to report to other system.
Was able to get the scenario name from cucumber.api.Scenario; how I can the feature description ?
Is there any interface that I can use?
Using cucumber-Jvm, get the feature description runtime; as each scenario being executed might be from different feature files.
You can get the description of a feature by retrieving the Gherkin feature from CucumberFeature:
List<CucumberFeature> cucumberFeatures = new ArrayList<>();
FeatureBuilder featureBuilder = new FeatureBuilder(cucumberFeatures);
featureBuilder.parse(new FileResource(featureFile.getParentFile(), featureFile), new ArrayList());
for (CucumberFeature feature: cucumberFeatures) {
// Here we retrieve the Gherkin model
Feature f = feature.getGherkinFeature();
// Here we get name and description of the feature.
System.out.format("%s: %s%n", f.getName(), f.getDescription());
}
Another solution is to implement your own formatter, and do the parsing with Gherkin directly:
public class MyFormatter implements Formatter {
private List<Feature> features = new ArrayList<>();
public static void main(String... args) throws Exception {
OutputStreamWriter out = new OutputStreamWriter(System.out, "UTF-8");
// Read the feature file into a string.
File f = new File("/path/to/file.feature");
String input = FixJava.readReader(new FileReader(f));
// Parse the gherkin string with our own formatter.
MyFormatter formatter = new MyFormatter();
Parser parser = new Parser(formatter);
parser.parse(input, f.getPath(), 0);
for (Feature feature: formatter.features) {
System.out.format("%s: %s%n", feature.getName(), feature.getDescription());
}
}
#Override
public void feature(Feature feature) {
features.add(feature);
}
// ...
// follow all the Formatter methods to implement.
}

Sharepoint search fails when using DataKeynames

We have a Sharepoint site which uses search.
We get the following error:
Unable to validate data. at
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData
(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length,
IVType ivType, Boolean useValidationSymAlgo)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
After a bit of testing we have found that the error occurs when we use DateKeyNames on a GridView control.
Not sure why there should be any combination between Search, this error and DataKeyNames.
Any ideas?
Update: Here is some code
[Guid("8891224e-e830-4ffa-afbd-f789583d8d14")]
public class TestErrorGridView : System.Web.UI.WebControls.WebParts.WebPart
{
Control ascxToAdd;
public TestErrorGridView()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
Table test = new Table();
TestBindObject t1 = new TestBindObject() { ID = 1, Name = "Test" };
List<TestBindObject> l1 = new List<TestBindObject>();
l1.Add(t1);
SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false};
BoundField header = new BoundField();
header.DataField = "ID";
BoundField name = new BoundField();
name.DataField = "Name";
testGrid.Columns.Add(header);
testGrid.Columns.Add(name);
testGrid.DataSource = l1;
testGrid.DataBind();
// If you comment out this line search works
testGrid.DataKeyNames = new string[] { "ID" };
this.Controls.Add(testGrid);
base.CreateChildControls();
SPGridView testGrid = new SPGridView() { AutoGenerateColumns = false, EnableViewState=false };
testGrid.DataKeyNames = new string[] { "testid" };
this.Controls.Add(testGrid);
}
}
public class TestBindObject
{
public int ID { get; set; }
public string Name { get; set; }
}
UPDATE
This error occurrs on the developer machines, so it is not realated to machine keys being different on different machines in a cluster.
One of the developers has MOSS installed, he does not get the error. The developers who have just WSS installed get the error.
UPDATE 2
Have added datasource to code
I'm going to throw out a guess here since the code where you set the GridView's datasource is missing as well, but here goes...
It probably has something to do with the order in which you are setting the GridView's properties. My guess is that you need to set it in this order:
Create your GridView
Set the GridView's datasource (so that it has data)
Set DataKeyNames
Call GridView.DataBind()
Step 3 and 4 are the steps I am not sure about. You may have to DataBind and then set DataKeyNames.
We eventually solved this by following the example in this link:
http://msdn.microsoft.com/en-us/library/bb466219.aspx
I think that is was binding to a data table rather than a list that made the difference.
The fact that Sharepoint grids do not allow autogenerated columns appears to be one of the factors leading to this problem.

Resources