Multiple level of sections in page_objects in nightwatch.js - node.js

I have just started out using nightwatch.js , and I am using page_objects to access elements in my tests. So what I was wondering is there anyway we can have sections within sections in page objects? I know that we can specify one level of section. What I have done is something like this :
module.exports = {
url : 'http://127.0.0.1:8111/local.html#open?view=shelf&lang=en_US',
sections : {
topContainer : {
selector : '.top_container',
elements : {
logo : {
selector : '.logo'
},
settingsButton : {
selector :'.dropdown'
},
searchBox : {
selector : '.search_box'
},
sortOrderButton : {
selector : '.icond'
}
}
},
library : {
selector : '.library',
bookList : {
selector : 'ul.library_container'
}
}
}
};
Can we have sections inside sections , and in case not , how do we select in test case with #variable
client.elements('css selector','#top_container ul.dropdown-menu li', function (result) {
if ( result.value.length == 3 ) {
this.verify.ok(result.value.length, '3 languages loaded');
}
});
Thanks !

The nightwatch.js documentation for "Working With Page Objects" specifies
Note that every command and assertion on a section (other than expect assertions) returns that section for chaining. If desired, you can nest sections under other sections for complex DOM structures.
So , I tried using by hit and try to make the correct json structure , and it works great now :)
Sample code in page_object
sections : {
book_view : {
selector : '.read_book_view',
sections : {
top_container : {
selector : '.top_container',
elements : {
lib_view : {
selector : '.lib_view'
},
toc_link : {
selector : '.dropdown .dropdown-toggle'
},
toc_index : {
selector : '.dropdown .index-dropdown'
},
notes_and_hightlights : {
selector : '.page_access'
},
settings : {
selector : '#settings_b'
},
search : {
selector : '.search_trigger'
},
zoom : {
selector : '.zoom_iconsset'
}
}
}
}
}
}
and referring to them in test cases, like this
var bookSection = bookView.section.book_view;
// Top container
var topSection = bookSection.section.top_container;
topSection.expect.element('#lib_view').to.be.present;
Thanks !

Related

Mongo text search with AND operation for multiple words partially enered

{
TypeList" : [
{
"TypeName" : "Carrier"
},
{
"TypeName" : "Not a Channel Member"
},
{
"TypeName" : "Service Provider"
}
]
}
Question :
db.supplies.find("text", {search:"\"chann\" \"mem\""})
For above query I want display :
{
TypeName" : "Not a Channel Member"
}
But I am unable to get my result.
What are changes I have to do in query .
Please help me.
The below query will return your desired result.
db.supplies.aggregate([
{$unwind:"$TypeList"},
{$match:{"TypeList.TypeName":{$regex:/.*chann.*mem.*/,$options:"i"}}},
{$project:{_id:0, TypeName:"$TypeList.TypeName"}}
])
If you can accept to get an output like this:
{
"TypeList" : [
{
"TypeName" : "Not a Channel Member"
}
]
}
then you can get around using the aggregation framework which generally helps performance by running the following query:
db.supplies.find(
{
"TypeList.TypeName": /chann.*mem/i
},
{ // project the list in the following way
"_id": 0, // do not include the "_id" field in the output
"TypeList": { // only include the items from the TypeList array...
$elemMatch: { //... where
"TypeName": /chann.*mem/i // the "TypeName" field matches the regular expression
}
}
})
Also see this link: Retrieve only the queried element in an object array in MongoDB collection

Firebase and Ionic: Best way to return an object in scope

I'm new in Ionic and I have a simple question I think :
Here is my JSON :
"profiles" : {
"wXD7sHme9gSoWXcB799VgzZDDA03" : {
"uid": "wXD7sHme9gSoWXcB799VgzZDDA03",
"languesDispo": [0,2]
}
},
"langues" : {
"anglais" : {
"id" : 0
},
"allemand": {
"id" : 1
},
"espagnol": {
"id" : 2,
}
}
I would like to return in scope an object (or array) with all langues based on the ids in the profiles node at languesDispo.
I would like to know what is the best way to do that, what can I use between
$firebaseArray()
$firebaseObject()
ref.on()
ref.once()
loaded()
I have to admit I'm a little bit confused. Thank you very much for your help!

Analyzing apache access logs with elasticsearch Watcher

