I'm automating a simple login test project with cucumber + maven + testng. I can't write username and password in login page I can't login https://www.lambdatest.com/automation-demos/ website. Where is my mistake? What am I doing wrong.

   public class loginPage extends TestBase {
    public loginPage() {
        PageFactory.initElements(driver, this);
    @FindBy(how = How.XPATH, using ="//input[@id='username']")
    WebElement uss;

    @FindBy(how = How.XPATH, using ="//input[@id='password']")
    WebElement pss;

    @FindBy(how = How.CSS, using=".applynow")
    WebElement buttonLogin;
    public void enter_username(String user) {

    public void enter_password(String pass) {
    public void enter_buttonLogin() {

public class loginPageSteps extends TestBase{
    loginPage LoginPage;
    @Given("I open the login page")
    public void i_open_the_login_page() throws InterruptedException {

    @When("^I fill username \"([^\"]*)\" and password \"([^\"]*)\"$")
    public void i_fill_username_and_password(String username, String password) {
    @Then("I should see the success login message \\\"([^\\\"]*)\\\"")
    public void i_should_see_the_success_login_message(String string) {
        // Write code here that turns the phrase above into concrete actions
        throw new cucumber.api.PendingException();


My TestBase Code:

public class TestBase {
public static WebDriver driver;
public static WebDriverWait wait;
public static Properties properties;
public static String currentDirectory = System.getProperty("user.dir");

public TestBase() {

    properties = new Properties();
    try {
        properties.load(new FileInputStream(currentDirectory + "//src//test//resources//config.properties"));
    } catch (FileNotFoundException e) {
        System.out.println("File Not Found Exception");
    } catch (IOException e) {
        System.out.println("IO Exception");

public static void initialization() {
    String browserName = properties.getProperty("browser");
    System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
    if (browserName.equals("chrome")) {
        // driver = new ChromeDriver();
        ChromeOptions optns = new ChromeOptions();
        driver = new ChromeDriver(optns);
        System.out.println("Browser is set to Chrome");
    } else if (browserName.equals("firefox")) {
        driver = new FirefoxDriver();
        System.out.println("Browser is set to Firefox");
    } else {
        driver = new InternetExplorerDriver();
        System.out.println("Browser is set to IE");
    // driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
    // driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT, TimeUnit.SECONDS);

public static void closeBrowser() {


You should define an instance of login page first. In loginPageSteps class and in i_fill_username_and_password method, first add this line:

LoginPage = new loginPage();

then call enter_username and all other methods you write.

Note: Actually you should read more about Naming convention in java in order to help you make your application more understandable. You should name a class with capital letter and the instance of the class with lower letter. In your case it would be better to define LoginPage as the class name and loginPage as the instance of that class. Although it's not mandatory but makes your application easy to read.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.