Extent Report Spark Disregards Line Feed (New Line) - testing

I added Extent Report 5 to tests and attached spark reporter to it, all in all it looks good, however I take result.getThrowable().getMessage() and it does not apply \n\r or \n in resulting index.html.
I know that it happens somewhere after flush is called, since in log list it still have the correct string with all characters. Also, if I send to fail() method getThrowable() itself it will be written correctly, but it have unnessessary data - exception and stack trace.
For reference my spark-config file looks like this:
{
"documentTitle": "Extent Reports Title",
"encoding": "utf-8",
"js": "",
"offlineMode": true,
"protocol": "HTTPS",
"reportName": "ExtentReportsName",
"timelineEnabled": false,
"timeStampFormat": "MMM dd, yyyy HH:mm:ss",
"theme": "dark"
}

The only other way I know is to send your input wrapped in <pre></pre> tags.
You can use the below technique which will keep your formatting intact.
test.fail(result.getThrowable());

Related

Zabbix pre-processing item get item within an array with javascript

I don't have any experience with Javascript so I'm reaching out for the community to accomplish the below.
I have a few API calls configured on Zabbix which are working just fine. The thing is, not all of the results within an item is importante for me so I need to grab just what I want out of the array.
I'm using the pre-processing option on Zabbix to grab what I'm after but I can't get the code correct.
For instance, the below is one of the results Zabbix is getting.
[
{
"batteryLife": "15 minutes",
"communityString": "public",
"instanceId": "260596.1",
"instanceName": "UPS-01",
"ipAddress": "10.1.100.44",
"modelNumber": "GXT4-10000RT230",
"name": "UPS-01",
"objectType": "ScUps",
"scName": "pth-pf-04",
"scSerialNumber": 260596,
"serialNumber": "unknown",
"status": "Up",
"statusDescription": "Online",
"type": "Liebert"
}
]
How Can I Use the pre-processing to grab just the "ipAddress" value for instance?
Thanks for the help.
PeteF
You can avoid JavaScript preprocessing where you can use JSONPath preprocessing, see https://www.zabbix.com/documentation/current/manual/config/items/preprocessing/jsonpath_functionality
In your case:
$[0].ipAddress
A useful tool for JSONPath is http://jsonpath.com/
In case someone have the same doubt as I was having here is how I got it working to return the "ipAdress" value
var json = JSON.parse(value);
return json.ipAddress;
In case there are more than one dictionary inside of an array.
var json = JSON.parse(value);
return json[0].ipAddress;

How to have PhantomJSCloud wait for imbedded javascript in content

I am passing an HTML string to PhantomJSCloud in the "content" of the page. The HTML has JS embedded in it inside script tags at the end of the string. When I return the jpeg that I am requesting from PJSC, the objects that the JS manipulates, have not been manipulated. I know the js works, because I can copy and paste the whole html string to a file, open it in chrome, and watch it happen.
It is using Chart.js, which has an animation option, but i have set it to false.
Currently my request JSON looks like this:
"pages": [
{
"content": "$$$CONTENT$$$",
"renderSettings": {
"quality": 100,
"selector": "[id='report']"
},
"requestSettings": {
"ioWait": 5000,
"waitInterval": 5000
}
}
]
}
Replacing the "$$$CONTENT$$$" with my actual HTML string. The whole request takes less than 5 seconds so the "waitInterval" doesn't seem to be what I'm looking for.
This turned out to not be an issue of whether it was waiting on the javascript. My javascript was manipulating text, and some of that text had a \n inside of it. It apparently needed a \\\n

Ember-data multi-word model fields not serialized properly

