Writing Cucumber feature file with passing unique data every time test runs - cucumber-jvm

I want to write a feature file that will pass unique data everytime I run my test.
Feature : - Create Facebook account
Scenario Outline: Create new account
Given I go to facebook.com
And I enter "First_Name>Last_name>DOB>Password>ConfirmPassword>Email>ConfirmEmail>"
When I click on Create account
Then I should get welcome to facebook message
Examples:
| First_Name | Last_name | DOB | Password | ConfirmPassword | Email | ConfirmEmail |
| Gary | English | 11/01/1989 | test123 | test123 | gar#mail.com | gar#mail.com |
| Barry | Smith | 01/11/1982 | test123 | test123 | bar#mail.com | bar#mail.com |
My question is:
When I run above scenario there will be 2 Facebook accounts created. When I commit my code and test are run every morning, they will fail unless I change email every-time to make them unique. As any system will check if email address provided already exists or not.
How do I tackle this issue where I don't have to change my Create account feature file data every time.
I hope someone of us should have come across such issue.
Note: I could not open and close <> as text was not visible between those brackets, hence I have kept just 1 bracket

Then don't put it in the feature file. Build a randomizer into the steps method. You should also change the feature file to reflect this.
And I enter "<First_Name>, <Last_name>, <DOB>, <Password>, <ConfirmPassword>, <Email>, <ConfirmEmail>"
And uses a random email
Or if you'd rather not build a separate condition, then use a keyword to signal that the value should be randomized (my preferred method):
|Barry|Smith|01/11/1982|test123|test123|[random]|[random]|
So when passed to the registration method, if the value doesn't validate as a legitimate email address (you are doing validation, right?), check for the [random] keyword. If it is there, then build a random valid email.

Related

Forcing a null value as a parameter does not get included in the call [duplicate]

This question already has an answer here:
The json key is not being omitted where the cells are empty in examples of Scenario Outline .What change needs to be done?
(1 answer)
Closed 1 year ago.
I read in the Karate documentation that if one uses "null", it will result in the key being omitted from the call. However, if one still wants to force a null, they could wrap it in parentheses like: "(null)".
It does go through with the key. However, on the actual call, the key is still omitted from the parameters. How can I force it there as well? Is it LITERALLY the same thing as an empty string?
I.e:
| Environment| Application| Version | status |
| Environment| Application| (null) | 401 |
call read....
Results:
{
"Environment": "Environment",
"Application": "Application",
"Version": "null",
"status": 401
}
But the URL looks like:
GET https://?Environment=Environment&Application=Application
Please advise.
EDIT below for a better example:
In my "primary" file, I have the following:
* table requestTable
| q | um | ie | status |
| (null) | 1 | utf | 400 |
Where all three params (q, um, ie) are required parameters.
My "secondary" runner file, looks like the following:
* def requiredParams = { q: '#(q)', um: '#(um)', ie: '#(ie)'}
* def mainUrl = 'https://www.google.com'
* def apiPath = '/search'
Given url mainUrl
And path apiPath
And params requiredParams
When method GET
Then status 400
I am expecting a 400 since a required param is required. It doesn't get sent as "null", even if I use (null), it removes that field altogether in the actual call. This example obviously won't work in real life since I am using example google stuff. I apologize about that. If you still need a real life example, please show me how I can do it.
I assume that you are talking about Examples: but your question is incomplete.
Try this: https://github.com/karatelabs/karate#scenario-outline-enhancements
Examples:
| Version! |
| '' |

Karate- Good way to send custom headers with each request

I have a scenario where I am doing a GET call and on my table I have parameters defined. Now for the headers, I want to purposefully send incorrect values to make sure the test fails as expected. Not really sure how to do it though.
I have the following setup:
* table input
| machine | version | osSystem | status |
| machineName| version | windows | 401 |
My secondary file that the above calls on, looks like this:
Given url env
And path path
And header Content-Type = 'application/xml; charset=UTF-16'
And header Accept = '*/xml; charset=UTF-16'
And header key = key
When method GET
In above, I want to send bogus values for "key" header. Total of six bogus values (random alpha string, random number string, random alphanumerical value, random guid, etc). I have obviously tried entering the values as a json under "and header key = {}" but how do I make each request run EACH header per request, instead of running them all in one request?
Thank you in advance!
Try this example and observe how it works, it will answer all your questions:
Scenario Outline:
* url 'https://httpbin.org/anything'
* header foo = header
* method get
Examples:
| header |
| one |
| two |
And for an alternate way to "loop" refer to this answer: https://stackoverflow.com/a/69422451/143475

