How do I call my cucumberTestRunner from another class (cucumberTestMaster) and get it to run? Currently, it just seems to skip the tests. Below is what I have tried. I am limited by JUnit 4.8 for project reasons, and both files are written in Groovy.
//cucumberTestMaster
package cucumber
import cucumber.testRunners.CucumberTestRunner
import org.junit.runner.JUnitCore
import org.junit.runner.Result
class CucumberTestMaster {
try {
Class runner = CucumberTestRunner as Class
Result result = JUnitCore.runClasses(runner.class)
}
catch (Exception e)
{
println(e)
}
}
//cucumberTestRunner
package cucumber.testRunners
import io.cucumber.junit.Cucumber
import io.cucumber.junit.CucumberOptions
import org.junit.runner.RunWith
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/main/groovy/cucumber/features/addDeal/",
glue = "cucumber.stepDefinitions",
publish = false,
monochrome = true,
tags = "#Daily",
plugin = ["pretty", "junit:target/JUNITReports/report.xml", "html:target/HTMLReports/report.html",
"json:target/JSONReports/report.json"]
)
class CucumberTestRunner {
}
Thank you in advance for any help.
Related
I am trying to run my Cucumber scenarios in parallel using the TestNG.
But when I run it 'parallel=true' it executes the test cases in thread count=10 (testng default).
I want to customise the thread count to say 2 or 3. How do I do that.?
I want to run this through IntelliJ as well as through the command line (terminal)
Tried using the 'jvmArgs(["-Ddataproviderthreadcount=2"])'
CucumberTestNGRunner
import io.cucumber.junit.Cucumber;
import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.runner.RunWith;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.DataProvider;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"path/to/features"},
glue = {"path.to.stepdep.package"},
plugin = {"pretty"},
tags = "#smoke",
dryRun = false,
monochrome = true
)
public class CucumberTestNGRunner extends AbstractTestNGCucumberTests {
#Override
#DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
build.gradle (snippet) :
test {
useTestNG()
//jvmArgs(["-Ddataproviderthreadcount=2"])
scanForTestClasses = false
testLogging.showStandardStreams = true
systemProperties = System.properties
}
By default cucumber report shows feature names.
Since I have several scenarios within 1 feature file,
I want to display scenario name instead of feature name.
To make the report more verbose
My Cucumber options are:
cucumberOptions = #CucumberOptions(
features = "src/test/resources/features",
monochrome = true,
glue = "stepDefinitions",
tags = {"not #disable"},
plugin = {
"pretty",
"json:build/cucumber-report/cucumber.json",
"html:build/cucumber-report/cucumber.html"},
strict = true
)
My report is showing scenario information also . I am using courgette-jvm with testNG here is my setup
package com.test;
import courgette.api.CourgetteOptions;
import courgette.api.CourgetteRunLevel;
import courgette.api.CucumberOptions;
import courgette.api.testng.TestNGCourgette;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
#Test
#CourgetteOptions(
threads = 10,
runLevel = CourgetteRunLevel.SCENARIO,
rerunFailedScenarios = true,
rerunAttempts = 1,
showTestOutput = true,
reportTitle = "Courgette-JVM Example",
reportTargetDir = "build",
environmentInfo = "browser=chrome; git_branch=master",
cucumberOptions = #CucumberOptions(
features = "src/test/resources/com/test/",
glue = "com.test.stepdefs",
//tags = {"#post or #get"},
publish = true,
plugin = {
"pretty",
"json:target/cucumber-report/cucumber.json",
"html:target/cucumber-report/cucumber.html"}
))
class AcceptanceIT extends TestNGCourgette {
}
package com.test;
I'm trying to generate and load from CSV filea and problem with CSVPrinter occured. The statement is the following:
Cannot resolve constructor 'CSVPrinter(java.io.BufferedWriter,org.apache.commons.csv.CSVFormat)"
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVRecord;
import java.io.BufferedWriter;
import java.io.*;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(file.getAbsolutePath()));
CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT
.withHeader("title", "description", "priority"))
) {
for (int i = 0; i < serializer.toDO.size(); i++){
csvPrinter.printRecord(serializer.toDO.get(i).getTitle(),
serializer.toDO.get(i).getDescription().replace("\n"," "),
serializer.toDO.get(i).getPriority(),
serializer.toDO.get(i).getLocalDate(),
"toDo");
}
Assuming you are using the apache variant, your code worked for me.
I think you need to add some of the details that you assure us you have done. My guess is that you have the wrong library in your project/classpath.
In what environment are you running your code (within the IDE or standalone from the command prompt)?
How did you incorporate the library (download JAR directly from Apache or automatically via a service - e.g. maven)?
Here is my version of the source code:
package csvwriter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVFormat;
public class Main {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
Main m = new Main();
m.go(args);
}
public void go(String [] args) {
File file = new File (args[0]);
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(file.getAbsolutePath()));
CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT
.withHeader("title", "description", "priority"))
) {
System.out.println("Done.");
// for (int i = 0; i < serializer.toDO.size(); i++){
// csvPrinter.printRecord(serializer.toDO.get(i).getTitle(),
// serializer.toDO.get(i).getDescription().replace("\n"," "),
// serializer.toDO.get(i).getPriority(),
// serializer.toDO.get(i).getLocalDate(),
// "toDo");
// }
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Here are my libraries:
I downloaded the library from the apache download center
When I run, I get the following as the output:
run:
Done.
BUILD SUCCESSFUL (total time: 0 seconds)
Repeating this exercise in IntelliJ (Java Project, incorporate apache-commons-csv-1.6) via Maven, produces the same result:
"C:\Program Files\Java\jdk1.8.0_172\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1\lib\idea_rt.jar=59482:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_172\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_172\jre\lib\rt.jar;C:\cygwin64\home\gm310509\Projects\Learning\Miscellaneous\CSVPrinter\out\production\CSVPrinter;C:\cygwin64\home\gm310509\Projects\Learning\Miscellaneous\CSVPrinter\lib\commons-csv-1.6.jar" stackoverflow.Main c:\temp\resistor.html
Done.
Process finished with exit code 0
Here is the "add library via maven" dialog:
I want to trigger the execution of some commands from a python module from Java. My script is executed without error messages, but it has no effect. The code I'm using from Java is as follows:
ProcessBuilder pb = new ProcessBuilder("python", "nerDemoTP/python/spacy_test.py");
pb.redirectOutput(Redirect.INHERIT);
Process p;
try {
p = pb.start();
p.waitFor();
} catch (IOException e1) {
... }
It works if my .py file contains only print('hello world'), then I see it in the Eclipse console. But what my python script is supposed to do:
from SpacyNER import SpacyNERExtractor
ner_extractor = SpacyNERExtractor('medium', 'sentences_nyt_200.txt')
annotated_df, entities_dict = ner_extractor.generate_extractions()
ner_extractor.store_predictions('test.csv')
print('spacy extractions done!')
And my SpacyNER module is defined as follows:
import pandas as pd
import numpy as np
import spacy
import en_core_web_md
import en_core_web_lg
import operator
import time
import re
class SpacyNERExtractor:
def __init__(self, model, text_file):
if model == 'medium':
self.spacy_model = en_core_web_md.load()
else:
self.spacy_model = en_core_web_lg.load()
self.sent_df = pd.read_csv(text_file, sep='\n', header=None, error_bad_lines = False)
self.sent_df.columns=['sentence']
def set_new_sent_df(self, df_new):
self.sent_df = df_new
def store_predictions(self, file_name):
self.df_predictions_spacy.to_csv(file_name,sep="#", index=False)
...
It has to do something with the import of the custom module, but I don't know how to deal with this problem. Also when I execute the script from the command line, i.e. python3.6 spacy_test.py, it works.
Any help is appreciated!
The moment I am adding extended cucumber dependency, the step definition is not executing, when I remove the extended cucumber dependency it works fine and execute step definitions.
Below is the Maven dependency which I am using.
<dependency>
<groupId>com.github.mkolisnyk</groupId>
<artifactId>cucumber-reports</artifactId>
<version>1.0.5</version>
</dependency>
/* This part of the code does not execute Step definitions*/
import org.junit.runner.RunWith;
import com.github.mkolisnyk.cucumber.runner.ExtendedCucumber;
import com.github.mkolisnyk.cucumber.runner.ExtendedCucumberOptions;
import cucumber.api.CucumberOptions;
#RunWith(ExtendedCucumber.class)
#ExtendedCucumberOptions(jsonReport = "target/cucumber.json",
overviewReport = true,
outputFolder = "target")
#CucumberOptions(features = {"./src/test/resources/features"}, plugin = { "html:target/cucumber-html-report",
"json:target/cucumber.json", "pretty:target/cucumber-pretty.txt",
"usage:target/cucumber-usage.json", "junit:target/cucumber-results.xml" },
glue = { "com/test/stepdefinition" },
monochrome = true)
public class RunCucumberTest {
}
/* This is working fine and executing step defnitions*/
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features = { "./src/test/resources/features" }, plugin = { "html:target/cucumber-html-report",
"json:target/cucumber.json", "pretty:target/cucumber-pretty.txt", "usage:target/cucumber-usage.json",
"junit:target/cucumber-results.xml" }, glue = {
"com/test/stepdefinition" }, monochrome = true)
public class RunCucumberTest {
}
I am not sure why this is happening, am I missing something here?
Update the all cucumber dependency to 1.2.5 then it will work