Part 6a - Working With Multiple Data using DataTable with Custom class type

preview_player
Показать описание

#ExecuteAutomation #QA #Testing #Java #IntelliJ #Selenium
Please hit like and share your comments about the video !!!
Subscribe: ExecuteAutomation channel in Youtube !!!
Рекомендации по теме
Комментарии
Автор

First of all great tutorials, now some pointers: In Java there are naming conventions that prohibit naming your variables with Upper case, they should all be camel case: userName. Second you should always check what a function does before using it. The asList method creates instances of your inner class. If you don't create setter and getter methods, the names of the variables need to match the ones you put in the row. This is bad practice, because u want to have encapsulation, and you should never ever directly set a value to a class property.

azvlad
Автор

7:09. It does not have anything to do with uppercase or lowercase or getters or setters. The technical reason is that the column headers in the feature file should be the same as the fields in the POJO. That is why it worked when you changed both to "username" and "password" - not because they were lowercase but because the column header names and the field names matched. Check tableHint() from the official cucumber-jvm repo:


Also, fields and methods in Java are lowerCamelCase. Changing them to "username" and "password" was incidentally best practice. I personally prefer the POJOs in their own classes over nesting them within the stepdef class.

KatRollo
Автор

TLDR: use camelCase in fields because the converter looks for it and no need to uncapitalize the title in the gherkin table
The problem you mentioned is actually the following: the mapper for the title row to POJO fields seems to work counter intuitive and does only allow camelCase naming convention in the POJOs fields.
look at line 19 in CamelCaseStringConverter: splitted[0] =
So if you are using UserName in the gherkin table the converter looks for fieldname 'userName' thats all there is no getters needed no setters needed also no renaming of title row needed just first letter of variable has to be in lower case in POJO

xandorneun
Автор

hey kartik your cucumber video is very helpful plz share your knowledge. its just and awsm and specially its intellij IDE so its very helpful
Thanks

vidhibakaraniya
Автор

Make your User class's 'UserName' and 'Password' variables to private and add getters and setters to access them, that will resolve your issue. You don't have to rename it with different name to resolve. Cheers

shanakafernando
Автор

U have to use "this" keyword inside user class constructor

pvrameshreddy
Автор

this is because the variables are confused we need use this.UserName and this.Password it will resolve the issue.

sairajesh
Автор

You should use this. operator - I think it would solve your your problem, Am I right?

Ravv
Автор

even constructor also not required. if class contains properties. then cucumber can inject those values into properties automatically. but class properties names and table column names in feature file must be same.

javabava
Автор

Class can be something like:
public class User {
private String username;
private String password;

public User() {
}

public String getUserName() {
return username;
}

public void setUserName(String userName) {
username = userName;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
password = password;
}
}

and the calls in the step definition:

System.out.println("The username is " + user.getUserName());
System.out.println("The password is " + user.getPassword());

testingtrail
Автор

you have to differentiate local variable and instance variable by using this keyword i think it should work

arunm
Автор

Hi brother you are getting this problem beacuse in Java when we use POJO classes that time we have to write parameters in declaration section and in constructor in a specific way beacuse we are intitializing them.
This is rule
For direct initializing you have to use getter and setter.

sanatanthereality
Автор

Is this deprecated? I got: Can't convert DataTable to

luca-rwss
Автор

use this keyword in the class to denote the object variables. instead of class variables as it is in constructor

tejagirajala
Автор

Hi Sir, by following your code, I am getting this:
can't convert DataTable to List<Steps.LoginSteps$User>.
Any help ?

Fei-D
Автор

I think the converter is based on java reflexion api so without getters/setters and without respecting the java variables convention you get this error

eslemfelli
Автор

Can smb show example how to use DataTable with Nested class on cucumber 4.

like_a_B
Автор

In the User constructor, if I didn't use "this" my code there were turn to gray, and could not be executed, , , And after I add "this" operator, in the "User class" the data member's name of username and password were different with that in feature file, but they will pass the test. So I think it is not important that variable names must be match in these two parts

tinalu
Автор

Your Nested class Cannot be public. Make That class static.

thequizclassroom
Автор

if you not able to fetch username and password, In User Class create get and set to access the table as below
public String getLogin() {

return this.getLogin();
}

public void setLogin(String userName, String password)
{
this.userName = userName;
this.password = password;
}

iBoyTrade
visit shbcf.ru