Repeating steps again with the new data in nightwatchjs - nightwatch.js

I have a csv data. I want to repeat each steps except the read csv step in the nightwatchjs then execute those steps with each line of csv. How that can be possible with nightwatchjs?
Steps are like
module.exports =
{
"ReadCsv" : function(client) {
// This will have an array of csvData
},
"StepOne" : function(client) {
//Code goes there...
},
"StepTwo" : function(client) {
//Code goes there...
},
"StepThree" : function(client) {
//Code goes there...
},
}
I want to repeat the steps StepOne, StepTwo & StepThree with each line of the csvData so that everything can be tested. What I tried is
"loopUntilEnd" : function(client)
{
for (var i = 1; i < csvData.length; i++)
{
this.StepOne(client, csvData[i])
this.StepTwo(client)
this.StepThree(client)
}
},
But it didn't worked.

The solution which I found is to use bash scripting and loop the csv data and execute the nightwatchjs until everything is finished.
My shell script will be like this.
#!/bin/bash
export IFS=","
cat mycsv.csv |
while read a b c d;
do echo "$a:$b:$c:$d";
nightwatch -t tests/test-script.js $a:$b:$c:$d;
done
And in the global.js file of nightwatchjs accept the csv data like this
CSV_DATA : process.argv[4].split(":").join(" "),

Related

How to modify just a property from a dexie store without deleting the rest?

I'm having the dexie stores showed in the print screen below:
Dexie stores print screen
My goal is to update a dexie field row from a store without losing the rest of the data.
For example: when I edit and save the field "com_name" from the second row (key={2}) I want to update "com_name" only and not lose the rest of the properties, see first and the third row.
I already tried with collection.modify and table.update but both deleted the rest of the properties when used the code below:
dexieDB.table('company').where('dexieKey').equals('{1}')
//USING table.update
//.update(dexieRecord.dexiekey, {
// company: {
// com_name: "TOP SERVE 2"
// }
//})
.modify(
{
company:
{
com_name: TOP SERVE 2
}
}
)
.then(function (updated) {
if (updated)
console.log("Success.");
else
console.log("Nothing was updated.");
})
.catch(function (err) { console.log(err); });
Any idea how can I accomplish that?
Thanks
Alex
You where right to use Table.update or Collection.modify. They should never delete other properties than the ones specified. Can you paste a jsitor.com or jsfiddle repro of that and someone may help you pinpoint why the code doesn't work as expected.
Now that you are saying I realised that company and contact stores are created dynamically and editedRecords store has the indexes explicitly declared therefore when update company or contact store, since dexie doesn't see the indexes will overwrite. I haven't tested it yet but I suspect this is the behaviour.
See the print screen below:
Dexie stores overview
Basically I have json raw data from db and in the browser I create the stores and stores data based on it, see code below:
function createDexieTables(jsonData) { //jsonData - array, is the json from db
const stores = {};
const editedRecordsTable = 'editedRecords';
jsonData.forEach((jsonPackage) => {
for (table in jsonPackage) {
if (_.find(dexieDB.tables, { 'name': table }) == undefined) {
stores[table] = 'dexieKey';
}
}
});
stores[editedRecordsTable] = 'dexieKey, table';
addDataToDexie(stores, jsonData);
}
function addDataToDexie(stores, jsonData) {
dbv1 = dexieDB.version(1);
if (jsonData.length > 0) {
dbv1.stores(stores);
jsonData.forEach((jsonPackage) => {
for (table in jsonPackage) {
jsonPackage[table].forEach((tableRow) => {
dexieDB.table(table).add(tableRow)
.then(function () {
console.log(tableRow, ' added to dexie db.');
})
.catch(function () {
console.log(tableRow, ' already exists.');
});
});
}
});
}
}
This is the json, which I convert to object and save to dexie in the value column and the key si "dexieKey":
[
{
"company": [
{
"dexieKey": "{1}",
"company": {
"com_pk": 1,
"com_name": "CloudFire",
"com_city": "Round Rock",
"serverLastEdit": [
{
"com_pk": "2021-06-02T11:30:24.774Z"
},
{
"com_name": "2021-06-02T11:30:24.774Z"
},
{
"com_city": "2021-06-02T11:30:24.774Z"
}
],
"userLastEdit": []
}
}
]
}
]
Any idea why indexes were not populated when generating them dynamically?
Given the JSON data, i understand what's going wrong.
Instead of passing the following to update():
{
company:
{
com_name: "TOP SERVE 2"
}
}
You probably meant to pass this:
{
"company.com_name": "TOP SERVE 2"
}
Another hint is to do the add within an rw transaction, or even better if you can use bulkAdd() instead to optimize the performance.

How to use choice parameter integer value as array in Jenkins Declarative pipeline file

I have a Jenkins choice parameter which is integer value. I need to loop through the parameter value in my Jenkins File to run a function [i] times.
Say for Ex: Choice Parameter has ['1','2','3','4'] in drop down. If I chooses 4, the loop should go through 4 times.
But my below code only displays I choose in the parameter which is '4' while echoing it. Could someone help me in loop through.
script {
def loop_value = "${params.choiceparameter}"
loop_value.each() {
echo it
}
}
Use it like this:
pipeline {
agent any
parameters {
choice choices: ['1', '2', '3', '4', '5'], description: '', name: 'choiceParameter'
}
stages {
stage("stage1") {
steps {
script {
for (i = 0; i < params.choiceParameter.toInteger(); i ++) {
print(i)
}
}
}
}
}
}
Groovy Solution
Here is a groovy solution more similar to your own
script {
def loop_value = "${params.choiceparameter}"
1.upto(loop_value.toInteger()) {
println it
}
}