I'm seeing some odd behavior with some custom serializer code that I wrote.
I have a field in an Asset model called 'marketName'. My Rails backend expects this field to be called 'market_name'. I've extended the ActiveModelSerializer and have overridden the 'extractSingle' and 'serialize' methods.
The odd thing is this - for all the other fields in my Asset model that are not made up of multiple words - the serialization code that I've written works great. No issues. However - for any field containing multiple words - the serialization doesn't work completely, in that while it saves the Asset when created - it doesn't correctly populate the Asset model's 'marketName' field (and any other field that is made up of multiple words).
For example if I examine the 'marketName' field in the data inspector it appears as '{}'. If I change the name of any multi word field in my Asset model to be singular (aka change 'marketName' to 'name') and update the serialization code accordingly - everthing works great.
Any idea what's going on ?
Thanks
Dave
In the test of extractSingle() that the core team (see line 126, also show below incase link goes bad for future readers) did, they pass in the variables as super_villains, then later the normalize() included in ActiveModelSerializer changes it for them to superVillains.
So I think in your extractSingle assume the values are not yet camelCase, but still are still in underscore_format (e.g., "market_name"), and you should be golden!
test("extractSingle", function() {
env.container.register('adapter:superVillain', DS.ActiveModelAdapter);
var json_hash = {
home_planet: {id: "1", name: "Umber", super_villain_ids: [1]},
super_villains: [{
id: "1",
first_name: "Tom",
last_name: "Dale",
home_planet_id: "1"
}]
};
var json = env.amsSerializer.extractSingle(env.store, HomePlanet, json_hash);
deepEqual(json, {
"id": "1",
"name": "Umber",
"superVillains": [1]
});
env.store.find("superVillain", 1).then(async(function(minion){
equal(minion.get('firstName'), "Tom");
}));
});

jQuery DataTables - understanding how data is fed in, mRender/mData..?

I am struggling with grasping jQuery datatables (v1.10.1 via CDN), and the conventions used in the current version. Various documentation is confusing/lacking in 'complete' examples at best, conflicting at worst.
Please explain the current (v1.10.1) best practices with regards to defining the contents of a field.
I see lots of information about columns/mData/mRender/mDataProp, amongst others and I feel overloaded as to what each one means and/or when each should be used (see the 'research' section below for examples).
Secondly, where do I stand with regards to using dates and "set"/"display"/"filter"/"sort" (assuming that this is the route to take, with mData/mRender)?
Example
EDIT: Here's an example of some data in a fiddle:
var massData = [
{ "Column1": "test1", "Timestamp": "Sun Jul 27 2014 14:42:20 GMT+0100 (GMT Standard Time)", "Date": "18/10/2012" },
{ "Column1": "test2", "Timestamp": "Mon Jul 28 2014 14:42:20 GMT+0100 (GMT Standard Time)", "Date": "18/10/2016" },
{ "Column1": "test3", "Timestamp": "Wed Jul 22 2014 14:42:20 GMT+0100 (GMT Standard Time)", "Date": "18/01/2012" }
];
var keys = ["Column1", "Timestamp", "Date"];
var columns = [];
for (var keyIndex = 0; keyIndex < keys.length; keyIndex++) {
columns.push({
"title": keys[keyIndex],
"data": keys[keyIndex],
"defaultContent": ""
});
}
$('#demo').html('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>');
$('#example').dataTable({
"data": massData,
"deferRender": true,
"scrollY": 400,
"scrollX": true,
"columns": columns
});
http://jsfiddle.net/2M97f/
Research
I see this question which has code using mRender, though my understanding is that filtering/sorting will use the actual data
I see this example and this documentation which uses aoColumnDefs, aTargets and mData..?
This question has a reply to "Filtering using the rendered text", but uses aoColumnDefs, mDataProp, and a 'renderDate()' function, but does NOT make use of mRender
The documentation for mRender and mData suggests that mRender depends upon mData..
Other documentation suggests fnRender/bUseRendered is deprecated
First of all, you're looking at examples from previous version (which are obvious based on the Hungarian Notation) So any example with mData may work now, but could be rendered unusable once legacy support is removed. While they can give you an idea of a direction to go, it's dangerous to find methods in the old API and then expect them to work as-is with 1.10. There is a version converter document that helps a lot to understand equivalents between old and new.
My preference is to use this example that uses the "columns" definition to specify the data field easily. You can also quickly and easily define things for each column there, such as searchable, title, visible, etc. See the API for others.
So, a sample Datatable in my code would look like this:
$('#example').DataTable( {
data: data,
columns: [
{ data: 'keyoffield1', title:'name title', visible:'false' },
{ data: 'keyoffield2', title:'position title' },
{ data: 'keyoffield3', title:'salary title here' },
{ data: 'keyoffield4', title:'office title here' }
]
} );
As for sorting, it's setup to recognize date fields out of the box for you, as you can see in your example (click on the header to change the sort) However, if you want to set default sorts such as asc, desc, etc, that's pretty easily done with columns.sort as you'll see in the API. There is a simple plugin to enhance sorting on fields that may not be formatted in a way that DataTables is built to use.
fnRender is gone, the closest equivalents are explained here. If you ignore those examples and the complaining that happened when it was removed, it's pretty easy to see how Allan was proceeding with the new methods like column.render for example.

