Is there a class/variable of karate available to get the details of failed scenarios like failed Scenario name, count etc when run using TestRunner - karate

I want to get the details of the failed testcase after running it using TestRunner class. I was able to get few details like error messages, failed count of scenarios and feature files using the Result class of karate.
Results results = Runner.path("classpath:errorData/pass.feature").parallel(5);
String errmsgs = results.getErrorMessages();
List<String> err = results.getErrors();
int failcount = results.getFailCount();
Now I wanted to know if there is a way to get the details like testcase status, failed scenario, failed step. Any input will be appreciated. Thanks in advance

If you can't find what you need in the Result class, please assume the answer is no. Since Karate is open source, you are welcome to figure this out yourself or contribute code for anything missing.

Related

Karate gatling name resolver not working properly for GET call [duplicate]

This question already has answers here:
Is there an option for us to customize and group the test scenarios in the statics section of the Karate Gatling Report?
(2 answers)
Closed 1 year ago.
My name resolver isn't working for some reason.
I want to group all the calls together as a single entity in results but the result is showing it as separate call.
Issue in having them separately is I am having 500,000 such request and when gatling tries to generate report its giving heap dump memory issues.
Below is my feature file
Given path '/hometown/process?requestId='+__gatling.ID+'&includeSystemComments=true'
And header karate-name = 'Request History'
When method GET
Then status 200
I've also used
val protocol = karateProtocol("/hometown/process?requestId={requestID}&includeSystemComments=true" -> Nil)
protocol.nameResolver = (req, ctx) => req.getHeader("karate-name")
Still in the results I am getting all of them as separate Rest calls.
I wanted these calls in results to be grouped as single entity.
Below is what I have the results as:
Any help would be appreciable.
Actually I think you don't even need a name resolver. Just try this:
val protocol = karateProtocol(
"/hometown/process" -> Nil
)
Or also try without anything, e.g. val protocol = karateProtocol().
Else maybe there's some other call that is "escaping". No one will be able to tell from your question, so please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

How to fetch TestNG Eclipse Test run status info from Console to use it when required?

I am trying to use the TestNG Test run status information (i.e. the Passed Tests, Failed Tests, Skipped Tests).
Ex- Want to use this
Sanity_Suite
=======================
Total tests run: 6,Passed:4, Failures: 2, Skips: 0
=========================================
I have written a method that sends test status information via sms to a recipient. Here is the ->
I have used ITestReporter, ITestResult, TestNG and other related contexts to get the correct test run status, I am using TestNG and ExtentReporter both and trying to fetch the information through anyway round possible. But I am getting mixed or incorrect results.
(BELOW IS THE SMS RECEIVED)
Is there any suggestions to get it done?
I get that You are trying to send out sms with testresults.Could You please provide what is ITestResults object. Or to make it easier try with StringBuilder class, maybe it will ease up and fix Your issue:
StringBuilder sb = new StringBuilder();
sb.append("Titlle\n");
sb.append("Passed: " + cntPass + "\n");
sb.append("Failed: " + cntFail + "\n");
sb.append("Description: " + description +"\n");
return sb.toString();
From the given code, its actually really hard to see full picture.

How to write a custom Failure message for the Failed Step in Cucumber-java in extentReports

I want to write custom failure message in my Cucumber ExtentReports.
Tool using :
Cucumber
Java
Selenium
JUnit
ExtentReports
What's happening now:
I have a cucumber scenario.
Given something
When I do something
Then this step fails
The failed step Fails with:
Assert.assertTrue("CUSTOM_FAIL_MSG", some_condition);
In the ExtentReport, I see the
What I want to achieve:
What I have researched so far:
There is a scenario.write("") function but this creates a new info log into the report(But I am looking for CustomFailure message rather than a new log entry)
scenario.stepResults has the String which is displayed in the report. However, I could not find a way to set some value in the same.
Any ideas on this?
Have you tried using the create label markup?
Here is how to do it for the FAILED test:
test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Your MSG here!", ExtentColor.RED));
and the PASSED test:
test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" Test Case PASSED", ExtentColor.GREEN));
You can easily manipulate the string part (var interpolation?) according to your need.
Does this help?
try to replace the JUnit assertion library with the testNG library...also using cucumber you can see the failed step...why do you want to change this "narrative" log?...or if you want a better report try to use a 3rd party library

Retrieve response from a "Run Test Step", using SoapUI/ Groovy?

In SoapUI, I have a host Test Case, which executes another external Test Case (with several test steps) using the "Run Test Case" test step. I need to access a response from the external TC from within my host TC, since I need to assert on some values.
I cannot transfer the properties since they are in XML. Could I get some pointers as to how I could leverage Groovy/SoapUI for this.
For Response you can use the below code.
testRunner.testCase.getTestStepByName("test step").testRequest.response.responseContent
In you external TC create another property and at the end of the TC use Transfer Property step to transfer your XML node to it. In your host TC, just read that property as you would any other.
I also had a look around to see if this can be done from Groovy. SoapUI documentation says that you need to refer to the external name of the testsuite / testcase:
def tc = testRunner.testCase.testSuite.project.testSuites["external TestSuite"].testCases["external TestCase"]
def ts = tc.testSteps["test step"]
But I could not find how to get at the Response after that.
In addition to Guest and SiKing answers, I share a solution to a problem that I've met:
If your step is not of type 'request' but 'calltestcase' you cannot use Guest answer.
I have a lot of requests contained each in a testCase and my other testCases call these testCases each time I need to launch a request.
I configured my request testCases in order to return the response as a custom property that I call "testResponse" so I can easily access it from my other testCases.
I met a problem in the following configuration :
I have a "calltestcase" step that gives me a request result.
Further in the test I have a groovy script that needs to call this step and get the response value
If I use this solution :
testRunner.runTestStepByName("test step")
followed by testRunner.testCase.getTestStepByName("test step").testRequest.response.responseContent
I'm stuck as there is no testRequest property for the class.
The solution that works is :
testRunner.runTestStepByName("test step")
def response_value = context.expand( '${test step#testResponse#$[\'value\']}' )
another solution is :
testRunner.runTestStepByName("test step")
tStep = testRunner.testCase.getTestStepByName("test step")
response = tStep.getPropertyValue("testResponse")
Then I extract the relevant value from 'response' (in my case, it is a json that I have to parse).
Of course it works only because I the request response as a custom property of my request test case.
I hope I was clear enough

Getting failure detail on failed scala/maven/specs tests

I am playing a bit with scala, using maven and scala plugin.
I can't find a way to have
mvn test
report failure details - in particular, whenever some function returns wrong reply, I am getting information about the failure, but I have no way to see WHICH wrong reply was reported.
For example, with test like:
object MyTestSpec extends Specification {
"my_function" should {
"return proper value for 3" {
val cnt = MyCode.my_function(3)
cnt must be_==(3)
}
}
}
in case my function returns something different than 3, I get only
Failed tests:
my_function should return proper value for 3
but there is no information what value was actually returned.
Is it possible to get this info somehow (apart from injecting manual println's)?
The Maven JUnit plugin only shows the failed tests in the console and not error messages. If you want to read the failure message you need to open the corresponding target/site/surefire-reports/MyTestSpecs.txt file.
You can also swap Maven for sbt-0.6.9 (Simple Build Tool) which can run specs specifications.
Eric.
cnt aka "my_function return value" must be_==(3)