I know how to send click events with nightwatch:
browser.click('#my-control');
But I have been unable to find a way to send key events. How is this done in nightwatch?
You can try the following way to press any key in nightwatch.js; I am pressing T and it is working superb!
client.keys("t", function(done) {
client.pause(5000);
client.expect.element('#carousel_container').to.have.css('display').which.equals('block');
});
We are using the above way because nightwatch.js Keys does not have any alphabet command in its array, I have consoled and I haven't found any alphabet to press it.
Keys:
{ NULL: '',
CANCEL: '',
HELP: '',
BACK_SPACE: '',
TAB: '',
CLEAR: '',
RETURN: '',
ENTER: '',
SHIFT: '',
CONTROL: '',
ALT: '',
PAUSE: '',
ESCAPE: '',
SPACE: '',
PAGEUP: '',
PAGEDOWN: '',
END: '',
HOME: '',
LEFT_ARROW: '',
UP_ARROW: '',
RIGHT_ARROW: '',
DOWN_ARROW: '',
ARROW_LEFT: '',
ARROW_UP: '',
ARROW_RIGHT: '',
ARROW_DOWN: '',
INSERT: '',
DELETE: '',
SEMICOLON: '',
EQUALS: '',
NUMPAD0: '',
NUMPAD1: '',
NUMPAD2: '',
NUMPAD3: '',
NUMPAD4: '',
NUMPAD5: '',
NUMPAD6: '',
NUMPAD7: '',
NUMPAD8: '',
NUMPAD9: '',
MULTIPLY: '',
ADD: '',
SEPARATOR: '',
SUBTRACT: '',
DECIMAL: '',
DIVIDE: '',
F1: '',
F2: '',
F3: '',
F4: '',
F5: '',
F6: '',
F7: '',
F8: '',
F9: '',
F10: '',
F11: '',
F12: '',
COMMAND: '',
META: ''
},
You can press any key in above array easily like "client.keys(client.Keys.ENTER);".
if you entend to send a simple key stroke, you can do it directly through the following
browser.keys('j')
this will simulate the pressing on the J key
but according to http://nightwatchjs.org/api#setValue
this should also do the job
demoTest = function (browser) {
browser.setValue('input[type=text]', ['this does the job', browser.Keys.ENTER]);
};
So if you need a press a simple character, send it as string, otherwise use one of the special character in the key.json in the nightwatch package
{
"NULL" : "\uE000",
"CANCEL" : "\uE001",
"HELP" : "\uE002",
"BACK_SPACE" : "\uE003",
"TAB" : "\uE004",
"CLEAR" : "\uE005",
"RETURN" : "\uE006",
"ENTER" : "\uE007",
"SHIFT" : "\uE008",
"CONTROL" : "\uE009",
"ALT" : "\uE00A",
"PAUSE" : "\uE00B",
"ESCAPE" : "\uE00C",
"SPACE" : "\uE00D",
"PAGEUP" : "\uE00E",
"PAGEDOWN" : "\uE00F",
"END" : "\uE010",
"HOME" : "\uE011",
"LEFT_ARROW" : "\uE012",
"UP_ARROW" : "\uE013",
"RIGHT_ARROW" : "\uE014",
"DOWN_ARROW" : "\uE015",
"ARROW_LEFT" : "\uE012",
"ARROW_UP" : "\uE013",
"ARROW_RIGHT" : "\uE014",
"ARROW_DOWN" : "\uE015",
"INSERT" : "\uE016",
"DELETE" : "\uE017",
"SEMICOLON" : "\uE018",
"EQUALS" : "\uE019",
"NUMPAD0" : "\uE01A",
"NUMPAD1" : "\uE01B",
"NUMPAD2" : "\uE01C",
"NUMPAD3" : "\uE01D",
"NUMPAD4" : "\uE01E",
"NUMPAD5" : "\uE01F",
"NUMPAD6" : "\uE020",
"NUMPAD7" : "\uE021",
"NUMPAD8" : "\uE022",
"NUMPAD9" : "\uE023",
"MULTIPLY" : "\uE024",
"ADD" : "\uE025",
"SEPARATOR" : "\uE026",
"SUBTRACT" : "\uE027",
"DECIMAL" : "\uE028",
"DIVIDE" : "\uE029",
"F1" : "\uE031",
"F2" : "\uE032",
"F3" : "\uE033",
"F4" : "\uE034",
"F5" : "\uE035",
"F6" : "\uE036",
"F7" : "\uE037",
"F8" : "\uE038",
"F9" : "\uE039",
"F10" : "\uE03A",
"F11" : "\uE03B",
"F12" : "\uE03C",
"COMMAND" : "\uE03D",
"META" : "\uE03D"
}
A simple way of doing this is to use .keys() method name and then to pass the key name you want to press.
For example: The below command will press the Down arrow key.
.keys(browser.Keys.ARROW_DOWN)
I think the keys method from Selenium protocol will be the one you need:
http://nightwatchjs.org/api#keys
You should pass the controller in sendKeys funtion.
Like This.
elements: {
textBoxSearch: {
selector: '.nav-search-input'
},
.sendKeys('#textBoxSearch',client.Keys.ENTER);
Related
Thank you for first.
MongoDB Version:4.2.11
I have a piece of data like this:
{
"name":...,
...
"administration" : [
{"name":...,"job":...},
{"name":...,"job":...}
],
"shareholder" : [
{"name":...,"proportion":...},
{"name":...,"proportion":...},
]
}
I want to match some specified data through regular expressions:
For a example:
db.collection.aggregate([
{"$match" :
{
"$or" :
[
{"name" : {"$regex": "Keyword"}}
{"administration.name": {"$regex": "Keyword"}},
{"shareholder.name": {"$regex": "Keyword"}},
]
}
},
])
I want to set a flag when the $or operator successfully matches any condition, which is represented by a custom field, for example:{"name" : {"$regex": "Keyword"}}Execute on success:
{"$project" :
{
"_id":false,
"name" : true,
"__regex_type__" : "name"
}
},
{"administration.name" : {"$regex": "Keyword"}}Execute on success:"__regex_type__" : "administration.name"
I try do this:
{"$project" :
{
"_id":false,
"name" : true,
"__regex_type__" :
{
"$switch":
{
"branches":
[
{"case": {"$regexMatch":{"input":"$name","regex": "Keyword"}},"then" : "name"},
{"case": {"$regexMatch":{"input":"$administration.name","regex": "Keyword"}},"then" : "administration.name"},
{"case": {"$regexMatch":{"input":"$shareholder.name","regex": "Keyword"}},"then" : "shareholder.name"},
],
"default" : "Other matches"
}
}
}
},
But $regexMatch cannot match the array,I tried to use $unwind again, but returned the number of many array members, which did not meet my starting point.
I want to implement the same function as mysql this SQL statement in mongodb, like this:
SELECT name,administration.name,shareholder.name,(
CASE
WHEN name REGEXP("Keyword") THEN "name"
WHEN administration.name REGEXP("Keyword") THEN "administration.name"
WHEN shareholder.name REGEXP("Keyword") THEN "shareholder.name"
END
)AS __regex_type__ FROM db.mytable WHERE
name REGEXP("Keyword") OR
shareholder.name REGEXP("Keyword") OR
administration.name REGEXP("Keyword");
Maybe this method is stupid, but I don’t have a better solution.
If you have a better solution, I would appreciate it!!!
Thank you!!!
Since $regexMatch does not handle arrays, use $filter to filter individual array elements with $regexMatch, then use $size to see how many elements matched.
[{"$match"=>{"$or"=>[{"a"=>"test"}, {"arr.a"=>"test"}]}},
{"$project"=>
{"a"=>1,
"arr"=>1,
"src"=>
{"$switch"=>
{"branches"=>
[{"case"=>{"$regexMatch"=>{"input"=>"$a", "regex"=>"test"}},
"then"=>"a"},
{"case"=>
{"$gte"=>
[{"$size"=>
{"$filter"=>
{"input"=>"$arr.a",
"cond"=>
{"$regexMatch"=>{"input"=>"$$this", "regex"=>"test"}}}}},
1]},
"then"=>"arr.a"}],
"default"=>"def"}}}}]
[{"_id"=>BSON::ObjectId('5ffb2df748966813f82f15ad'), "a"=>"test", "src"=>"a"},
{"_id"=>BSON::ObjectId('5ffb2df748966813f82f15ae'),
"arr"=>[{"a"=>"test"}],
"src"=>"arr.a"}]
I am trying to make a Mongodb query in Mule with the $in function, but mule says Invalid input '$', expected Namespace or NameIdentifier
have a collection that stores user authorization
{
"_id" : ObjectId("584a0dea073d4c3e976140a9"),
"partnerDataAccess" : [
{
"factoryID" : "Fac-1",
"partnerID" : "Part-1"
}
],
"userID" : "z12",
}
{
"_id" : ObjectId("584f5eba073d4c3e976140ab"),
"partnerDataAccess" : [
{
"factoryID" : "Fac-1",
"partnerID" : "Part-2"
},
{
"factoryID" : "Fac-2",
"partnerID" : "Part-2"
}
],
"userID" : "w12",
}
the flow will submit a userID and partnerID and query the database to see if authorization exist
when I query from Robo 3T, I write queries like this
e.g. user w12 and partner Part-2
db.getCollection('user').find({
userID:"w12", "partnerDataAccess.partnerID": {$in : ["Part-2", "ALL"]}
})
The $in was used because there is the "ALL" setting for admins
but while I try to put the find part into the Mongodb connector, Mule gives error during development and runtime
Hardcoded:
<mongo:find-one-document collectionName="user" doc:name="Find one document" doc:id="a03a6689-6b9d-473c-b8a6-3b8d1e989e38" config-ref="MongoDB_Config">
<mongo:find-query ><![CDATA[#[{
userID:"w12",
"partnerDataAccess.partnerID": {$in : ["Part-2", "ALL"]}
}]]]></mongo:find-query>
</mongo:find-one-document>
parametized
<mongo:find-one-document collectionName="user" doc:name="Find one document" doc:id="a03a6689-6b9d-473c-b8a6-3b8d1e989e38" config-ref="MongoDB_Config">
<mongo:find-query ><![CDATA[#[{
userID: payload.User,
"partnerDataAccess.partnerID": {$in : [ payload.partner, "ALL"]}
}]]]></mongo:find-query>
</mongo:find-one-document>
Error:
during development:
Invalid input '$', expected } or ~ or , (line 3, column 38):
Runtime:
Message : "Script '{
userID:"w12",
"partnerDataAccess.partnerID": {$in : ["Part-2", "ALL"]}
} ' has errors:
Invalid input '$', expected Namespace or NameIdentifier (line 3, column 38):
at 3 : 3" evaluating expression:
I have tried removing the $ or escaping the $ with backslash but it does not work
I know my query is not actually complex, welcome any help
seems to have found the correct way
><![CDATA[#[{
userID:"w12",
"partnerDataAccess.partnerID": {"\$in" : ["Part-2", "ALL"]}
}]]]>
My object is like
WL.AppProperty = {
AIR_ICON_16x16_PATH : "AIR_ICON_16x16_PATH",
AIR_ICON_128x128_PATH : "AIR_ICON_128x128_PATH",
DOWNLOAD_APP_LINK : "DOWNLOAD_APP_LINK",
ENVIRONMENT : "ENVIRONMENT",
APP_DISPLAY_NAME : "APP_DISPLAY_NAME",
APP_LOGIN_TYPE : "APP_LOGIN_TYPE",
APP_VERSION : "APP_VERSION",
HEIGHT : "HEIGHT",
IID : "IID",
LATEST_VERSION : "LATEST_VERSION",
LOGIN_DISPLAY_TYPE : "LOGIN_DISPLAY_TYPE",
LOGIN_REALM : "LOGIN_REALM",
MAIN_FILE_PATH : "MAIN_FILE_PATH",
SHOW_IN_TASKBAR : "SHOW_IN_TASKBAR",
THUMBNAIL_IMAGE_URL : "THUMBNAIL_IMAGE_URL",
WELCOME_PAGE_URL : "WELCOME_PAGE_URL",
WIDTH : "WIDTH",
WORKLIGHT_ROOT_URL : "WORKLIGHT_ROOT_URL",
APP_SERVICES_URL : "APP_SERVICES_URL",
WLCLIENT_TIMEOUT_IN_MILLIS : "WLCLIENT_TIMEOUT_IN_MILLIS" };
// Short alias:
WL.AppProp = WL.AppProperty;
Getting error at below line :
var reachabilityUrl =
WL.Client.getAppProperty(WL.AppProp.APP_SERVICES_URL) + "reach";
There is no such thing as WL.AppProp
There is no such property APP_SERVICES_URL available.
For available properties and correct API usage see the documentation for getAppProperty.
For example, how would you store the text of the following:
<div class="value">ABC</div>
<div class="value">123</div>
In the IDE I would have:
Command ::: Target : : : Value
storeText : : : ????? : : : Key1
storeText : : : ????? : : : Key2
I want to store the ABC as key1 and the 123 as Key2 so how do I make my target point to the correct element. Is there a way to index such as class=value[0] and class=value[1] to do this?
You can use xpath for the Target:
Command : : : Target : : : Value
storeText : : : //div[#class='value'][1] : : : Key1
storeText : : : //div[#class='value'][2] : : : Key2
The [n] is an index that will return the nth match.
Also you could use
storeText : : : //div[#class='value'][last()] : : : Key2
Please see following link for details
http://zvon.org/xxl/XPathTutorial/General/examples.html
If you have fire bug add-on of the Firefox installed you can do the following:
Right click on the element and click on inspect element with Firebug and select the div or element that you want,
Right click on it and then click on Copy CSS path
In the your selenium plugin Target type "css=" after that paste the css path
now when you use the echo command next and run the test you should see the result. in the log section
I had much success building my own little search with elasticsearch in the background. But there is one thing I couldn't find in the documentation.
I'm indexing the names of musicians and bands. There is one band called "The The" and due to the stop words list this band is never indexed.
I know I can ignore the stop words list completely but this is not what I want since the results searching for other bands like "the who" would explode.
So, is it possible to save "The The" in the index but not disabling the stop words at all?
You can use the synonym filter to convert The The into a single token eg thethe which won't be removed by the stopwords filter.
First, configure the analyzer:
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"settings" : {
"analysis" : {
"filter" : {
"syn" : {
"synonyms" : [
"the the => thethe"
],
"type" : "synonym"
}
},
"analyzer" : {
"syn" : {
"filter" : [
"lowercase",
"syn",
"stop"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}
}
'
Then test it with the string "The The The Who".
curl -XGET 'http://127.0.0.1:9200/test/_analyze?pretty=1&text=The+The+The+Who&analyzer=syn'
{
"tokens" : [
{
"end_offset" : 7,
"position" : 1,
"start_offset" : 0,
"type" : "SYNONYM",
"token" : "thethe"
},
{
"end_offset" : 15,
"position" : 3,
"start_offset" : 12,
"type" : "<ALPHANUM>",
"token" : "who"
}
]
}
"The The" has been tokenized as "the the", and "The Who" as "who" because the preceding "the" was removed by the stopwords filter.
To stop or not to stop
Which brings us back to whether we should include stopwords or not? You said:
I know I can ignore the stop words list completely
but this is not what I want since the results searching
for other bands like "the who" would explode.
What do you mean by that? Explode how? Index size? Performance?
Stopwords were originally introduced to improve search engine performance by removing common words which are likely to have little effect on the relevance of a query. However, we've come a long way since then. Our servers are capable of much more than they were back in the 80s.
Indexing stopwords won't have a huge impact on index size. For instance, to index the word the means adding a single term to the index. You already have thousands of terms - indexing the stopwords as well won't make much difference to size or to performance.
Actually, the bigger problem is that the is very common and thus will have a low impact on relevance, so a search for "The The concert Madrid" will prefer Madrid over the other terms.
This can be mitigated by using a shingle filter, which would result in these tokens:
['the the','the concert','concert madrid']
While the may be common, the the isn't and so will rank higher.
You wouldn't query the shingled field by itself, but you could combine a query against a field tokenized by the standard analyzer (without stopwords) with a query against the shingled field.
We can use a multi-field to analyze the text field in two different ways:
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"mappings" : {
"test" : {
"properties" : {
"text" : {
"fields" : {
"shingle" : {
"type" : "string",
"analyzer" : "shingle"
},
"text" : {
"type" : "string",
"analyzer" : "no_stop"
}
},
"type" : "multi_field"
}
}
}
},
"settings" : {
"analysis" : {
"analyzer" : {
"no_stop" : {
"stopwords" : "",
"type" : "standard"
},
"shingle" : {
"filter" : [
"standard",
"lowercase",
"shingle"
],
"type" : "custom",
"tokenizer" : "standard"
}
}
}
}
}
'
Then use a multi_match query to query both versions of the field, giving the shingled version more "boost"/relevance. In this example the text.shingle^2 means that we want to boost that field by 2:
curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1' -d '
{
"query" : {
"multi_match" : {
"fields" : [
"text",
"text.shingle^2"
],
"query" : "the the concert madrid"
}
}
}
'