The testrail-api have 4 method to update result.
add_result
add_result_for_case
add_results
add_results_for_cases
add_result >> How should I do let me can add result to step?
The TestRail documentation includes an example of how to add steps when using the add_result endpoint. You need to use the custom_step_results field as shown below:
{
"status_id": 5,
"comment": "This test failed",
"elapsed": "15s",
"defects": "TR-7",
"version": "1.0 RC1 build 3724",
"custom_step_results": [
{
"content": "Step 1",
"expected": "Expected Result 1",
"actual": "Actual Result 1",
"status_id": 1
},
{
"content": "Step 2",
"expected": "Expected Result 2",
"actual": "Actual Result 2",
"status_id": 2
}
]
}
Related
I want to modify the current JSON file with the following change:
I want to edit the "Vs" column and split that data into two columns. I want it to be split into two columns named team 1 and team 2 respectively by splitting data after 'vs'.
How should I do that using python script?
Input: JSON data (this is sample data.)
[
{
"Match No": "1",
"Date": "17-10-21",
"Vs": "Sri Lanka vs Ireland",
"Rounds": "1st",
"Group": "Group A"
},
Required Output: JSON data
[
{
"Match No": "1",
"Date": "17-10-21",
"Team1": "Sri Lanka",
"Team2": "Ireland",
"Rounds": "1st",
"Group": "Group A"
},
So, I used the library json to serialize your input. THen you only need to loop over each object in the json array and create a new json object from the data. I hope you understand the principal.
import json
input = """
[
{
"Match No": "1",
"Date": "17-10-21",
"Vs": "Sri Lanka vs Ireland",
"Rounds": "1st",
"Group": "Group A"
}
]
"""
result = json.loads("""
[
]
""")
for o in json.loads(input):
teams = o["Vs"].split(" vs ")
result.append({
"Match No": o["Match No"],
"Date": o["Date"],
"Team 1": teams[0],
"Team 2": teams[1],
"Rounds": o["Rounds"],
"Group": o["Group"]
})
print(result)
I have a json that looks like this:
[
{
"auth": 1,
"status": "Active",
"userCustomAttributes": [
{
"customAttributeName": "Attribute 1",
"customAttributeValue": "Value 1"
},
{
"customAttributeName": "Attribute 2",
"customAttributeValue": "Value 2"
},
{
"customAttributeName": "Attribute 3",
"customAttributeValue": "Value 3"
}
],
},
{
"auth": 1,
"status": "Active",
"userCustomAttributes": [
{
"customAttributeName": "Attribute 1",
"customAttributeValue": "Value 1"
},
{
"customAttributeName": "Attribute 2",
"customAttributeValue": "Value 2"
},
{
"customAttributeName": "Attribute 3",
"customAttributeValue": "Value 3"
},
{
"customAttributeName": "Attribute 4",
"customAttributeValue": "Value 4"
}
],
}
]
I would like to parse this and have a css output that looks something like this:
authType, status, attribute 1, attribute 2, attribute 3, attribute 4
"1", "active", "value1", "value2", "value3",""
"1", "active", "value1", "value2", "value3","value 4"
The json has over 180k records in the array so it would need to loop through all of them. Some records don't have all the attributes. Some have all 4 yet some only have 1. I am hoping to show a null value in the csv for the records that don't have the attribute.
With your sample input, the following program, which does not depend on the ordering of the "attribute" keys:
jq -r '
["Attribute 1", "Attribute 2", "Attribute 3", "Attribute 4"] as $attributes
# Header row
| ["authType", "status"]
+ ($attributes | map( (.[:1] | ascii_upcase) + .[1:])),
# Data rows:
(.[]
| (INDEX(.userCustomAttributes[]; .customAttributeName)
| map_values(.customAttributeValue)) as $dict
| [.auth, .status] + [ $dict[ $attributes[] ] ]
)
| #csv
'
produces the following CSV:
"authType","status","Attribute 1","Attribute 2","Attribute 3","Attribute 4"
1,"Active","Value 1","Value 2","Value 3",
1,"Active","Value 1","Value 2","Value 3","Value 4"
You can easily modify this to emit a literal string of your choice in place of a JSON null value.
Explanation
$dict[ $a[] ] produces the stream of values:
$dict[ $a[0] ]
$dict[ $a[1] ]
...
This is used to ensure the columns are produced in the correct order, independently of the ordering or even presence of the keys.
I have a JSON where I should prepare a HTML on basis of that. Please find my JSON below
{
"apiName": "myapi-v10",
"eventKey": "monitor_records",
"emailSubject": "local: PLAYER Records",
"customFields": {
"x_transaction_id": "9f99a9b0-30f5-11ea-8347-381c20524153",
"emailData": {
"Table 1": {
"title": "Some X",
"headers": [
"COUNT",
"PLAYER",
"STATUS"
],
"data": [
{
"COUNT": 4,
"PLAYER": "APLAYER",
"STATUS": "Open"
},
{
"COUNT": 2,
"PLAYER": "APLAYER",
"STATUS": "Waiting"
},
{
"COUNT": 3,
"PLAYER": "CPLAYER",
"STATUS": "Closed"
},
{
"COUNT": 2,
"PLAYER": "CPLAYER,
"STATUS": "withheld"
},
{
"COUNT": 3,
"PLAYER": "NPLAYER",
"STATUS": "Closed"
},
{
"COUNT": 2,
"PLAYER": "NPLAYER",
"STATUS": "provationsiu"
},
{
"COUNT": 4,
"PLAYER": "WPLAYER",
"STATUS": "boost"
},
{
"COUNT": 1,
"PLAYER": "WPLAYER",
"STATUS": "No Status"
}
]
},
"Table 2": {
"Title": "Some Y",
"Headers": [
"COUNT",
"PLAYER",
"STATUS"
],
"data": [
{
"COUNT": 4,
"PLAYER": "APLAYER",
"STATUS": "Open"
},
{
"COUNT": 2,
"PLAYER": "APLAYER",
"STATUS": "Closed"
},
{
"COUNT": 3,
"PLAYER": "CMH",
"STATUS": "Closed"
},
{
"COUNT": 2,
"PLAYER": "CMH",
"STATUS": "withheld"
},
{
"COUNT": 3,
"PLAYER": "NPLAYER",
"STATUS": "Closed"
},
{
"COUNT": 4,
"PLAYER": "WPLAYER",
"STATUS": "boost"
},
{
"COUNT": 1,
"PLAYER": "WPLAYER",
"STATUS": "No Status"
}
]
}
}
}
}
I need to loop through customFields->emailData tables and access each value in it. I tried multiple ways but none seems to work out and throws the below exception.
For "." left-hand operand: Expected a hash, but this has evaluated to a method+sequence
FTL Code snippet being used as below
<div style="font-family: Arial, Helvetica, sas-serif; font-size: 10pt;">
<#assign tableValues = customFields.emailData?values>
<#assign tableKeys = customFields.emailData?keys/>
<#list tableKeys as tableKey>
<#assign seq_index = tableKeys?seq_index_of(tableKey) />
<#assign tableValue = tableValues[seq_index]/>
<table class="demo">
<caption>${tableValue.title}</caption>
<thead>
<tr>
<#list tableValue.headers as header>
<th>${header}</th>
</#list>
</tr>
</thead>
<tbody>
<#assign rows = table.data>
<#list rows as row>
<tr>
<#list tableValue.headers as header>
<td>${row[header]}</td>
</#list>
</tr>
</#list>
</tbody>
</table>
<p> </p>
</#list>
</div>
Note: I'm using 2.3.23 freemarker version and upgrading or downgrading to other version is not possible as this takes lot of approvals.
Also any suggestions to modify JSON which will result in easier ftl code are welcome.
It fails while trying to parse at title itself.
Exception Trace:
Jan 08, 2020 11:05:32 AM freemarker.log._JULLoggerFactory$JULLogger error
SEVERE: Error executing FreeMarker template
FreeMarker template error:
For "." left-hand operand: Expected a hash, but this has evaluated to a method+sequence (wrapper: f.e.b.SimpleMethodModel):
==> tableValue [in template "monitorapi-success.template" at line 30, column 52]
----
Tip: Maybe using obj.something(params) instead of obj.something will yield the desired value
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${tableValue.title} [in template "monitorapi-success.template" at line 30, column 50]
----
Java stack trace (for programmers):
----
freemarker.core.NonHashException: [... Exception message was already printed; see it above ...]
at freemarker.core.Dot._eval(Dot.java:45)
at freemarker.core.Expression.eval(Expression.java:78)
at freemarker.core.Expression.evalAndCoerceToString(Expression.java:82)
at freemarker.core.DollarVariable.accept(DollarVariable.java:41)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.MixedContent.accept(MixedContent.java:54)
at freemarker.core.Environment.visitByHiddingParent(Environment.java:345)
at freemarker.core.IteratorBlock$IterationContext.executeNestedBlockInner(IteratorBlock.java:240)
at freemarker.core.IteratorBlock$IterationContext.executeNestedBlock(IteratorBlock.java:220)
at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:194)
at freemarker.core.Environment.visitIteratorBlock(Environment.java:572)
at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:78)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:64)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.MixedContent.accept(MixedContent.java:54)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.Environment.process(Environment.java:302)
at freemarker.template.Template.process(Template.java:325)
at TestEmailTemplate.main(TestEmailTemplate.java:24)
Exception in thread "main" FreeMarker template error:
For "." left-hand operand: Expected a hash, but this has evaluated to a method+sequence (wrapper: f.e.b.SimpleMethodModel):
==> tableValue [in template "monitorapi-success.template" at line 30, column 52]
----
Tip: Maybe using obj.something(params) instead of obj.something will yield the desired value
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${tableValue.title} [in template "monitorapi-success.template" at line 30, column 50]
----
Java stack trace (for programmers):
----
freemarker.core.NonHashException: [... Exception message was already printed; see it above ...]
at freemarker.core.Dot._eval(Dot.java:45)
at freemarker.core.Expression.eval(Expression.java:78)
at freemarker.core.Expression.evalAndCoerceToString(Expression.java:82)
at freemarker.core.DollarVariable.accept(DollarVariable.java:41)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.MixedContent.accept(MixedContent.java:54)
at freemarker.core.Environment.visitByHiddingParent(Environment.java:345)
at freemarker.core.IteratorBlock$IterationContext.executeNestedBlockInner(IteratorBlock.java:240)
at freemarker.core.IteratorBlock$IterationContext.executeNestedBlock(IteratorBlock.java:220)
at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:194)
at freemarker.core.Environment.visitIteratorBlock(Environment.java:572)
at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:78)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:64)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.MixedContent.accept(MixedContent.java:54)
at freemarker.core.Environment.visit(Environment.java:324)
at freemarker.core.Environment.process(Environment.java:302)
at freemarker.template.Template.process(Template.java:325)
at TestEmailTemplate.main(TestEmailTemplate.java:24)
Process finished with exit code 1
Issue is fixed when I convert the JSON to HashMap.
I'm trying to design a nested MongoDB schema.
Currently, I have this schema and it's working:
var CompanySchema = new mongoose.Schema({
name: String,
rate: number
date: Date
})
But I wanna expend it to get:
var CompanySchema = new mongoose.Schema({
name: String,
currency: {
mxn: Number,
php: Number,
},
source: [String],
deliveryMethod: [String],
date: Date
})
For source, I want to get an array of inputs ex. ["bank", "debit card", "agent"]
and almost samething for deliverymethod.
But either my input is wrong or my schema, because the value for source saves as one long string, not a separated value.
Also, I think the way I designed the currency to have more currency rate is correct but I don't know how my input json should suppose to be.
I tried it in postman:
{
"name": "google",
"currency": {
"mxn": 20,
"php": 30
}
}
and this is the result i got:
{
"status": 201,
"data": {
"__v": 0,
"name": "google",
"date": "2017-12-06T22:38:45.896Z",
"_id": "5a2871752e3b7343dc388549",
"deliveryMethod": [
null
],
"source": [
null
]
},
"message": "Succesfully Created Company"
}
1- if my currency nested schema is correct how should be my post json file be?
2- how can I get source and deliveryMethod as an array of string?
The JSON in the request body should look like this:
{
"name": "google",
"currency": {
"mxn": 20,
"php": 30
},
"source": ["source1", "source 2", "source 3"],
"deliveryMethod": ["delMetd 1", "delMetd 2", "delMetd 3"],
"date": "2015-11-27T23:00:00Z"
}
I copy/pasted your code and tried with Postman. The response I got back was:
{
"__v": 0,
"name": "google",
"date": "2015-11-27T23:00:00.000Z",
"_id": "5a2915295c5f714f7cb25d90",
"deliveryMethod": [
"delMetd 1",
"delMetd 2",
"delMetd 3"
],
"source": [
"source1",
"source 2",
"source 3"
],
"currency": {
"mxn": 20,
"php": 30
}
}
If I connect to the database with the mongo shell and run db.companies.find().pretty() I get this result:
{
"_id" : ObjectId("5a2915295c5f714f7cb25d90"),
"name" : "google",
"date" : ISODate("2015-11-27T23:00:00Z"),
"deliveryMethod" : [
"delMetd 1",
"delMetd 2",
"delMetd 3"
],
"source" : [
"source1",
"source 2",
"source 3"
],
"currency" : {
"mxn" : 20,
"php" : 30
},
"__v" : 0
}
Your schema is fine. You can try dropping the collection (db.companies.drop()) if you can't get it to work. Start with a fresh one if you don't have any important data in it.
When having a nested document like this:
{
"blog": "testblog1",
"user_id": 41,
"comments": [
{
"comment": "testcomment1",
"user_id": 883
},
{
"comment": "testcomment2",
"user_id": 790
}
]
}
can one do an Update Operation with N1QL to add an extra field to a subdocument?
I would like to add the field "ranking" : "top comment" to the subdocument with the comment testcomment2:
{
"blog": "testblog1",
"user_id": 41,
"comments": [
{
"comment": "testcomment1",
"user_id": 883
},
{
"comment": "testcomment2",
"user_id": 790,
"ranking" : "top comment"
}
]
}
Site Note: The following statement would add a field to the root document on the Collection Blog:
UPDATE Blog SET rank = "top blog" WHERE blog = "testblog1";
Yes, you can do the following in N1QL:
UPDATE Blog
SET c.ranking = "top comment" FOR c IN comments WHEN c.comment = "testcomment2" END
WHERE blog = "testblog1"