How to connect to documentDB using karate? [duplicate] - karate

Want to know if Karate supports Neo4j database?. If yes, would like to have an ex. feature which will be helpful.

Karate supports any Java code so that way indirectly you should be able to do anything you want.
Please look at this JDBC example which will get you started: dogs.feature. You will need to write a little bit of Java code (one time only) so if you don't have that skill, please ask someone to help.
# use jdbc to validate
* def config = { username: 'sa', password: '', url: 'jdbc:h2:mem:testdb', driverClassName: 'org.h2.Driver' }
* def DbUtils = Java.type('com.intuit.karate.demo.util.DbUtils')
* def db = new DbUtils(config)
# since the DbUtils returns a Java Map, it becomes normal JSON here !
# which means that you can use the full power of Karate's 'match' syntax
* def dogs = db.readRows('SELECT * FROM DOGS')
* match dogs contains { ID: '#(id)', NAME: 'Scooby' }

Related

Karate CLI Testing - Execute Command within context of another Command

I'm currently testing a CLI app written by a developer in my team - specifically this command:
./mycli init
After entering this command, it responds with this:
Enter endpoint:
As suggested, I need to provide the target URL, then hit enter.
I'll then be asked 2 more questions which require input.
For example, let's say I have this:
* def listener =
"""
function(line) {
if (line.contains('Enter endpoint')) {
//input the answer
}
}
"""
* def initCmd = karate.fork({ args: ['sh','mycli','init'], listener: listener })
* print initCmd.sysOut
(NB: This snippet was inspired by fork-listener.feature and this interesting thread with jbang team https://github.com/karatelabs/karate/issues/1191)
Karate is working really well for all the other tests I need to do for this CLI - is there something I can put in the IF statement for this particular use case?

How to connect to Bigquery database using Gherkins (Cucumber) / Karate? [duplicate]

Want to know if Karate supports Neo4j database?. If yes, would like to have an ex. feature which will be helpful.
Karate supports any Java code so that way indirectly you should be able to do anything you want.
Please look at this JDBC example which will get you started: dogs.feature. You will need to write a little bit of Java code (one time only) so if you don't have that skill, please ask someone to help.
# use jdbc to validate
* def config = { username: 'sa', password: '', url: 'jdbc:h2:mem:testdb', driverClassName: 'org.h2.Driver' }
* def DbUtils = Java.type('com.intuit.karate.demo.util.DbUtils')
* def db = new DbUtils(config)
# since the DbUtils returns a Java Map, it becomes normal JSON here !
# which means that you can use the full power of Karate's 'match' syntax
* def dogs = db.readRows('SELECT * FROM DOGS')
* match dogs contains { ID: '#(id)', NAME: 'Scooby' }

Intercepting multiple graphql operations in a karate UI scenario always returns the first response from mock feature

My scenario in the top feature file looks like this:
Scenario: Fetch a cat type id and create a cat
* driver.intercept({ patterns: [{ urlPattern: '*api/graphql*'}], mock:
'Mock.feature' })
When I click on the button to add a cat (//first graphql call happens. This gets cat types from the mock as expected)
And input a name
And select the cat type
And click create (//second graphql call happens here. But this returns the cat types again)
Then I see a success message
Here is the mock.feature:
Scenario: karate.match("request contains operationName: 'getCatTypes'")
def response = call read ('response.json')
Scenario: karate.match("request contains operationName: 'AddCat'")
def response = call read ('response1.json')
We use karate standalone jar and on version v1.2.0.RC1 (tried with 1.1.0 as well).
Appreciate any suggestions/directions.
Your use of karate.match() is wrong, note that it does not directly return a boolean. Read this for more: https://stackoverflow.com/a/50350442/143475
Try this change:
Scenario: karate.match("request contains operationName: 'getCatTypes'").pass
I also think there are much better ways to do the above, so read this also: https://stackoverflow.com/a/63708918/143475

Does anybody use Karate DSL as a test data management tool?

i am glad with the use of Karate DSL for API testing. But i was wondering if it is suited for test data generation. Some of our UI tests need some particular data load which I think could be generated by calling the API (Rest and SOAP) through Karate DSL.
Is Karate adequate for this or would you use other specific data generation tool?
Thanks in advance for your help.
I suggest you start looking at the new RC version (0.9.9.RC3) you can use a function to generate data: https://github.com/intuit/karate/tree/develop#json-function-data-source
* def generator = function(i){ if (i == 20) return null; return { name: 'cat' + i, age: i } }

Karate - Database testing - getting timestamp displayed as nano

I am trying to run some basic database tests using Karate and Spring JDBC ( as mentioned in DBUtils class in Demo Project).
Here is what I am doing:
Background:
# Read url/username/pwd and provide it to the class
* def config = read('env_file.json')
* def DbUtils = Java.type('DbConnection')
* def db = new DbUtils(config)
Scenario: Validate the modd_ts is present in lob table
* def createdTs = db.readRows('SELECT crtd_ts FROM tableA ')
* print createdTs
Here is what it returns:
com.intuit.karate - [print] [{"crtd_ts":{"nanos":0}},{"crtd_ts":{"nanos":0}}
Not sure why it should return timestamp as "nanos":0 , seems a bug to me . Please confirm and I will open one in github.
This is not a problem with Karate it is the implementation of DbUtils. It is up to you to write something that is right for your environment and database etc. Remember this is just part of the karate-demo as an example.