Getting [object Object] instead of value in protractor getText() - protractor

I am trying expect the value like
var foo = element(by.name('salutId'));
expect(foo.getText()).toEqual('MS');
console.log(foo); -- shows like [object Object]
Failed: No element found using locator: By(css selector, *[name="salutId"])

.getText() returns a promise. Promise is on object. Thus what you see is expected
In order to resolve a promise and get the value, you should use either await or .then
While first syntax is recommended, I'll show you an example with the second
foo.getText().then(value => {
console.log(value)
expect(value).toEqual('MS');
)

Related

Flutter null safety: Error: A value must be explicitly returned from a non-void function

Future<void> saveEverything() {
_formKeyForDeposit.currentState?.save();
Navigator.of(this.context).pop(true);
return;
}
This^ is throwing the error:
A value must be explicitly returned from a non-void function.
I've tried returning void, I've tried return true, I've tried returning Future<void>, I've tried returning the Navigator.pop line.
There is an answer on Stackoverflow, but that doesn't work with enforced null safety, this function wants something returned despite being void. I don't understand it.
It won't compile, I'd love some clarity on what drives the issue, and a solution.
As far as I can see none of the called functions are async, so there is nothing you could await. This means that your function isn't asynchronous either and there is no need to use Future as a return type. void should work fine:
void saveEverything() {
_formKeyForDeposit.currentState?.save();
Navigator.of(this.context).pop(true);
}
Edit: To specifically answer:
this function wants something returned despite being void
The return type isn't void, it is a Future with a generic type of void . Future is a normal class and thus your method expects an object of type Future to be returned. The void here is defining what type the value of a successfully resolved Future should have.
like this
Future<void> saveEverything() async {
_formKeyForDeposit.currentState?.save();
Navigator.of(this.context).pop(true);
}

dart gRPC: what the meaning of the function?

I'm new in flutter(dart) gRPC. I'm learing the tutorial given by https://grpc.io/docs/languages/dart/basics/. But I got confused about the dart syntax in this function.
Future<Feature> getFeature(grpc.ServiceCall call, Point request) async {
return featuresDb.firstWhere((f) => f.location == request,
orElse: () => Feature()..location = request);
}
Actually, I don't understand what argument f means and why there is an orElse. I have found => means arrow function and it can be simply understood as return sentence, but I can't say I figure it out toally. Any explanation would be appreciated.
firstWhere method takes a Predicate. A Predicate is just a function that takes in an object, and returns true or false. So basically it's saying "give me the first object from this list where the function I'm giving you returns true. The orElse is an optional, named parameter that says, if you've gotten to the end of the list and not a single object returned true when passed through the function I just supplied, then execute this function as a last resort and return whatever value it produces. You can think of a Predicate like a filter. It takes an object and returns true if it should pass through the filter, or false if it should not pass through the filter. firstWhere basically goes through each element checking to see if it passes through the filter, and the first time something does, it returns that element. If nothing makes it through the filter, it uses the orElse producer function to generate some value to return, since nothing made it through on it's own.
(f) => f.location == request is a function that returns true or false based on it's argument - it's a Predicate
() => Feature()..location = request is a Producer. A function that has no argument, but produces a value. In this case, a value that is equal to a new Feature with a location value equal to request. An assignment evaluates to the value that was assigned. The cascade .. ensures that the Feature will be returned, instead of the Point object, request.
So basically you can think of it like this:
list.giveMeTheFirstObjectWhere(thisFunctionReturnsTrue, orElse: giveMeTheValueThisFunctionProvidesIfNoneOfTheElementsReturnedTrueUsingTheOtherFunction)
So the purpose of this code seems to be, checking if a Feature already exists, and if it does, it returns the first such Feature. If it doesn't exist, it creates a new Feature and returns it (however, this newly created one isn't automatically added to the list/db)

Error when trying to get single item from element.all in Protractor

I have the following test code (a simplified example):
e = element(by.id('element-id'));
it('description', function(){
e.all(by.tagName('my-directive')).then(function(items){
expect(items.count()).toEqual(3); //error
expect(items.length).toEqual(3); //ok
expect(items.get(0).getAttribute('my-attr')).toEqual('1'); //error
});
});
This is the HTML:
<div id="element-id">
<my-directive my-attr="1"></my-directive>
<my-directive my-attr="0"></my-directive>
<my-directive my-attr="0"></my-directive>
</div>
When I run this test I get the following error:
TypeError: undefined is not a function
I stripped it down and found out that the error is from the get() function and the count() function. I have read about the functions in the Protractor API and used them the same way as the example on the site, so I don't understand why it does not work for me.
Does anyone know what I'm doing wrong?
I have also tried this (included 'element'):
e.element.all(by.tagName('my-directive')).then(function(items){...})
But that gave an error event without the get() function.
items in this case is just an ordinary array. You get
TypeError: undefined is not a function
because there isn't any function on the Array.prototype called count.
count() and get() can only be called on ElementFinderArrays, which is a Protractor specific object: http://angular.github.io/protractor/#/api?view=ElementArrayFinder
If you want to get the length and one of the elements' attribute, this will work:
e.all(by.tagName('my-directive')).then(function(items){
expect(items.length).toEqual(3);
expect(items[0].getAttribute('my-attr')).toEqual('1');
});
or like this:
expect(e.all(by.tagName('my-directive')).count()).toEqual(3);
expect(e.all(by.tagName('my-directive')).get(0).getAttribute('my-attr')).toEqual(1);

undefine is not a function jquery auto complete

When trying to handle the data returned from autocomplete result set this always happens.
Any clue on this issue?
$("#search").autocomplete(suggest_url,{
max:100,
delay:10,
selectFirst: false
}).result(function(event, data, formatted)
{
do_search(true);
});
Thanks
Such error happens only if you are trying to call a function, but it is not a function.
x = 123;
x(); // produces «number is not a function
y = undefined;
y(); // produces exactly «TypeError: undefined is not a function»
«Uncaught type error» indicates that exception caused inside the lambla-style function. Thus, I hope, it is something wrong with do_searh identifier. Try to alert(do_searh) before calling it.
>>> UPDATE
This questions refers to another:
jQuery UI Autocomplete .result is not a function woes

Extjs form - findField is not defined

I am selecting a form in Extjs as the following:
var form = Ext.getCmp(mainTabsId).getActiveTab().down().getForm("add-form");
//I am getting here the correct id.
console.log(form.id);
But when I am trying to find a field inside like that I am getting the following error:
form.findField("Address").getValue();
Uncaught TypeError: Object [object Object] has no method 'findField'
this is the console.log of form http://pastebin.com/EuVizyCZ
findField is a method of Ext.form.Basic, not Ext.form.Panel... So you have to do:
form.getForm() // get the BasicForm ref
.findField('Address')
.getValue();
Update
By guessing from your code, I would try:
// supposing add-form is the id or itemId of a FormPanel
Ext.getCmp(mainTabsId).getActiveTab().down('#add-form').getForm()