how to parameterize the item block in code :-
Scenario Outline: parameterization
* text query =
"""
{
"add":"Product",
"item":[
{"pn":"12345","qn":1,"m":"mk"}
]
}
"""
Given url baseURL
And request { query: '#(query)' }
And header Accept = 'application/json'
When method post
Then status 200
Examples:
| item_num |
| 12345 |
| 67890 |
Scenario Outline:
* def json = { add: 'Product', item: [{ pn: '<itemNum>', qn: 1, m: 'mk'}]}
* print json
Examples:
| itemNum |
| 12345 |
| 67890 |
Related
I have a rather complex query and I'm not sure if it's doable in psql.
I have 3 tables, checklists, checklist_items and a junction table that maintains a many-to-many relationship between checklist & checklist_items.
checklists
| id | description |
| -------- | ---------------- |
| 01 | 'Upon Dispatch' |
| 02 | 'Upon Return' |
checklist_items
| id | type |elements |
| -- | ----------| -------------------------|
| 01 | 'combobox'| [] |
| 02 | 'text' | [] |
| 03 | 'select' | ['option 1', 'option 2'] |
junction_table
| checklist_id | checklist_item_id |
| ------------ | ----------------- |
| 01 | 01 |
| 01 | 02 |
| 01 | 03 |
| 02 | 02 |
I was trying to write a query to get all checklists along with all checklist_items associated with each individual checklist.
Something along these lines
[
{
id: '01',
description: 'Upon Dispatch',
items: [
{
id: '01',
type: 'combobox',
elements: []
},
{
id: '02',
type: 'text',
elements: []
},
{
id: '01',
type: 'select',
elements: ['option 1', 'option 2']
}
]
},
{
id: '02',
description: 'Upon Return',
items: [
{
id: '02',
type: 'text',
elements: []
}
]
}
]
Current solution is me getting all checklists, iterating over them to find their checklist_items in junction_table, populate checklist_items with a join and add items field to each checklist.
const checklists = await knex.select('*').from('checklists');
for (let checklist of checklists) {
let data = await knex('junction_table')
.join(
'checklist_items',
'junction_table.checklist_item_id',
'=',
'checklist_items.id'
)
.select('id', 'type', 'elements')
.where({ checklist_id: checklist.id });
checklist.items = data;
}
Is there a better way to achieve this ? preferably without iterating over the checklists array in code.
I am new to karate and read through most of the examples, but can't quite crack this. Your help is much appreciated! Assuming I have an array and I need to call a service and pass each value of this as a param, how do I do that please?
Thanks in advance.
How about this:
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| value |
| hello |
| world |
And in Karate 0.9.0 onwards you can do this:
Background:
* def data = [{ value: 'hello' }, { value: 'world' }]
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| data |
EDIT: and if you need to transform an existing primitive array:
Background:
* def array = ['hello', 'world']
* def data = karate.map(array, function(x){ return { value: x } })
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| data |
I am new to karate and read through most of the examples, but can't quite crack this. Your help is much appreciated! Assuming I have an array and I need to call a service and pass each value of this as a param, how do I do that please?
Thanks in advance.
How about this:
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| value |
| hello |
| world |
And in Karate 0.9.0 onwards you can do this:
Background:
* def data = [{ value: 'hello' }, { value: 'world' }]
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| data |
EDIT: and if you need to transform an existing primitive array:
Background:
* def array = ['hello', 'world']
* def data = karate.map(array, function(x){ return { value: x } })
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| data |
I find using * match each response.xyz super powerful for merging object structure testing with content testing. Is there a way to use it with Examples tables and <placeholder>?
I've got something like this, that I want to use an Examples table on:
* match each response.Services ==
"""
{
"ServiceId" : #present,
"Name" : <Name>,
"Description" : #present,
"InActive" : <Inactive>,
}
"""
Examples:
| ClientId | Name | Status | ErrorCode | Inactive |
| 400152 | "Foxtrot" | 200 | 0 | false |
| 400152 | "Waltz" | 200 | 0 | false |
I get
"Services": [
{
"ServiceId": 3,
"Name": "Waltz",
"Description": "Waltzing like Matilda",
"InActive": false,
},
{
"ServiceId": 4,
"Name": "Foxtrot",
"Description": "",
"InActive": false,
},
back as a response.
Obviously, when I'm using multiple lines in Examples:, it results in several tests.
What I'm looking for is to test each object in the array against predefined values, but without knowing what order they'll show up in. And use the ordered approach like tables produce.
Instead of each, try this:
* match response.Services contains
"""
{
"ServiceId" : #present,
"Name" : <Name>,
"Description" : #present,
"InActive" : <Inactive>,
}
"""
EDIT: okay, an alternate option. By the way there are at least 5 different ways I can think of :P
Scenario:
* table data
| ClientId | Name | Status | ErrorCode | Inactive |
| 400152 | "Foxtrot" | 200 | 0 | false |
| 400152 | "Waltz" | 200 | 0 | false |
* def expected = karate.map(data, function(x){ return { ServiceId: '#present', Name: x.Name, Description: '#present', InActive: x.Inactive} })
* match response.Services contains expected
EDIT2: if you can control the whole table:
Scenario:
* table expected
| Name | InActive | ServiceId | Description |
| "Foxtrot" | false | '#present' | '#present' |
| "Waltz" | false | '#present' | '#present' |
* match response.Services contains expected
I found a lot of introductions to parameterized tests/ test cases for test cafe, but the syntax is completely different to the one I am using. I guess they're for the discontinued paid version. How can I do the same thing with the free version? I'm not looking for user roles specifically, I want to write tests with parameters in general.
Do you want to do something like this?
This works for me perfectly
import { Selector } from 'testcafe';
fixture `Your fixture`
.page `http://some_url.com`
const testCases = [
{ name: 'name1', param: 'param1' },
{ name: 'name2', param: 'param2' }
...
];
for (const c of testCases) {
test(`Test ${c.name}`, async t => {
yourTestMethod(c.param)
});
}
An additional twist can be added by using a combination of JS and YAML
import YamlTableReader, {fixtureData, TestData} from "./YamlTableReader";
var table = fixtureData `
| ID | N1 | N2 | Equals |
| Should Be equal | 1 | 1 | true |
| Shouldn't be equal | 1 | 2 | false |
| Shouldn't be equal | 1 | "hans" | false |
| Should be equal | hans | "hans" | true |
`;
table.forEach(row => {
test('Should be equal', t => {
row["Equals"] == (row["N1"] === row["N2"]));
}
});
Simple Sources for this can be found here https://github.com/deicongmbh/jasmine-param-tests