Protractor - How to print Parameter itself using console.log - protractor

I am trying to print the Parameter itself on console. my sample codes are like this:
it('should print the parameter value', async function(){
expect (PO.printParameterandDoSomethingElse(myElement1)).toBe(true);
}
the Page object is :
this.printParameterandDoSomethingElse = async function(ele){
console.log(ele)
//do something
//do something else
//return output
}
I was hoping to get "MyElement1" printed , but, in this code the console is printing "[object Object]" instead of the parameter itself (MyElement1). I found a discussion in the github thread where another user had the same problem but I could not find her SO thread. Is there a way to achieve this?

Related

Can you return a variable out of a listener in dart?

I am struggling to find a solution to proceed with my program when a listener completes.
So my main goal is it to return a queryParameter of the DeepLink that leads back to my app. I already found out how to get the params with uni_links :
String function(){
linkStream.listen((String? link) async {
if (link!.startsWith(redirectUri)) {
param = Uri.parse(link).queryParameters['code'].toString();
print(param);
}
});
}
But now I want to return param instead of just printing it into the console. The problem is, because the return type of a listener is Future<void>, I am not able to just return the String without some kind of a workaround.
Is there a way to solve this?

protractor browser.executescript does not return a value

I'm trying to run the following scripts in Protractor
browser.executeScript("return window.localStorage.getItem('access_token');").then((accessToken) => {
console.log("AccessToken Obtained ", accessToken);
});
However the code never goes into the .then section. It just gets blocked. I tried executeAsyncScript and still the same result.
I went through a lot of online examples and I think this should work, however not sure whats going wrong here.
Could you try this one:
function getAccessToken() {
return window.localStorage.getItem('access_token');
}
browser.executeScript(getAccessToken).then((accessToken) => {
console.log("AccessToken Obtained ", accessToken);
});

TypeError seneca indexof if not a function during respond

I have written a simple action which connects to mongo db using seneca-mongo store module, execute a list query and get the results. I can see that the query was successful and the correct results were fetched. When I try to send these results back to the client, the respond call errors out with following message and stack trace.
ERROR act root$ OUT cmd:getparams,role:diff 11 {cmd:getparams,role:diff,payload:{id:scalaScan}} ENTRY (dqk22) - seneca: Action cmd:getparams,role:diff callback threw: k.indexOf is not a function. act_callback {message:k.indexOf is not a function,pattern:cmd:getparams,role:diff,instance:Seneca/0.7.2/d0twcki9cmxg/1485517 TypeError: k.indexOf is not a function
at /scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:851:13
at Function.forEach (/scratch/DiffAnalyzer/node_modules/lodash/dist/lodash.js:3298:15)
at Object.defaultmodify [as modify] (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:850:7)
at respond (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:654:22)
at Seneca.<anonymous> (/scratch/DiffAnalyzer/node_modules/seneca/node_modules/seneca-web/web.js:401:7)
at act_done (/scratch/DiffAnalyzer/node_modules/seneca/seneca.js:1554:16)
at /scratch/DiffAnalyzer/node_modules/gate-executor/gate-executor.js:127:20
at Seneca.<anonymous> (/scratch/DiffAnalyzer/analyze.js:613:5)
at act_done (/scratch/DiffAnalyzer/node_modules/seneca/seneca.js:1554:16)
at /scratch/DiffAnalyzer/node_modules/gate-executor/gate-executor.js:127:20
at /scratch/DiffAnalyzer/node_modules/seneca-mongo-store/mongo-store.js:329:21
at /scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:271:33
at /scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:778:35
at Cursor.close (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:1009:5)
at Cursor.nextObject (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:778:17)
at Cursor.each (/scratch/DiffAnalyzer/node_modules/mongodb/lib/mongodb/cursor.js:264:12)
The action that I have written is
seneca.add("role:diff,cmd:getparams", function(msg, respond) {
seneca.ready(function() {
var collection = seneca.make$("paramStore");
var f = msg.payload;
seneca.log.info("Filter", f);
collection.list$(f, function(err, ob) {
if (err) {
seneca.log.error(err);
respond(err);
} else {
seneca.log.info("Result", ob);
respond(null, ob);
}
});
});
});
The same piece of code was working and now I am getting this error. Not sure what changed. Any help/suggestions are greatly appreciated.
The issue I was facing was because of this bit of code in the module's js file
if( _.isObject( result.out ) ) {
_.each(result.out,function(v,k){
if(~k.indexOf('$') && 'http$' !== k) {
delete result.out[k]
}
})
The _.each function is meant to parse a JSON object, where in my case the out was actually a JSON array. Wrapping the array into an object resolved it.

How can I manually trigger the success callback function that is part of a config object?

Y.jsonp(
url, {
on: {
success: function(res) {
displaySuccess();
},
failure: function(res) {
}
},
context: this
});
I am trying to unit test the above jsonp call with different sets of data. I have tried to use yieldTo, but it looks like it expects "success" callback as an argument to the function. How can I trigger the success callback when it is part of a config object like above?
displaySuccess = sinon.spy();
sinon.stub(Y, "jsonp").yieldsTo("success", [1, 2, 3]);
//In the test call a function which calls Y.jsonp
assert(displaySuccess.called); //Fails
According to the docs, the correct solution would be something like (quite close to what you wrote) :
"test should fake successful jsonp request": function () {
sinon.stub(Y, "jsonp").yieldsTo("success", [1, 2, 3]);
Y.jsonp({
on: {
success: customSuccessHandler
}
});
}
Did you also wrap that into a function for the object ("test should fake successful jsonp request") ?Edit : OK, I saw your edit.
Also, try to print something in the success function, to see if it actually gets called or if the problem is elsewhere...
Maybe you have to return something (bool ?) in the function, by the way.

titanium - get the facebook user name?

Using titanium, does anybody have some simple instructions to get the user's facebook name, once signed into facebook?
you don't need to do any of this, the username is provided in the data response after the login is done.
Look at the appcelerator documentation
I haven't tested the code but you can try this:
var fbuid = Titanium.Facebook.uid; //this would be the logged user's facebook uid
function fQuery() //this function exec the fql query
{
var myQuery = "SELECT name FROM user WHERE uid = "+fbuid;
var data = [];
Titanium.Facebook.request('fql.query', {query: myQuery}, function(x)
{
var results = JSON.parse(x.result);
var username = results[0].name; //user's fb name
});
};
Ah, here is how you do it:
function getFacebookInfo(){
Titanium.Facebook.requestWithGraphPath('me', {}, 'GET', function(e){
if (e.success){
var jsonObject = JSON.parse(e.result);
//do something here with these values. They cannot be passed out of this
//function call... this is an asynchronous call
//that is, do this:
saveToDb(jsonObject.first_name);
} else {
//some sort of error message here i guess
}
});
};
Finally, along with name and username, check out the facebook page for the other variables you can get -
http://developers.facebook.com/docs/reference/api/
FINALLY: be aware that this is a callback, and titanium won't actually wait for this call to finish. That is, any variable declared to hold the results the returned after the requestWithGraphPAth will immediately return, and as a result almost always be empty.
I guess you could make a nifty loop that just... loops until some variable is set to false. And you'd set the variable to false in the callback... but that seems dodgy.
Just make your call back do everything else, that is, save to the db etc etc
If you do go the route of calling Ti.Facebook.authorise() to log in the user, remember to define
Ti.Facebook.addEventListener('login',function(e){
if (e.success){
...
...
} else if (e.error){ } else if (e.cancel) { }
}
before the call. And then, in the success bit, you can make a requestWithGraphPath call and so on. I just save all the details to the database and retrieve them each time after that, works fine for me!