-1

It is possible to use a variable to set a value using Selenium - Cucumber?

In my Class.Java : I tried to create a private variable ( private String username = "x"; )

with Setter ( public void setUsername(String username).. )

But the value doesn't change when i use setUsername from another class.

MyClass myVariable = new MyClass ();
myVariable .setUsername("myUsername");
myVariable .setPassword("myPassword");

myVariable becomes "myUsername" but When " @Before " starts, the value is "x" even if I changed it.

The value of the variable must be dynamic and non-static for the purposes of the project. Can i use Config.properties to do this ? There is a way to solve this problem?

Thank you so much.

Yann
  • 1
  • Please include the Java code for the getter and setter. – Greg Burghardt Jul 02 '20 at 19:58
  • Hi Greg, thank you for the answer. I solved this problem using data from Config.properties file. I have another question for you: Can i start a cucumber test from another Java Project? I export my first Project (that contains MyClass.Java and MyClass.feature) but when i try to start MyClass.feature, it doesn't read MyClass.Java and advice me to add all the steps) – Yann Jul 03 '20 at 09:48

1 Answers1

0

"myUsername" is the literal string. If you want to pass the variable, it should be myVariable.setUsername(username); I guess from the code you provided.

Also, I if the space between myVariable and .setUsername is in your code it won't work.

ou_ryperd
  • 2,037
  • 2
  • 18
  • 23
  • Hi ou_ryperd, thank you for the answer. I solved this problem using data from Config.properties file. I have another question for you: Can i start a cucumber test from another Java Project? I export my first Project (that contains MyClass.Java and MyClass.feature) but when i try to start MyClass.feature, it doesn't read MyClass.Java and advice me to add all the steps) – Yann Jul 03 '20 at 09:52