Karate Parallel fail since 1.3.0 - karate

Good morning,
I just mounted the version of Karate and I have an unexpected behavior on the execution of tests in parallel.
I have a single feature file that I execute in parallel. In 10 simple API scenarios.
If I add a sleep of 10 seconds in two scenarios then the execution will take 27 seconds.
In 1.1.0 or 1.2.0 it takes 17 seconds. As if the parallelization had no place.
I use the sleep method proposed on the documentation. My sleep method is called in CallSingle in my background file ( like in the Example below )
Result :
Karate version: 1.1.0
======================================================
elapsed: 16,70 | threads: 25 | thread time: 87,05
features: 1 | skipped: 0 | efficiency: 0,21
scenarios: 34 | passed: 34 | failed: 0
======================================================
Karate version: 1.3.0
======================================================
elapsed: 25,51 | threads: 25 | thread time: 126,30
features: 1 | skipped: 0 | efficiency: 0,20
scenarios: 34 | passed: 34 | failed: 0
======================================================
My runner :
Results results = Runner.path(
"classpath:Tenant/TenantAPI/gestionTenantAPI.feature"
).tags("\~#ignore").reportDir("target/surefire-reports-myrunner).outputCucumberJson(true).outputJunitXml(true)
.parallel(25);
karateReportCucumber.generateReport(results.getReportDir(), runner);
assertEquals(0, results.getFailCount(), results.getErrorMessages());
Exemple of Feature :
Feature : Test Sleep
Background:
* def SleepGenerator = karate.call('classpath:Common/Utils/generators.feature#sleepGenerator').SleepGenerator
Scenario: Number 01
* def pause = SleepGenerator(10000)
Given url url_api + '/v1/myapp/code/karate'
And header Content-Type = 'application/json'
And header Authorization = "Bearer " + token_bearer
When method GET
Then status 200
Scenario:Number 01
* def pause = SleepGenerator(10000)
Given url url_api + '/v1/myapp/code/MAGICSTRING'
And header Content-Type = 'application/json'
And header Authorization = "Bearer " + token_bearer
When method GET
Then status 200

Can you please read this thread: https://github.com/karatelabs/karate/issues/2222#issuecomment-1420534265
In the meantime, if you can try build locally that will greatly help.

Thanks for the quick response.
I just got the Karate sources, I built a 1.4.0-Snapshot from the development branch and I have exactly the same result.
Karate version: 1.4.0-SNAPSHOT
======================================================
elapsed: 24,24 | threads: 25 | thread time: 165,23
features: 1 | skipped: 0 | efficiency: 0,27
scenarios: 34 | passed: 34 | failed: 0
======================================================
You can contact me later on my Stack account if you want a beta tester. Am using karate since 4 Year.

Related

Print logs only when the tests failed in karate

With Karate API tests, I would like to print the request and reponse only when the test fails.
How can I achieve that in karate.
Consider the below scenarios
Feature: Validate Addition.
Background:
Scenario Outline: Verify Addition
* def sum = <num1> + <num2>
And match sum == 10
* print "number1:" + num1 + " number2:" + num2
Examples:
| num1 | num2 |
| 5 | 5 |
| 7 | 3 |
| 3 | 8 |
| 1 | 5 |
| 1 | 9 |
In the above scenario I get the print for every iteration. Is it possible to print the numbers only when the match fails.
I think it would be more efficient if we can have such option.
Short answer is that it is not possible. You can try contributing code to make this happen. Or maybe you should use REST-assured or Selenium - those sound more like a good fit for you, based on all your questions.
One thought is that you can switch off all logging by making the levels ERROR etc. and then write some custom hook. Refer to hooks here: https://stackoverflow.com/a/60944060/143475
Also refer to how to create custom reports here: https://stackoverflow.com/a/66773839/143475

Karate - How to pass a variable to another feature file using table [duplicate]

This question already has an answer here:
Karate - How to call multiple external features from a single main feature
(1 answer)
Closed 1 year ago.
After doing some reading, I have figured out how to send variables to another feature file. However, how do I pass a variable when I am using a table?
The setup is:
* table valueTable
| number | mode | time | status |
| 12345 | mobile | 100 | 200 |
* call read('feature1.feature#scenario1') valueTable
So if I use the following line to pass variable through, I get failures:
* call read('feature1.feature#scenario1') {table1: '#(valueTable)', payload1: '#(payload)'}
Of course in above, 'payload' is the variable I want to pass to the second feature file. I don't have any issues passing variables if there is no table involved.
Please advise.
Works for me. Put this in a new feature:
* table valueTable
| number | mode | time | status |
| 12345 | 'mobile' | 100 | 200 |
* call read('called.feature') { table1: '#(valueTable)' }
And in called.feature have this:
#ignore
Feature:
Scenario:
* print __arg
And it works fine. So if you are still stuck, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

How do i parameterize parameters i am passing in my API request & execute through Karate?

I am testing API's for my application & each API has multiple parameters to be passed, ex. below:
https://abc.xyz.com/***.svc/restful/GetSummary?FromDate=2019/06/28&ToDate=2019/06/28&CompAreaId=15&RegId=4
Each parameter in the request has multiple values (within a defined set of values), so if I want to parameterize each parameter with all the values it could possibly have, how can I create a scenario that will help me achieve this?
I would appreciate any hints/views.
I have been passing parameters as shown in the code below, but unable to pull off the scenario above mentioned, it would be time-consuming & repetitive to pass parameters in a separate scenario each time.
Scenario: Verify if GetContext API returns data with params
Given path 'GetContext'
And param FromDate = '2019/06/27'
And param ToDate = '2019/06/27'
And param CompAreaId = 20
And param RegId = 4
When method get
Then status 200
* def res = response
* print 'response:', response
You can use “Scenario Outline” to achieve that. The following modified code below will run for the 3 rows in the example. (related link: https://github.com/intuit/karate#the-cucumber-way)
Scenario Outline:
Given path 'GetContext'
And param FromDate = '<FromDate>'
And param ToDate = '<ToDate>'
And param CompAreaId = <CompAreaId>
And param RegId = <RegId>
When method get
Then status 200
* def res = response
* print 'response:', response
Examples:
| FromDate | ToDate | CompAreaId | RegId |
| 2019/06/27 | 2019/06/27 | 20 | 4 |
| 2019/06/28 | 2019/06/28 | 21 | 5 |
| 2019/06/29 | 2019/06/29 | 22 | 6 |
Instead of a static count, if you have a dynamic number of rows, you can store the parameter values in a json or CSV and reference it in the example. (related link: https://github.com/intuit/karate#dynamic-scenario-outline)

Using table inside of dynamic step definitions

I have feature file with step like this
When user login with credentials
|username|password|
|blahblah|blahblah|
But then I want to use this step inside my dynamic step definitions. Is it possible? I was trying to do something like this
step 'user login with credentials
|username|password|
|blahblah|blahblah|'
or creating and passing a hash. Couldn't make it work so far.
https://github.com/cucumber/cucumber/wiki/Calling-Steps-from-Step-Definitions#calling-steps-with-multiline-step-arguments
Calling steps with multiline step arguments
Sometimes you want to call a step that has been designed to take Multiline Step Arguments, for example:
# ruby
Given /^an expense report for (.*) with the following posts:$/ do |date, posts_table|
# The posts_table variable is an instance of Cucumber::Ast::Table
end
This can easily be called from a plain text step like this:
# feature
Given an expense report for Jan 2009 with the following posts:
| account | description | amount |
| INT-100 | Taxi | 114 |
| CUC-101 | Peeler | 22 |
But what if you want to call this from a step definition? There are a couple of ways to do this:
# ruby
Given /A simple expense report/ do
step "an expense report for Jan 2009 with the following posts:", table(%{
| account | description | amount |
| INT-100 | Taxi | 114 |
| CUC-101 | Peeler | 22 |
})
end
Or, if you prefer a more programmatic approach:
# ruby
Given /A simple expense report/ do
step "an expense report for Jan 2009 with the following posts:", table([
%w{ account description amount },
%w{ INT-100 Taxi 114 },
%w{ CUC-101 Peeler 22 }
])
end

how to increment field value each time selenium test is run?

is there any simple way to increment for example field value by +1 every time Selenium test is run through Selenium IDE?
Command: Type
Target: some kind of id
Value: number+1
EDIT 1 :thanks for a reply krosenvold. i got your idea and this is a simplified version of what i got so far:
...
store | 10 | x
storeEval | storedVars['x'] = ${x}+1 |
...
variable's x value does realy get incremented, but how would you save that value between distinct test runs? is it even possible?
should i get $x value every time the test is run and at the end of it assign $x value to some dummy element on testing page, so i could retrieve that previously incremented value the next time test is run?
Correct Answer
store | 10 | i
store | javascript{storedVars.i++;} | i
echo | ${i}
This is solution for your problem
store | 10 | i
store | javascript{storedVars.i++;}
echo | ${i}
store | 0 | iterator
echo | ${iterator} |
execute script | return parseInt(${iterator}) + 1 | iterator
echo | ${iterator} |
As result will be:
0
1
You can use eval;
eval($('elementId').value = $('elementId').value +1);
The exact syntax I'm showing implies prototype on the client;
document.getElementById('elementId').value should also do the trick in a standard DOM environment.
This worked for me
storeEval | storedVars['nextRow'] = ${nextRow}+1 |