how do we read a csv file and display the same in dojo?

i want to write a dojo code where upon a button click i want to read a .csv file and display the .csv file in a datagrid using Dojo. Can anyone please help me with this?
Your best try is to retrieve the data using the dojo/request/xhr module, with it you can retrieve an external CSV file. For example:
require(["dojo/request/xhr"], function(xhr) {
xhr.get("myfile.csv", {
handleAs: "text"
}).then(function(data) {
// Use data
});
});
Well, now you have the data as a string in your data parameter, what you now need to do is parse that string. The easiest way is to split your string on each enter, for example:
var lines = data.split(/\r?\n/);
The \r is optional (depends on the system you're using), but now you have each line seperated in an array element in lines. The next step is to retrieve each seperate value, for example by doing:
require(["dojo/_base/array"], function(array) {
/** Rest of code */
array.forEach(lines, function(line) {
var cells = line.split(',');
});
});
Then you have your data splitted by each comma. The next step is that you have to change it to a format that the dojox/grid/DataGrid can read. This means that you will probably convert the first line of your CSV content to your headers (if they contain headers) and the rest of the data to objects (in stead of arrays of strings).
You can get the first line with:
var headers = lines[0].split(',');
And the rest of the data with:
var otherData = lines.splice(1);
Now you should carefully read the documentation #MiBrock gave you, and with it you can transform the simple array of strings to the correct format.
The headers should become an array of objects like this:
[{ name: "display name", field: "field name" }, { /** other objects */ }]
I did that by doing:
array.map(headers, function(header) {
return {
field: header,
name: header
};
});
This will actually convert [ "a", "b" ] to:
[{ field: "a", name: "a" }, { field: "b", name: "b" }]
Now you need to convert all other lines to objects containing a field with name a and a field with name b, you can do that using:
array.map(otherData, function(line) {
var cells = line.split(','), obj = {};
array.forEach(cells, function(cell, idx) {
obj[headers[idx]] = cell;
});
return obj:
});
This will actually retrieve the fieldname by retrieving the corresponding header value and output it as a single object.
Now you can put it in a grid, look at #MiBrock's answer for more details about how to do that. The final result would look a bit like this JSFiddle.
Note: Next time you encounter a problem you can't solve, handle the parts you actually can solve first and then ask a question about the other parts. I mean, it's hard to believe that you can actually not solve any of this by yourself. You should try and learn it by yourself first.
The dojo-smore project includes a CSV object store that loads data from CSV into an in-memory store which can then be used with any component that supports object stores, like dgrid. You shouldn’t try to do it yourself, like Dimitri M suggested, and you shouldn’t use the dojox grids, which are deprecated.
You can use dojox.data.CsvStore to read a CSV store and use it in a data grid.
Have a look here : http://dojotoolkit.org/reference-guide/1.8/dojox/grid/index.html#dojox-grid-index
and here: http://dojotoolkit.org/documentation/tutorials/1.9/populating_datagrid/
This should help you to start with your Programming.
If you need further help, show us what you have tried to solve the Problem by posting your code and we'll be glad to help you.
Regards, Miriam