Scenario Outline to use different data set by passing in REST API JSON body object - cucumber

We have REST APIs with JSON BODY arrays/objects. To control the data to go in the JSON file at Runtime, using testdata.properties file where defining the data and calling that as below. We are using cucumber Serenity.
Testdata.properties file:
Value = 123
StepDefinition file:
#Given("^Set the \"([^\"]*)\" with \"([^\"]*)\"$")
public void set_data_parameterization (String fieldName, String Value) {
if (fieldName.contains("Test")) {
jsonObjectNew.getAsJsonObject("TestInfo").add("Value",
gson.toJsonTree(Value));
}
System.err.println("Test value fetched from the Scenario outline");
}
JSON File:
{
"TestInfo": {
"Test123": 3,
"Value": 50 // this value to be replaced
}
}
.feature file:
Scenario Outline::
1. Testing data parameterize
Given Set the URL for "Test" as "base"
And Set the "Test" with "Value"
Examples:
|Value|
|700|
|710|
If calling the variable data from .properties file works fine, however if want to have different sets of data to be executed for the same scenario. How can it be achieved. Tried with Examples in feature file, but when run the file as cucumbertest>getting the actual payload value which is 50. It is not replacing with 700/710.
Please guide.

Able to get values as expected now, the issue was I was trying as "String" (ex: "Values"). When tried as in .feature file and rest of the code is similar.
Able to get values iterated of given Examples.

Related

Puppet data array

I got a module that creating some directories depending of server:
class linux_sftp::sftp_mount ($sftp_mount_ip, $sftp_mount_username, $sftp_mount_password, $sftp_mount_point) {
file { "/mnt/${sftp_mount_point}":
ensure => directory,
subscribe => Exec['sftp_remount'],
}
in data.yml
sftp_mount_point: "stcontent1"
I want to add to data more folders like: stcontent2, stcontent3. Is it a way to add this and loop thru data?
sftp_mount_point:
- "stcontent1"
- "stcontent2" ...
Yes you can use lambda method (can also be invoked as functions if desired) iteration to accomplish this task. The most common for your use case is each. It can be easily invoked on type Array[String] like you have in your question.
$sftp_mount_point.each |String $mount| {
file { "/mnt/${mount}":
ensure => directory,
}
}
Note that the file type does not have a subscribable property, so subscribe is not a valid attribute and I therefore removed it above.

how to treat special characters in variable names

I have a json which has the a particular format, I wanted to extract data from it, but it contains ':' in its key value which is giving error while printing
metadata:
{
'A:B':'string'
}
I have tried to take it in another varibale stills it gives error:
text='A'+':'+'B';
console.log(metadata.text);
//console.log(metadata.A:B);
You can simply use jsonVariableName["ObjectName"] instead of sonVariableName.ObjectName
var metadata = {
'A:B':'string'
};
console.log(metadata["A:B"]);
Also I found you mention code as:
metadata:{...}
Which I think will be:
metadata = {...}

GraphQL string concatenation or interpolation

I'm using GitHub API v 4 to learn GraphQL. Here is a broken query to fetch blobs (files) and their text content for a given branch:
query GetTree($branch: String = "master") {
repository(name: "blog-content", owner: "lzrski") {
branch: ref(qualifiedName: "refs/heads/${branch}") {
name
target {
... on Commit {
tree {
entries {
name
object {
... on Blob {
isBinary
text
}
}
}
}
}
}
}
}
}
As you see on line 3 there is my attempt of guessing interpolation syntax, but it does not work - I leave it as an illustration of my intention.
I could provide a fully qualified name for a revision, but that doesn't seem particularly elegant. Is there any GraphQL native way of manipulating strings?
I don't think there's anything in the GraphQL specification that specifically outlines any methods for manipulating string values within a query.
However, when utilizing GraphQL queries within an actual application, you will provide most of the arguments for your query by utilizing variables that are passed alongside your query inside your request. So rather than being done inside your query, most of your string manipulation will be done within your client code when composing the JSON that will represent your variables.

Using 'eachWithindex' groovy instead of For loops to read in json data

I'm having trouble with converting an existing FOR loop to use the 'eachWithIndex' groovy function.
I'm not sure how to go about doing this successfully, examples I've seen are quite straightforward on tutorials but I'm not sure how to make them work with groovy json files.
The current solution uses a For loop which reads in data from 3 different groovy files
Add_Page1_data = data.get("json_Page1")
Add_Page2_data = data.get("json_Page2")
Add_Page3_data = data.get("json_Page3")
for (int i=0; i< Add_Page1_data.size(); i++) {
execute(w, Add_Page1_data[i],
Add_Page2_data[i],
Add_Page3_data[i])
}
I then use the following code to populate data inside windows by accessing the page objects of the file before :
def execute(w, data1) {
def page1 = new PO_Add_Page1(wrapper: w)
page1.typeInSomeText(data1.sometext)
}
PageObject file looks like this:
class PO_Add_Page1 {
def typeInSomeText(val) {
wrapper.findWithLabel("Some Text . .").rightEditable().type(val)
}
Json file used contains multiple records like this:
{
"json_Page1": [
{
"sometext": "text1"
},
{
"sometext": "text2"
},
The json is fed in as the "data" which maps to elements on the page using the page object groovy file.
I wanted to be able to repeat the same functionality in a more groovy idiomatic way.
Any help would be much appreciated.

How to set TestName in CodedUI?

I have a data driven CodedUI test method named myTestMethod, which uses XML for supplying input data.
For each run on a data set, CodedUI reports something like this in the Test Explorer:
Test Passed - myTestMethod (Data Row 0)
Test Passed - myTestMethod (Data Row 1)
Test Failed - myTestMethod (Data Row 2) <error details>
Test Failed - myTestMethod (Data Row 3) <error details>
I was wondering is there is a way to set the test name to something more identifiable (probably from the input data set itself).
Seems like CodedUI uses TestContext.TestName for this reporting purpose, but, it is a readonly property. Is there a way to set it somewhere else, somehow?
Please help.
Thanks,
Harit
Ok i understand you now. I actually have a class where i write general functions. One of them is for save the test results as i want.
I use data driven based in XML. then my Employe1 and Employe2 are different runs of the same test_method.
Just locate [TestCleanup()] and call here a function to save a log has you need.
Log can be saved in csv format, plain text separated by ; for example with StreamWriter.
namespace NAME_SPACE
{
[CodedUITest]
public class Program_Something_BlaBla
{
Stopwatch stopWatch = new Stopwatch();
[TestMethod(), Timeout(999999999)]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", PATH_XML, "DATOS", DataAccessMethod.Sequential)]
public void Program_Something_BlaBla_Method()
{
string employe = TestContext.DataRow["EMPLOYE"].ToString();
try
{
//Test actions
...
{
catch (Exception g)
{
...
return;
}
}
#region Additional test attributes
// You can use the following additional attributes as you write your tests:
////Use TestInitialize to run code before running each test
[TestInitialize()]
public void MyTestInitialize()
{
stopWatch.Start();
...
}
//Use TestCleanup to run code after each test has run
[TestCleanup()]
public void MyTestCleanup()
{
stopWatch.Stop();
...
Common.EndTest(employe);
}
#endregion
Hope it helps,
I don't want to say it's impossible, but the Test Explorer in populated at compile time and the data would be pulled in at run time.
I don't think this would be possible. The only way for you is to read the generated "TRX" file ( as it is xml) and replace the values by reading your csvs. Might need to do a tool but the overhead is huge.

Resources