i am using java with selenium , maven, testng for my project.
for some functions , i have passed parameters through testng parameters annotations.
while build and executing the project through jenkins,
parameter passed methods are not executed through jenkins.
other methods are executed fine.
Please provide solutions. Awaiting the response
sample code
#Test(priority=1)
#Parameters({"drivername","driverpath","outputpath","URL"})
public void opendriver(#Optional("drivername") String drivername,#Optional("driverpath") String driverpath,#Optional("outputpath") String outputpath,#Optional("URL") String URL)
in the above code i have passed some parameters through testng. while executing the code
through maven it is working fine. but making build in jenkins and execute the script
it is not working. Please suggest and advise
Related
How can I add Reporter.log() on Jenkins log?
I write my test in java and used TestNG.
I try import:
import org.testng.Reporter;
next write method:
Reporter.log("Click on button next");
click(btnNext);
return this;
}
and write test:
public void shouldPageChangeAfterClick(){
mainPage
.launch()
.clickOnBtnNextPage()
.assertThatPageIsCorrect();
}
Next I run test on Jenkins from pom.xml, test is failed, but I don't see Reporter.log() in log on Jenkins.
What should I do to display Reporte.log() on Jenkins?
Reporter.log() method is to log the passed string to the HTML report. It will not print in any console or log file. You have to use different logger api to get the same in Jenkins console. Log4j will be helpful in this case.
I am running protractor test cases through Jenkins, and using SauceLabs as execution environment. I am using Protractor-Cucumber-Framework. I want to pass build number from Jenkins so that I can pass same to SauceLabs to organize my test execution results.
I tried params as mentioned in this post
https://moduscreate.com/blog/protractor_parameters_adding_flexibility_automation_tests/
in Config.js
params: {
buildNumber:'xyz'
}
for running protractor :
protractor config/config.js --parameters.buildNumber= 1.1 --disableChecks"
using :
browser.params.buildNumber
This gives buildnumber =xyz and not 1.1
Could you please help me here
Update:
Sorry forgot to mention that I am using browser.params.buildNumber in after hook of cucumberjs.
you should use pattern: --params.xxx in cmd line, rather than --parameters.xxx.
In your case, should be: protractor config/config.js --params.buildNumber=1.1 --disableChecks
Note: Don't insert blank space around the =, like --params.name = value, or --params.name= value.
If the parameter value has blank space, you should use double quote to wrapper it, like --params.name="I like to xxx"
Is it possible to define/specify a runner when starting tests from cucumber's command line(cucumber.api.cli.Main)?
My reason for this is so i can generate xml reports in Jenkins and push the results to ALM Octane.
I kind of inherited this project and its using gradle to do a javaexect and call cucumber.api.cli.Main
I know its possible to do this with #RunWith(OctaneCucumber.class) when using JUnit runner + maven (or only JUnit runner), otherwise that tag is ignored. I have the custom runner with that tag but when i run from cucumber.api.cli.Main i can't find a way to run with it and my tag just gets ignored.
What #Grasshopper suggested didn't exactly work but it made me look in the right direction.
Instead of adding the code as a plugin, i managed to "hack/load" the octane reporter by creating a copy of the cucumber.api.cli.Main, using it as a base to run the cli commands and change a bit the run method and add the plugin at runtime. Needed to do this because the plugin required quite a few parameters in its constructor. Might not be the perfect solution, but it allowed me to keep the gradle build process i initially had.
public static byte run(String[] argv, ClassLoader classLoader) throws IOException {
RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList(argv)));
ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
//====================Added the following lines ================
//Hardcoded runner(?) class. If its changed, it will need to be changed here also
OutputFile outputFile = new OutputFile(Main.class);
runtimeOptions.addPlugin(new HPEAlmOctaneGherkinFormatter(resourceLoader, runtimeOptions.getFeaturePaths(), outputFile));
//==============================================================
runtime.run();
return runtime.exitStatus();
}
I have two runners in my automation project as follows:
Main runner - Executes all the #ui-test tagged test cases and if a scenario is failed target/rerun.txt will be populated with the scenario location (e.g. features/Dummy.feature:22):
#RunWith(Cucumber.class)
#CucumberOptions(
features = "classpath:features",
plugin = {"pretty", "html:target/cucumber-html-report", "json:target/cucumber.json", "rerun:target/rerun.txt"},
tags = {"#ui-test", "~#ignore"}
)
public class RunCukesTest {
}
Secondary runner - Re-executes the scenarios from target/rerun.txt:
#RunWith(Cucumber.class)
#CucumberOptions(
features = "#target/rerun.txt",
plugin = {"pretty", "html:target/cucumber-html-report-rerun", "json:target/cucumber_rerun.json"}
)
public class ReRunFailedCukesTest {
}
When the execution is performed two result json files are created:
cucumber.json
cucumber_rerun.json
Jenkins will collect the results via Cucumber-JVM Reports plugin and will create a combined report.
The problem is, even if all the target/rerun.txt tests are passed in the second run, the report status will remain failed because of the cucumber.json.
Is there a way (to set up Cucumber-JVM Reports plugin or modify the upper presented runners) to overwrite cucumber.json with the results from cucumber_rerun.json and to publish only the modified cucumber.json?
Another sub-keywords: maven, java, cucumber-java8, cucumber-junit, junit
I had problem similar to yours, though, I've used single runner, handled re-runs from testNG(re-runs was one of the reasons I've switched from JUnit to TestNG) directly and as a results I had increased amount of tests in my json report.
My solution was to clean json files afterwards, despite the fact that Jenkins knows about failed tests it won't mark build as failed or as unstable.
In your particular case you may try to somehow match tests from rerun.json and exclude them from regular json report.
For parsing jsons I may recommend using Jackson FasterXML
I use Jenkins cucumber reporting latest release with below config in Jenkins.
Image Of Config In Jenkins
1st Runner
#RunWith(Cucumber.class)
#CucumberOptions(
features="FolderFeature",
glue={"Gluefolder"},
plugin={"html:target/cucumberpf-html-report",
"json:target/cucumberpf.json"}
)
public class RunPF {
}
2nd Runner
#RunWith(Cucumber.class)
#CucumberOptions(
features="Blah/Test.feature",
glue={"mygluefolder"},
plugin={"html:target/cucumber-html-report",
"json:target/cucumber.json"}
)
public class RunRA {
}
I had failed in both .json files and when it passed both were merged and updated correctly in one cucumber report.
Here is the error:
[CucumberReport] Preparing Cucumber Reports
[CucumberReport] JSON report directory is "C:\Users\ajacobs\workspace\com.mytest.framework\target\"
[CucumberReport] Copied 2 json files from workspace "C:\Users\admin\workspace\yourtest\target" to
reports directory "C:\Users\admin\.jenkins\jobs\Regression\builds\21\cucumber-html-reports\.cache"
[CucumberReport] Processing 2 json files:
[CucumberReport] C:\Users\admin\yourtest\builds\21\cucumber-html-reports\.cache\cucumber.json
[CucumberReport] C:\Users\admin\yourtest\builds\21\cucumber-html-reports\.cache\cucumberpf.json
Finished: SUCCESS
I am trying to execute a Jenkins build from my Java program using the Resty framework (using Resty isn't a requirement, just seemed like the easiest way). It works fine for jobs without parameters, including authentication, however I am trying to execute a build with a parameter but I am getting the (non-descript) Error 500 returned from Jenkins server.
URI jenkinsURI = new URI("https://"+jenkinsServer+"/job/bowling%20Q%20build/build?token="+jenkinsToken);
String b = URLEncoder.encode("json={\"parameter\": [{\"name\": \"git_tag\", \"value\": \"v1\"}],\"\":\"\"", "UTF-8");
System.out.println("My Results: "+r.text(jenkinsURI, Resty.content(b)));
Any idea how to do this? I have followed these instructions for sending the JSON and it works fine from curl, but does not from Java Resty.
The problem was that I didn't/can't use the URLEncoder. Once I changed the Resty.content to
System.out.println("My Results: "+r.text(jenkinsURI, Resty.form(Resty.data("json", "{\"parameter\": [{\"name\": \"git_tag\", \"value\": \"1.0.4\"}],\"\":\"\"}"))));
it started working fine.