How to resolve the "java.lang.nullpointerexception null value in entry url=null " in Selenium(POM)



  • 1.TestCommands.java

    public class TestCommands {
    public void click(By locator,WebDriver driver){
        try {
            WebElement element = driver.findElement(locator);
            element.click();            
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }       
    }
    public void type(By locator,WebDriver driver,String key){
        try {
            WebElement element = driver.findElement(locator);
            element.clear();
            element.sendKeys(key);          
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }       
    }
    public void open(String url,WebDriver driver) {
        try {
            driver.get(url);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }       
    }
    

    }

    2.LoginPage.java

    public class LoginPage extends TestCommands{
    //web elements
    public By userName(){
        return By.xpath("//input[@id='user-name']");
    }
    public By password(){
        return By.xpath("//input[@id='user-password']");
    }
    public By loginButton(){
        return By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='SIGN IN'])[1]/following::div[2]");
    }
    
    //Business functions
    public void openApplication(String url,WebDriver driver){
        open(url,driver);
    }
    public void loginToApplication(WebDriver driver,String userName,String password){
        type(userName(),driver,userName);
        type(password(),driver,password);
        click(loginButton(),driver);
    }
    

    }

    3.TC_LoginToTest.java

    public class TC_LoginToTest {
    WebDriver driver ;
    String baseUrl;
    LoginPage login = new LoginPage(); 
    
    @Parameters("browser")
    @BeforeMethod
    public void beforeMethod(String browser) {
    
        if (browser.equals("firefox")) {
            System.setProperty("webdriver.gecko.driver", "drivers\\geckodriver.exe");
            driver = new FirefoxDriver();
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        } else if (browser.equals("chrome")) {
            System.setProperty("webdriver.chrome.driver", "drivers\\chromedriver.exe");
            driver = new ChromeDriver();            
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            driver.manage().window().maximize();
        }
    }  
    @DataProvider
    public Object[][] tc001() {
        return new Object[][] {
                new Object[] {"nadee","12345678"},      
        };
    }
    
    @Test(dataProvider="tc001")
    public void tc001(String userName , String password) {
        driver.get(baseUrl);
        login.openApplication("https://test.com", driver);
        login.loginToApplication(driver, userName, password);
    }
    }
    

    I have use the xml file as follows to send the browser type,

    **4.xml file**
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Suite" parallel="false">
    <test name="Test">
      <parameter name="browser" value="chrome" />
        <classes>
          <class name="Systemloginfunctionalities.TC_LoginToTest"/>
        </classes>
    </test> <!-- Test -->
    </suite> <!-- Suite -->
    

    But I have received an error as follows in the TestNG , java.lang.NullPointerException: null value in entry: url=null

    Please help me to find a solution for this.



  • Here

    @Test(dataProvider="tc001")
    public void tc001(String userName , String password) {
        driver.get(baseUrl);
        login.openApplication("https://test.com", driver);
        login.loginToApplication(driver, userName, password);
    }
    

    you have driver.get(baseUrl); that receives baseUrl which is null (you are not assigning a value for that string anywhere)



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2