I am using the ELK Stack to analyze logs and I need to analyze and detect anomalies of apache access logs. What can I analyze with apache access logs and how should I give the conditions with curl -XPUT to Watcher?
If you haven't found it already, there's a decent tutorial at https://www.elastic.co/guide/en/watcher/watcher-1.0/watch-log-data.html. It provides a basic example of creating a log watch.
You can analyze/watch anything that you can query in Elasticsearch. It's just a matter of formatting the query with the correct JSON syntax. The guide for crafting the conditions is at https://www.elastic.co/guide/en/watcher/watcher-1.0/condition.html.
You'll also want to look at https://www.elastic.co/guide/en/watcher/watcher-1.0/actions.html to get an idea of the possible actions Watcher can take when a query meets a condition.
As far as the post to Watcher, each watch is essentially a JSON object. Because they can get pretty elaborate, I have found that it's best to create a file for each watch you want to create, and post them like this:
curl -XPUT http://my_elasticsearch:9200/_watcher/watch/my_watch_name -d #/path/to/my_watch_name.json
my_watch_name.json should have these basic elements (as described in the first link above):
{
"trigger" : { ... },
"input" : { ... },
"condition" : { ... },
"actions" : { ... }
}
The actions section is going to be specific to your use case, but here's a basic example of the other sections that I'm using successfully:
{
"trigger" : {
"schedule" : { "interval" : "5m" }
},
"input" : {
"search" : {
"request" : {
"indices" : [ "logstash" ],
"body" : {
"query" : {
"filtered" : {
"query" : {
"match" : { "message" : "error" }
},
"filter" : {
"range" : { "#timestamp" : { "gte" : "now-5m" } }
}
}
}
}
}
}
},
"condition" : {
"compare" : { "ctx.payload.hits.total" : { "gt" : 0 } }
},
"actions" : {
...
}
}

Updating a Set in Dynamo db using Node Js

I am trying to do one of the most simple operations "Update" in a dynamo db list.
Table Schema -
businessId : String, customers: StringSet, itemCode : NumberSet
I have an entry inserted via put -
bussinessId = "sampleBusiness", cuatomers 0: "cust1", itemCode 0: 4554
I want to add more items using update and here is what I have tried -
var updateRequest = {
'TableName' : tableName,
'Key' : {
'businessId' : {
"S" : businessId
}
},
'UpdateExpression' : "SET itemCode[2] =:attrValue",
'ExpressionAttributeValues' : {
':attrValue' : {
"N" : "564564"
}
}
};
This gives me error -
Document Path provided in document is invalid
I wanted to append new entries so tried this as well -
var sm = [];
sm[0] = "56465";
//Add business to
var updateRequest = {
'TableName' : tableName,
'Key' : {
'businessId' : {
"S" : businessId
}
},
'UpdateExpression' : 'SET #attrName = list_append(#attrName, :attrValue)',
'ExpressionAttributeNames' : {
'#attrName' : 'itemCode'
},
'ExpressionAttributeValues' : {
':attrValue' : {
"NS" : sm
}
}
};
This gives:
ValidationException: Invalid UpdateExpression: Incorrect operand type for operator or function; operator or function: list_append, operand type: NS
Also attempted this -
':attrValue' : {
"N" : "4564"
}
But same error.
As per the example provided in http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html , it adds a new element to the FiveStar review list. The expression attribute name #pr is ProductReviews; the attribute value :r is a one-element list. If the list previously had two elements, [0] and [1], then the new element will be [2].
SET #pr.FiveStar = list_append(#pr.FiveStar, :r)
which Says :r is one element list
I am missing some thing here. Request if any one can help. Struck on this for long time. I just want to append elements in set in dynamo db using nodeJS.
It looks like this:
'ExpressionAttributeValues' : {
':attrValue' : {
"NS" : sm
}
}
Should be this:
'ExpressionAttributeValues' : {
':attrValue' : {
"S" : sm
}
}
Or you need to cast this value sm[0] = "56465"; to a Number Number("56465") and change the :attrValue data type "S" to "N". Depends on how you have your table configured.
It's possible too that you should assign :attrValue to be "S" : sm[0] because right now you are passing an "S" a whole array.
I got a proper solution
var item = {"endTime": "7pm", "imageName": "7abcd", "startTime": "7pm"};
dynamo.updateItem({
TableName:'TableName',
Key:{"BucketName":"abcdefg" },
UpdateExpression : "SET #attrName = list_append(#attrName, :attrValue)",
ExpressionAttributeNames : {
"#attrName" : "ImageLists"
},
ExpressionAttributeValues : {
':attrValue' : [item]
}
},function(err, data) {
if (err)
console.log(err);
else
console.log(data)
});

Boosting specific field value in Elastic search

Hi I need to boost the documents based on the on a particular value of a field.. My documents contains a field called Region.. Based on the value present in the region i need to boost my documents..
These are my documents
{
"title":"INOX: Malleshwaram - Mantri Square",
"region":"Bangalore"
}
{
"title":"INOX: Bund Garden Road",
"region":"Pune"
}
{
"title":"INOX: Glomax Mall, Kharghar",
"region":"Mumbai"
}
I have tried to use rescore query in my query which look like this
"rescore" : {
"query" : {
"score_mode":"total",
"query_weight" : 2.5,
"rescore_query_weight" : 0.5,
"rescore_query" : {
"match" : {
"region" : {
"query" : "mumbai",
"slop" : 2
}
}
}
}
}
}
But its not working properly as required..Is there any way to solve this?..
Thanks in advance!
Why rescoring, all you need is boosting. Based on the query type you are using, boosting is possible in
"query_string": {
"fields":["region^56"],
"use_dis_max" : true,
"query": "mumbai"
}
where ^56 is the boosting value.
You can also use as mentioned here http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
If you are using the bool query you can use boost like this to boost all queries
{
"bool" : {
"must" : {
"term" : { "region" : "mumbai" }
},
"boost" : 25.0
}
}

Resources