dataSource.data() doesn't return the datas

I'm currently testing kendoUI and developping a little webapp.
For some reason I need to pass my dataSource.datas from a view to another. In order to do this I use sessionStorage and when I try to put my dataSource.data() in sessionStorage, the return is empty.
See here when I put a log to test if my dataSource.data() is correctly inserted/returned
However, when I put a log to test ma dataSource I can clearly see that _data is not empty as it is showed in the follow picture :
Did someone know the origin of my problem ?
EDIT
here is the code that shows how I add my dataSource to sessionStorage :
var qui = (e.view.params.qui) ? e.view.params.qui : "";
var quoi = (e.view.params.quoi) ? e.view.params.quoi : "";
dataSourceFournisseurs = new kendo.data.DataSource({
transport : {
read : {
url:"annuaire.json",
dataType:"json"
}
},
schema : {
data : "data",
model : {
DISTANCE: function() {
var lat = this.get("LATITUDE");
var lng = this.get("LONGITUDE");
var distance = APP.distanceBetweenCoords(lat, lng);
return "à " + distance + "km";
}
}
},
sort : {
field : "LIBELLE",
dir : "asc"
},
filter: [
{ field: "LIBELLE", operator: "contains", value: qui },
{ field: "NAFLIBELLE", operator: "contains", value: quoi }
]
});
console.log(dataSourceFournisseurs);
session.setValueObject("liste", dataSourceFournisseurs.data());
And here is how I retrieve it :
var datas = session.getValueObject("liste");
console.log(datas);
PS :
setValueObject and getValueObject are two methods I wrote in order to Stringify the datas I set and Parse the retrieved datas (there are fully functionnal I use them for over a year)
the two console.log are those that represent the picture above (picture 1 with second log and picture 2 with first log)
EDIT END
Try using dataSourceFournisseurs.view(). This should give you the all of the data. Using data is meant for initial configuration, and is not meant to be used as a method for retrieving data.
Bonne chance!

Does the completions file "contents" have to be 1 line (no newline)?

New to sublime text and trying to setup some completions as I have a bunch of snippets and I'd rather just use 1 file, instead of separate files for each snippet.
When I save the below code, I get the error that it can't parse the file, unexpected newline. I'd assume it's because I'm using linebreaks. Are completions only for short 1 line code? Is there anything that can be done so I don't have to use individual files for snippets when I have longer code like below?
{
"completions":
[
{ "trigger": "clearforms", "contents":
"//clear form fields
\$(function() {
\$.fn.clearInput = function() {
return this.focus(function() {
if( this.value == this.defaultValue ) {
this.value = "";
}
}).blur(function() {
if( !this.value.length ) {
this.value = this.defaultValue;
}
});
};
\$('#subscribe').clearInput();
\$('#search').clearInput();
});"
}
]
}
JSON does not allow multi-line strings - the line breaks need to be encoded as \n. The $ symbol needs to be double-escaped like so \\$, and your comment forward slashes single-escaped like so - \/\/. So, your completions file needs to look like this:
{
"completions":
[
{ "trigger": "clearforms", "contents": "\/\/ clear forms \n\\$(function() { \n\\$.fn.clearInput = function() { \nreturn this.focus(function() { \nif( this.value == this.defaultValue ) { \nthis.value = \"\"; \n} \n}).blur(function() { \nif( !this.value.length ) { \nthis.value = this.defaultValue; \n} \n}); \n}; \n\n\\$('#subscribe').clearInput(); \n\\$('#search').clearInput(); \n});" }
]
}
I'll leave it up to you to put in the appropriate whitespace after each line break. I should note that while it may be slightly more "clutter-y" to have individual snippet files, they do allow multi-line entries with no newline escaping needed, allowing you to format your output more easily. However, the $ and possibly the JS comments might need escapes.

Kendo variables in Command section in a grid

I have noticed that it is possible to have some kendo logic and variables inside a template in the columns sections.
This is an example from my column section template
template: "#= myVariable# #if(myBoolean) {# <img src='/images/myImage.png' /> #}#"
Please do note that myVariable and myBoolean are variables (fields) of each row of the grid.
Unfortunately i tried the same under the command section in the template. I get the following error "ReferenceError: myVariable is not defined"
Is there any way to add variables in the command sections as it happens with the columns?
As far as I know using templates in columns.command is not even documented: although it works. And you can do things like:
columns : [
{
command: {
template : "# console.log('this', this); console.log('data', data); # toto"
}
},
...
]
or even like:
command: {
template : function (arg) {
console.log("this" ,this);
console.log("arg", arg);
console.log("data", data);
return "toto";
}
}
But what the template returns needs to be a string and in the console of your browser you will see that this is window, arg is the object command and data is an array containing grid data.
Although you can include extra arguments as:
command: {
template : function (arg) {
console.log("this" ,this);
console.log("arg", arg);
console.log("arg.a", arg.a);
console.log("data", data);
return "toto";
},
a: "extra argument"
}
Where I add an extra a argument that can be accessed via arg.a you still cannot get access to current row data since the element is still not inserted.
Instead of that what I do propose is doing something like:
columns : [
{
title: " ",
template: "#= myVariable# #if(myBoolean) {# <img src='/images/myImage.png' /> #}#"
},
...
]
You don't need to have it as command, right? Why do you need it as command?

Resources