0

I am using Faker class to create random values in Selenium Webdriver automation. Below is the class for your reference.

public class NewUserFormAction {

    Faker faker = new Faker();
    public  String name = faker.name().firstName();
    public  String Surname = faker.name().lastName();

    public static void Execute(WebDriver driver,List<HashMap<String,String>> map) throws Exception{

        WebDriverWait wait = new WebDriverWait(driver,10);
        wait.until(ExpectedConditions.elementToBeClickable(NewUserFormPage.gender));
        NewUserFormPage.gender.click();
        NewUserFormPage.customer_firstname.sendKeys(name);
        NewUserFormPage.customer_lastname.sendKeys(Surname);

    }
}

when I am executing this code I am getting exception at compilation at below steps with error can not make static method reference to non static data member.

NewUserFormPage.customer_firstname.sendKeys(name);
NewUserFormPage.customer_lastname.sendKeys(Surname);

Here I understand the faker instance is create on public class which is non static and it is being called in Execute method which is static. Can you please help me how to solve this issue ?

Marit
  • 2,399
  • 18
  • 27
Hemant Varhekar
  • 42
  • 1
  • 1
  • 11
  • your execute method is static. you are trying to use instance variables (name and Surname) in it. That causes the problem. You would do well to first learn the basics, and some basics of the general naming conventions, before trying to switch to more advanced material – Stultuske Mar 05 '20 at 11:33
  • Hello, Thanks for your reply. Here as you can see I am initializing faker class by: Faker faker = new Faker() and then using the instance further in methods. Can you please suggest any better approach to resolve this issue ? that is I am more interested in... – Hemant Varhekar Mar 05 '20 at 11:39
  • a better approach? Learn the basics. again: you are trying to use INSTANCE VARIABLES of your NewUserFormAction class in a STATIC method. It makes zero sense to try and write code like this, if you don't understand the concepts of static and instance well enough to see why this fails. – Stultuske Mar 05 '20 at 12:26

0 Answers0