The example from github doesn't work for me.
https://github.com/nightwatchjs/nightwatch/issues/369
This is my code.
When('I open a new browser window', () => {
var host = 'http://www.google.com';
client
.windowHandle(function(wh){console.log(wh.value)})
.url(host)
.waitForElementVisible('#hplogo', 1000)
.execute(function(newWindow){
window.open('http://www.twitter.com', null, "height=1024,width=768");
}, [host])
.assert.urlContains('google')
.window_handles(function(result) {
var temp = result.value[1];
this.switchWindow(temp);
})
.windowHandle(function(wh){console.log(wh.value)})
.assert.urlContains('twitter')
.end();
});
Both console.log before and after .switchWindow print out the same string.
Does anyone have any ideas please...?
EDIT
I've changed the code a bit taking into account what pcalkins said.
This is the code now:
When('I open a new browser window', () => {
var host = 'http://www.google.com';
client
.windowHandle(function(wh){console.log("\nBEFORE: " + wh.value)})
.url(host)
.waitForElementVisible('#hplogo', 1000)
.execute(function(newWindow){
window.open('http://www.twitter.com', null, "height=1024,width=768");
}, [host])
.pause(3000)
.window_handles(function(result) {
console.log("\n\nHANDLE: " + result.value + "\n");
var temp = result.value[0];
this.switchWindow(temp);
console.log("\n\ntemp0: " + temp + "\n");
temp = result.value[1];
this.switchWindow(temp);
console.log("\n\ntemp1: " + temp + "\n");
})
.pause(2000);
});
When run, this is the result:
BEFORE is the handle for the original window.
HANDLE is both windows.
temp0 and temp1 are the two different windows in sequence. Clearly temp1 is the window I want, and yet the final this.switchWindow is not doing its job.
AFTER is the current window handle at the next test step.
I want to keep the result of my last 10 queries in Redis sorted set. I use timestamps as the score. I need to keep top 10 members by score and delete the rest. I basically need ZREMRANGEBYREVSCORE or ZREMRANGEBYREVRANK but these commands do not exist. Is there a way around this?
The redis command ZPOPMIN pops out the minimum value or specified number of minimum values from the sorted set. However, it is supported only from version 5.0.0 which is not stable.
I find a workaround with using negative scores with zremrangebyrank. I am not sure this is the right way but works for me.
counter = 0;
// temp data
setInterval(async () => {
counter += 1;
val = (new Date()).toString() + " " + counter;
score = -1 * (new Date() / 1000);
res = await client.zaddAsync("myset", score, val)
}, 1000)
// remove other than top50
setInterval(async () => {
res = await client.zremrangebyrankAsync("myset", 50, -1);
console.log("myset zremrangebyrank" + " " + res + " " + val);
}, 5000)
// log
setInterval(async () => {
res = await client.zrangeAsync("myset", 0, 5);
console.log(res);
res = await client.zcardAsync("myset");
console.log("myset zcard" + " " + res);
}, 2000)
I think you are looking for
ZREMRANGEBYRANK yourset 0 -11
This will remove all elements from your sorted set, keeping top 10.
I am watching an event:
var events = EthProj.Message({}, { fromBlock: 0, toBlock: 'latest'});
events.watch((error, results) => {
Inside the event I do this tempString = ((messages.split(":")[1].split(",")[0] + " (From: " + messages.split(":")[2].split("}")[0]) + ")").replace(/"/g, ''); Which, long story short, makes a string from the event giving the event from the block (i.e. It gives the event made at block 173).
I then set a <h2> element's text from each event. When this happens it sets them in a seemingly random order. What can be going on, it sets them from block 0 to the latest block, so how can this happen.
Here is the full code: https://pastebin.com/wGt5kL1Y
var events = EthProj.Message({}, { fromBlock: 0, toBlock: 'latest'});
events.watch((error, results) => {
i++;
messages = "";
messages = JSON.stringify(results.args);
if(i === messageToGet) {
if(messages.split(":")[1].split(",")[0] != '""') {
console.log(messages.split(":")[1].split(",")[0] + " (From: " + messages.split(":")[2].split(",")[0].split("}")[0].split("}")[0] + ")");
tempString = ((messages.split(":")[1].split(",")[0] + " (From: " + messages.split(":")[2].split("}")[0]) + ")").replace(/"/g, '');
} else {
console.log("(No included text)" + "(From: " + messages.split(":")[2].split(",")[0].split("}")[0] + ")");
tempString = (("(no included text) " + " (From: " + messages.split(":")[2].split("}")[0]) + ")").replace(/"/g, '');
}
if((messages.split(":")[1].split(",")[0] === undefined) || (messages.split(":")[2].split(")")[0] === undefined)) {
return;
}
if(document.getElementById("Message" + placeToSet) != null) {
document.getElementById("Message" + placeToSet).remove();
if(document.getElementById("hr" + placeToSet) != null) {
document.getElementById("hr" + placeToSet).remove();
}
}
if(document.getElementById("Message" + placeToSet) === null) {
var newh2 = document.createElement('h2');
newh2.setAttribute("id", ("Message" + placeToSet));
var text = document.createTextNode(tempString);
newh2.appendChild(text);
document.body.appendChild(newh2);
var newHR = document.createElement('hr');
newHR.setAttribute("id", ("hr" + placeToSet));
}
}
});
I'm trying set my second query to the pie chart datasource in angular and nodejs using multiple queries to get the results at same time
Someone have some idea to solve it.
Server Side
var url = require('url');
//Require express,
var express = require('express');
//and create an app
var app = express();
var mysql = require('mysql');
var connection = mysql.createConnection({
multipleStatements: true,
host: 'localhost',
user: 'hello',
password: 'passw',
database: 'db',
port: 330333
});
//var connection = mysql.createConnection({multipleStatements: true});
app.get('/home', function (req, res) {
res.send('Hello World!');
});
app.get('/sts', function (req, res) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", true);
res.header("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept");
// res.header('Access-Control-Allow-Methods', 'POST, \n\
// GET, PUT, DELETE, OPTIONS');
connection.query(
" SELECT ST.manufacturer, ST.name, ST.model, ST.os, ST.status, " +
" SI.Coord, ST.Last_Update_Date_Time FROM " +
" ( " +
" select s.manufacturer, s.name, s.model, s.os, s. status, " +
" concat(DATE(s.last_update_date),' ',TIME(s.last_update_time)) as Last_Update_Date_Time " +
" from sts s " +
" order by Last_Update_Date_Time DESC " +
" ) AS ST JOIN " +
" ( " +
" select DISTINCT CONCAT(si.latitude, ', ', si.longitude) as Coord, " +
" concat(DATE(update_date),' ',TIME(update_time)) as Update_Date_Time " +
" from sts_info si " +
" order by Update_Date_Time DESC " +
" ) AS SI ON ST.Last_Update_Date_Time = SI.Update_Date_Time; " +
" " +
" \n\ " +
" SELECT ST.manufacturer, ST.name, ST.model, ST.os, ST.status, " +
" count(status) as CountStatus, " +
" SI.Coord, ST.Last_Update_Date_Time FROM " +
" ( " +
" select s.manufacturer, s.name, s.model, s.os, s. status, " +
" concat(DATE(s.last_update_date),' ',TIME(s.last_update_time)) as Last_Update_Date_Time " +
" from sts s " +
" order by Last_Update_Date_Time DESC " +
" ) AS ST JOIN " +
" ( " +
" select DISTINCT CONCAT(si.latitude, ', ', si.longitude) as Coord, " +
" concat(DATE(update_date),' ',TIME(update_time)) as Update_Date_Time " +
" from sts_info si " +
" order by Update_Date_Time DESC " +
" ) AS SI ON ST.Last_Update_Date_Time = SI.Update_Date_Time " +
" group by status; "
, function (err, rows) {
if (!err) {
console.log("Database is connected... \n");
console.log('The solution is: ', rows[0]);
console.log('The solution is: ', rows[1]);
} else {
console.log("Error connecting database... \n");
console.log('Error while performing Query.');
}
console.log(rows[0]);
console.log(rows[1]);
res.end(JSON.stringify(rows[0]));
res.end(JSON.stringify(rows[1]));
});
});
var server = app.listen(8000, function () {
var port = server.address().port;
var host = server.address().address;
console.log('Example app listening at http://' + host + ':' + port);
});
AngularJs
**$scope.chartOpt1 = {
bindingOptions: {
dataSource: "sts"
},**
//Exposes the current URL in the browser address bar
//Maintains synchronization between itself and the browser's URL
//Represents the URL object as a set of methods
myApp.config(function ($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
})
// route for the about page
.when('/about', {
templateUrl: 'pages/about.html',
controller: 'aboutController'
})
// route for the contact page
.when('/contact', {
templateUrl: 'pages/contact.html',
controller: 'contactController'
})
.when('/devicessts', {
templateUrl: 'pages/devicessts.html',
controller: 'devicesController'
})
.when('/sts', {
templateUrl: 'pages/sts.html',
controller: 'stsController'
});
// $locationProvider.html5Mode(true);
});
The result of the page:
Look at the data grid and pie chart aren't being showed in the page.
How do I retrieve the results from query to the angular?
Thank you
If you want get 2 responses you should :
post 2 request
OR
replace this
res.end(JSON.stringify(rows[0]));
res.end(JSON.stringify(rows[1]));
by this
res.end(JSON.stringify([rows[0],rows[1]]));
But a single http request can't send 2 responses
I've just started discovering Windows StoreApps (that's what Microsoft calls it) and I'm following the sample code here about using the FolderPicker.
I want to Iterate through the folder and read all the sub-folders and files.
There are two functions I've looked at which I thought are what I need but I'm not able to do it properly after trying hours.
In the link above, the line which says:
WinJS.log && WinJS.log("Picked folder: " + folder.name, "sample", "status");
I tried to dig deeper in the folder with something like:
folder.getFoldersAsync().then(function (folderItem) {
document.getElementById('musicFolder').innerHTML += folderItem.length + " folders)<br/>";
folderItem.forEach(function (x) {
document.getElementById('musicFolder').innerHTML += "--" + x.name + "<br/>";
x.getFilesAsync().then(function (items) {
document.getElementById('musicFolder').innerHTML += items.length + " files"+"<br>";
});
});
});
UPDATE:
I have been struggling but can't get the stuff organized while iterating folders and sub-folders.
#Damir's code doesn't dig deepest folder. We need a recursive function. I could come up with the following function but as I said result is not organized
function scanFolder(folder) {
var isInc = false;
folder.getFoldersAsync().then(function (folderItem) {
if (folderItem.length > 0) {
folderItem.forEach(function (x) {
if (!isInc) {
isInc = true;
hyphen += "-";
}
document.getElementById('musicFolder').innerHTML += hyphen + x.name + "</br>";
x.getFilesAsync().then(function (items) {
items.forEach(function (item) {
allTracks.push({
name: item.name,
path: item.path
});
document.getElementById('musicFolder').innerHTML += hyphen +"-"+ item.name + "</br>";
});
}).done(function () {
scanFolder(x);
});
});
}
});
}
You want to read all the subfolders and the files inside them? Something like this should work:
folder.getFoldersAsync().then(function (folderItem) {
document.getElementById('musicFolder').innerHTML += "(" + folderItem.length + " folders)<br/>";
folderItem.forEach(function (x) {
x.getFilesAsync().then(function (items) {
document.getElementById('musicFolder').innerHTML += "--" + x.name + " (" + items.length + " files)<br>";
items.forEach(function(item) {
document.getElementById('musicFolder').innerHTML += "----" + item.name + "<br>";
});
});
});
});
EDIT:
There's actually no need for recursion to recursively scan a folder and its subfolders in WinRT. You can use StorageFolder.CreateFileQueryWithOptions() instead:
var options = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.defaultQuery, ['*']);
options.folderDepth = Windows.Storage.Search.FolderDepth.deep;
folder.createFileQueryWithOptions(options).getFilesAsync().then(function (files) {
var paths = new Array();
files.forEach(function(file) {
paths.push(file.path);
});
paths.sort();
paths.forEach(function(path) {
document.getElementById('musicFolder').innerHTML += path + "<br>";
});
});
From here on you can transform the flat list of files to whatever you need instead of just printing out their path.