Missing method Class Text_feild .getContents - watir

I am trying to use the .getContents method for Watir, but it says that the method does not exist. So i tried to update Watir, but i already have the latest version.
This is the line of code i was trying to use
Provence = e.frame(:name => "content").frame(:name =>
"main").text_field(:name => "txtLocDesc").getContents
And then get and method missing error.

Use #value method instead for getting value attribute for input field:
e.frame(:name => "content").frame(:name => "main").text_field(:name => "txtLocDesc").value

Why do you think getContents will return text field value? I do not see that method in watir-classic or watir-webdriver gem API.

Related

Jest error with <Trans>: You forgot to export your component from the file it's defined in, or you might have mixed up default and named imports

Error: Uncaught [Error: Element type is invalid: expected a string
(for built-in components) or a class/function (for composite
components) but got: undefined. You likely forgot to export your
component from the file it's defined in, or you might have mixed up
default and named imports.
This is the error I was getting while running test in jest. React component which is being tested uses <Trans> from react-i18next. When I comment that portion of code, test were working as expected.
The error shown is very very very miss leading.
In my case it was missing mock for <Trans>. While I had mock for react-i18next, but since I had many components to cover with tests, and some of them were using <Trans> and some of them not, I copy/paste test files but totally forgot to check about mock. It took me few hours to notice it, after I replaced <Trans> to text like <Typography> from material-ui...
jest.mock('react-i18next', () => ({
withTranslation: () => (Component: any) => {
Component.defaultProps = {...Component.defaultProps, t: (children: any) => children};
return Component;
},
Trans: ({children}: any) => children, // this line was missing (() => jest.fn() might also work)
}));
Hope it will save some time for some of you :)
I faced the same issue, in order to resolve the issue I mocked the Trans component like this
jest.mock("react-i18next", () => ({
Trans: ({ i18nKey }: { i18nKey: string }) => i18nKey,
}));
Instead of passing the node, we can simply pass the i18nKey.
In my case, I am only checking the key value. Hope it helps!

Object class couldn't be converted to string Laravel 5

When I return the request of my controller, I get:
{"employees":"3","reason":"common
reason","request":"5000","ded_per_pay":"500","months_to_pay":"2","date_issued":"2018-01-31"}
And in my create function, I get this error:
Object of class Symfony\Component\HttpFoundation\ParameterBag could not be converted to string
Here's my code:
CashAdvance::create([
'emp_id' => $request->employees,
'reason' => $request->reason,
'request' => $request->request,
'ded_per_pay' => $request->ded_per_pay,
'date_issued' => $request->date_issued,
'months_to_pay' => $request->months_to_pay
]);
What seems to be causing the problem??
This is really interesting. I've had a look in the API docs and it appears that the Request object has a parameter request. Which means that when you are calling $request->request, you are getting the parameter bag from your $request.
To get around this, you can use something like:
$myRequest = $request->input('request');
But I would heavily advise that instead you rename request to something that won't confuse yourself/other devs later in the project, and to keep these special named variables reserved for what they actually mean.

Using string.Split() in AutoMapper issue

I have an ASP .Net core application. I am simply trying to have my AutoMapper configure to convert a string comma delimited into a list of strings as per this configuration:
configuration.CreateMap<Job, JobDto>()
.ForMember(dto => dto.Keywords, options => options.MapFrom(entity => entity.Keywords.Split(',').ToList()))
For some reason it does not get compiled and give me the following error:
An expression tree may not contain a call or invocation that uses
optional argument
I can't see why I am getting this error. I am pretty sure that I have done that in my other projects before without any such error.
As error says, Split function has an optional parameter. The full signature of it is as this (options is optional)
public string[] Split(string separator, StringSplitOptions options = StringSplitOptions.None)
As you are trying to use a function with default value inside an expression tree, it gives you the error.
To Fix it, easy, just pass on optional parameters by yourself. ( StringSplitOptions.None )
So, simply change it to this:
entity.Keywords.Split(',' , StringSplitOptions.None).ToList()
This is completely true.
Error is raised because expression tree being created is about to contain some more complex logic, like .Split(',').ToList(), which is not an accessible property or method, only top-level reflected object properties and methods are supported (like in class MemberInfo).
Property chaining, deep-calls (.obj1property.obj2property), extension methods are not supported by the expression trees, like in this .ToList() call.
My solution was like this:
// Execute a custom function to the source and/or destination types after member mapping
configuration.CreateMap<Job, JobDto>()
.AfterMap((dto,jobDto)=>jobDto.Keywords = dto.Keywords.Split(',').ToList());
I had the same problem. I do not know if it is an issue or not. Anyway, I found a workaround.
CreateMap<Category, GetCategoryRest>()
.ForMember(dest => dest.Words,
opt => opt.MapFrom(src => ToWordsList(src.Words)));
private static List<string> ToWordsList(string words)
{
return string.IsNullOrWhiteSpace(words) ? new List<string>() : words.Split(",").ToList();
}
It is guaranteed that AutoMapper has always a List. Still, I'm confused. In my Startup.cs I define that AutoMapper allows null values for list.
Mapper.Initialize(cfg => {
cfg.AllowNullCollections = true;
}
Category.Words is a string.
GetCategoryRest.Words is a List<string>
AutoMapper Version: 8.1.1,
AutoMapper.Microsoft.DependencyInjection: 6.1.1
Use .AfterMap
CreateMap<src, dto>()
.ForMember(src =>src.Categories,options=> options.Ignore())
.AfterMap((src, dto) => { dto.Categories.AddRange(src.Categories.Split(",").ToList()); })
.ReverseMap()
.ForMember(src => src.Categories, option => option.MapFrom(dto => string.Join(",", dto.Categories)));

Why doesn't react component work inside a loop?

I think that the problem's source is my environment. Is there any NodeJS package I need to install?
Inside a Loop and without loop.
You have to return elements inside your map function
this.props.users.map(user => {
// Here you can manipulate your data before using it
return <UserPreview user={user}/>
})
If you only have to return the component without manipulating the data you could simply remove the brackets and the return keyword
this.props.users.map(user => <UserPreview user={user}/>);
Replace curly braces with parenthesis () to make the map return something:
this.props.users.map(user => (
<UserPreview user={user}/>
))

ServiceStack Ormlite Select Expression

I am building a service using ServiceStack and using OrmLite to communicate with database. I found following example in ServiceStack OrmLite Documention:
db.Select<Author>(q => q.Earnings <= 50);
OR
db.Select<Author>(q => q.Name.StartsWith("A"));
I am trying it with my class User, but unable to find a overload for method "Select" which allows me to do mentioned stuff. In my case q is a linq expression not an instance/reference for generic class type (User in my case). Following is my code:
db.Select<User>(q => q.Where(x => x.LastName == "XYZ"));
and i want it to be like:
db.Select<User>(q => q.LastName == "XYZ");
Please let me know if that is an extension method which i am looking for and how can i use that?
The Type that gets selected is the table is looking at, e.g:
db.Select<Author>(...) //Author
db.Select<User>(...) //User
See the answers on this earlier question for selecting a subset of data with OrmLite.

Resources