karate

Karate -Generate random alphanumeric string in the current feature file

白昼怎懂夜的黑 提交于 2019-12-24 08:38:16
问题 I am trying to generate alphanumeric string of length 5 in Karate.I am trying the below code. Feature: Test user Background: Given url AM_HOST " * def random_string = function(s) { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; for (var i = 0; i < s; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } * def sessionId = random_string(5) * print sessionId " >Scenario: Verify return user Given path 'user/<sessionId>' When method get

Tag logic for Parallel Run

社会主义新天地 提交于 2019-12-24 08:21:13
问题 The logic for tags via Parallel method is not the same as cucumber options. Would be great if there can be some documentation. mvn -Doptions="--tags @integration --tags @x --tags ~@wip" doesn't work for scenario with tags as integration Or x Based on my understanding the above represent @CucumberOptions(tags = {"@integration","@x","~@wip"} if I give mvn -Doptions="--tags @integration,@x" then it will execute scenario's with tag integration or x. public static List<String> setTags(String

how to get afterFeature and afterScenario report in either karate or cucumber reporting

别说谁变了你拦得住时间么 提交于 2019-12-24 07:39:46
问题 Is it possible to see the status of the calls in a afterFeature and afterScenario as a report inside of either cucumber-html-reporting and the karate reports (preferably both) Regards 回答1: Can you check again. I thought afterScenario is already being logged. Honestly you should use the after hooks only in rare circumstances. But feel free to raise a feature request for the afterFeature to be present in the logs as well. EDIT: Actually just realized that only if you use a *.feature file to

Karate: match with parametrized regex

徘徊边缘 提交于 2019-12-24 07:26:05
问题 I didn't find the right way to write a match with regexp cointaining a variable: * def getYear = """ function() { var SimpleDateFormat = Java.type('java.text.SimpleDateFormat'); var sdf = new SimpleDateFormat('yyyy'); var date = new java.util.Date(); return sdf.format(date); } """ * def currentYear = getYear() * def testmatch = { gencode: '#("000" + currentYear + "0000012345")' } * match testmatch == { gencode: '#regex "[0-9]{3}" + currentYear + "[0-9]{10}"' } There is a way to do this?

Karate - How to run a specific scenario only in one environment?

倖福魔咒の 提交于 2019-12-24 06:48:58
问题 Consider there are 100 scenarios and I want to run 99 scenarios in prod environment and 100 on stage environment . Is there a way to achieve this in karate ? Things I tried 1. Create a feature file with 1 scenario and another feature file with remaining 99 2. Add tag to the 1 scenario file 3. Ignore that while running But then when I use it in jenkins job I have to run one command to run on both machines so would not work 回答1: The best solution for this case is the karate.abort() API: So in

How to validate Non-JSON response body using Karate

↘锁芯ラ 提交于 2019-12-24 06:31:10
问题 I am trying to validate an error response body of non-json format. I have tried using the schema as well as a keyword using contains to match. It is not working for me. Actual Response response returned from API when multiple matches are observed in a post call: {"error":{"text":SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'NewEmp' for key 'employee_name_unique'}} My Karate Feature: Given url 'http://dummy.restapiexample.com/api/v1/create' def errResp = "error" And

Unable to use read('classpath:') when running tests with standalone karate.jar

倾然丶 夕夏残阳落幕 提交于 2019-12-24 06:06:38
问题 I am attempting to execute my tests using the karate stand-alone jar. Throughout my project, I use the read('classpath:') when locating files. However, when I attempt to execute my tests from the CLI, I receive the following error: src.test.java.Users.getUser: -unknown-:6 - javascript evaluation failed: read('classpath:commonUtils.feature'), java.io.FileNotFoundException: commonUtils.feature (The system cannot find the file specified) Command: java -jar -Dkarate.config.dir="src/test/java"

Trouble using #regex marker

安稳与你 提交于 2019-12-24 03:42:49
问题 I'm having trouble constructing a proper #regex marker. I'm trying to match on a couple of date formats in my response JSON: "created": "2017-03-23T14:16:25.854Z" "modified": "2018-06-21T05:38:37.978Z" I've attempted the following markers: '#regex [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}Z' '#regex [0-9]{4}-[0-9]{2}-[0-9]{2}.[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}.' '#regex \d+-\d+-\d+.\d+:\d+:\d+.\d+.' All 3 forms appear to be correct (according to rubular.com). I've also

Getting “required (…)+ loop did not match anything at input 'Scenario:'” error when using Background section in cucumber

醉酒当歌 提交于 2019-12-24 03:07:48
问题 I am writing a Karate DSL test to test a web service end point. I have defined my url base in karate-config.js file already. But when I try to use this in the Background section, I am getting the below error. Please help. Provided my feature file below. Error: "required (...)+ loop did not match anything at input 'Scenario:'" Feature: Test Data Management service endpoints that perform different operations with EPR Background: url dataManagementUrlBase Scenario: Validate that the contractor's

Karate - Possible to put scenario in a loop?

元气小坏坏 提交于 2019-12-24 01:17:09
问题 I want to know if it's possible to put scenario in a loop? Imagine I have a scenario that I want to test it 10 times with 10 different data in a list. It's a good Idea to put whole scenario in a loop and even set scenario name in the loop. Is it possible? 回答1: Yes, this is what Karate's data-driven call does. You need to split code into a second feature file (with only one scenario). Here is the link to the documentation: Data Driven Features. And in the karate demos look at the examples call