You have to understand the concept of static in Java.
A static method is a method that belongs to a class but does not belong to an instance of that class and this method can be called without the instance or object of that class.
Here you are accessing non-static method staticly.
public static void iEnterUsername(){
testIds.username.sendKeys("username");
}
Also, you are using PageFactory, so you need to use PageFactory. initElements()
static method which takes the driver instance of the given class and the class type, and returns a Page Object with its fields fully initialized.
Solution:
Using Static Approach: Bad Approach Not Recommended
You have to create a constructor and pass the driver instance to it, also initializing PageFactory.initElements(driver, this);
public Class testIds{
WebDriver driver;
public testIds (WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
}
@FindBy (id="username")
public static WebElement username;
}
In Test Class:
public static void iEnterUsername(){
testIds t = testIds(driver);
testIds.username.sendKeys("username");
}
Other Solution: Standard and Correct Approach
public Class testIds{
WebDriver driver;
public testIds (WebDriver driver){
this.driver = driver;
PageFactory.initElements(driver, this);
}
@FindBy (id="username")
public WebElement username;
public WebElement getUserName(){
return username;
}
}
Test Class:
public static void iEnterUsername(){
testIds t = testIds(driver);
testIds.getUserName().sendKeys("username");
}