0

Getting this Error : java.lang.IllegalArgumentException: Keys to send should be a not null CharSequence. How to resolve this issue?

POM design model used using TestNG Framework

Please find out the below code snippets for both the java classes I have added

The below code snippet is LoginPageTest Java Class

package com.crm.qa.testcases; 

import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.crm.qa.base.TestBase;
import com.crm.qa.pages.HomePage;
import com.crm.qa.pages.LoginPage;

public class LoginPageTest extends TestBase{

    LoginPage loginpage;
    HomePage homepage;

    public LoginPageTest() {
        super();
    }

    @BeforeMethod
    public void setup() {
        initialization();
        loginpage = new LoginPage();
    }

     @Test(priority=1)
     public void loginpagetitletest() {
     String title = loginpage.ValidatePageTitle();
    Assert.assertEquals(title, "Login");
    } 

    @Test(priority=2)
    public void loginTest()
    {
        homepage = loginpage.login(prop.getProperty("emailId"),prop.getProperty("password"));
    }

    @AfterMethod
    public void Teardown() {
        driver.quit();
    }

}

And the below snippet is LoginPage Java Class

package com.crm.qa.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import com.crm.qa.base.TestBase;

public class LoginPage extends TestBase {

    //Page Factory - object repository:

        @FindBy(id = "li_myaccount")
        WebElement myaccountbtn;

        //*[@id="li_myaccount"]/ul/li[1]/a

        @FindBy(xpath = "//a[contains(text(), 'login')]")
        WebElement loginbtn;

        @FindBy(name = "username")
        WebElement username;

        @FindBy(name = "password")
        WebElement password;

        @FindBy(xpath = "//*[@id='loginfrm']/button")
        WebElement lgnbtn;

        @FindBy(xpath = "//a[contains(text(), 'Sign Up')]")
        WebElement Signupbtn;

        //Initialize the Page Objects
    public LoginPage() {
        PageFactory.initElements(driver, this);
    }

    //Actions
    public String ValidatePageTitle() {
        return driver.getTitle();
    }


    public HomePage login(String un, String pwd) {

        username.sendKeys(un);
        password.sendKeys(pwd);
        myaccountbtn.click();
        loginbtn.click();

        return new HomePage();
        }

    } package com.crm.qa.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import com.crm.qa.base.TestBase;

public class LoginPage extends TestBase {

    //Page Factory - object repository:

        @FindBy(id = "li_myaccount")
        WebElement myaccountbtn;

        //*[@id="li_myaccount"]/ul/li[1]/a

        @FindBy(xpath = "//a[contains(text(), 'login')]")
        WebElement loginbtn;

        @FindBy(name = "username")
        WebElement username;

        @FindBy(name = "password")
        WebElement password;

        @FindBy(xpath = "//*[@id='loginfrm']/button")
        WebElement lgnbtn;

        @FindBy(xpath = "//a[contains(text(), 'Sign Up')]")
        WebElement Signupbtn;

        //Initialize the Page Objects
    public LoginPage() {
        PageFactory.initElements(driver, this);
    }

    //Actions
    public String ValidatePageTitle() {
        return driver.getTitle();
    }


    public HomePage login(String un, String pwd) {

        username.sendKeys(un);
        password.sendKeys(pwd);
        myaccountbtn.click();
        loginbtn.click();

    return new HomePage();
        }

    }`
3
  • 1
    Either prop.getProperty("emailId") or prop.getProperty("password") is null, by the looks of it. Commented Jul 27, 2019 at 10:16
  • 1
    "Keys to send should be a not null CharSequence"! Very self-explanatory, isn't it? Commented Jul 27, 2019 at 10:17
  • But I cross checked again everything seems good. Is there any other possible mistake Commented Jul 27, 2019 at 11:53

3 Answers 3

0

Hardcode the un and password.
If that works, means that whoever calls login() method, puts empty strings.

username.sendKeys("user1");
password.sendKeys("pass1");
Sign up to request clarification or add additional context in comments.

Comments

0

Check your config.properties file. It seems that the variable in the properties file is not correct.

Comments

0

Check that the parameter is defined in the config file and cross verify that the same parameter is define & used.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.