How to pass variable into the title of a scenario/scenario title in Karate framework

While using data-driven feature in Karate framework, I see the generated report just show the title as configured in Scenario Outline NOT attached the value using in Example table. It causes the Tester confuse which data is using, and take time to expand each scenarios to know which data is using; so I want the report can pass variable into the title - Scenario/Scenario Outline. Please take a look at the example below.
E.g.
Feature: Login Feature
Background:
* configure headers = { 'Webapp-Version': '1.0.0'}
Scenario Outline: As a <description> user, I want to get the corresponding response_code <status_code>
Given def path = 'classpath:features/Authentication/authentication.feature'
And def signIn = call read(path) {username: '<username>', password: '1234567890'}
Then match signIn.status == <status_code>
Examples:
|username | status_code| description |
|test#gmail.com | 200 | valid user |
|null | 400 | invalid user|
My expected result, the generated report should fill the value on table for field "status code" and "description" fields.
-> As a valid user user, I want to get the corresponding response_code 200.
Please share your ideas and comments on it.
Thanks,
Learn.
Not supported. Just use the print syntax and you will see it in the report.
EDIT: okay this will be possible in the next version: https://github.com/intuit/karate/issues/553

How to use data in a file with postman?

I have a list of IDs and Values in a file and would like to use postman to connect to an API and update the records found in this file.
I tried with the Runner but am stuck in writing the syntax.
The answer is pretty simple and very well explained on this page
You can start with the a basic "put/post" - try to modify one single data set with static values to determine how the final query needs to be build. In my case the API accepted only RAW JSON formated data payloads.
As soon as you have your static postman query running - you can start automating it by determining which parts should be replaced. This data should be found in a data file (JSON or CSV). The schema is important for postman to understand the data. As reference I state the example as if I would like to replace an ID and a Value. My data document has one more column which is not a problem.
+--------+--------+--------+
| id | email | value |
+--------+--------+--------+
| data 1 | data 1 | data 1 |
+--------+--------+--------+
| data 2 | data 2 | data 2 |
+--------+--------+--------+
| data 3 | data 3 | data 3 |
+--------+--------+--------+
Column two (aka email) will be ignored and not be used. Notice how "id" and "value" are written in the header.
I would like to replace the ID which needs to be attached to the API endpoint and like to update a value which is within the dataset of this ID. Replacing the static parts with variables like {{variable}} allows Postman to understand that it needs to fill dynamic data here.
Notice that the variable attached to the URL says that it is not defined in the environment - if you did not set it up in the environment, this is correct and will work with data files.
I used simple tests to confirm if the data of the file made it into my query:
tests["URL has ID"] = responseURL.has(data.id);
tests["Body contains SFID"] = responseBody.has(data.value);
If you reach this point - all there is left to do is to go to the runner page, select the query to run, add the data file (you should preview if everything looks okay) and run it.

Jawbone Create Meal/MealType

I'm trying to log Meal Entry using Jawbone API. In API documentation described sub_type parameter which is responsible for Meal Type (breakfast/lunch/dinner). However it looks like this parameter doesn't control anything and everything is controlled by time_created/tz parameters. Could anyone help me to understand exact logic responsible for where Logged Meal goes - Breakfast/Lunch/Dinner/Snack.
update 20/09/2016
I'd like to be able to log Meal(as Breakfast/Dinner/Lunch or Snack) and see result in user feed as Breakfast/Dinner/Lunch or Snack (https://jawbone.com/up/food/meals). For now I'm interested only in these 4 Meal Types because of compatibility with our app.
I've found that it can be achieved by specifying time_created = (${begin_of_the_day} + mealTypeAdjustment), where mealTypeAdjustment=
-7h for Breakfast
-13h for Lunch
-19h for Dinner
these numbers are just my assumption which work so far. But there is no Jawbone documentation about this logic so my questions:
1) how can I controll using time_created, where logged Meal appears in user feed(Breakfast/Dinner/Lunch or Snack)?
2) I still didn't get how to log Snack. Few times I was able to do it by randomizing input parameters but unfortunately I can't reproduce it now.
The sub_type is just a piece of metadata about the meal in case you would like to classify a meal as breakfast/lunch/dinner.
Where a meal entry appears in a user's feed is dictated by time_created. In fact, there is no direct connection between time_created and sub_type.
Here are all the meal sub_type values:
sub_type | value
-------------|-------
Breakfast | 1
Lunch | 2
Dinner | 3
Pre-Workout | 4
Post-Workout | 5
Snack | 6