IntelliJ POM module - null pointer expecption error

30 views
Skip to first unread message

Rashmi Upari

unread,
May 20, 2019, 6:12:12 AM5/20/19
to Selenium Users
Hello All,
 i m using intelliJ fo jus open browser and check for logo with POM , but getting null pointer error.
Please help me to resolve this

Driver : MyChromeDriver class
package SanityCases.drivers;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class MyChromeDriver
{
    private static WebDriver driver;
    private static final int IMPLICIT_WAIT = 10;

    public static synchronized WebDriver getChromeDriver ()
    {
        if (driver == null)
        {
            //This is for "Allowing Camera & Geolocation" in Chrome
           // Map<String, Object> prefs = new HashMap<>();
            Map<String, Object> prefs = new HashMap<String, Object>();
            //Map<String, Object> prefs = new HashMap<String, Object>();
            //Map<String, Object> prefs = new HashMap<String, Object>();

            prefs.put("profile.default_content_setting_values.geolocation",1);
            prefs.put("profile.default_content_setting_values.media_stream_camera",1);
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", prefs);

            //Below is path to the ChromeDriver
            System.setProperty("webdriver.chrome.driver", ClassLoader.getSystemClassLoader().getResource("drivers/chromedriver.exe").getPath());

            //"Options" in the brackets should be visible due to above Camera and Geolocation
            driver = new ChromeDriver(options);
            driver.manage().deleteAllCookies();
            driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT, TimeUnit.SECONDS);
            driver.manage().window().maximize();
        }
        return driver;
    }

    public static void quitChromeDriver ()
    {
        if (driver != null) {
            driver.quit();
            driver = null;
        }
    }
}

Pages: PublicPage class
public class PublicPage extends PageFactory
{
    public static final String URL = "https://rashmi.qa1.snapvcm.com/";

    @FindBy(xpath = "//*[@id=\"viewcontainer\"]/div/div[2]/div[1]/div[1]/div[1]/img")
    private WebElement logo;


    public PublicPage()
    {
        initElements(getChromeDriver(), this);
        openPage();

    }


    public PublicPage openPage()
    {
        getChromeDriver().get(URL);
        WebDriverWait wait = new WebDriverWait(getChromeDriver(), 20);
        wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@id=\"viewcontainer\"]/div/div[2]/div[1]/div[1]/div[2]")));
        Assertions.assertTrue(logo.isDisplayed());

        return this;
    }
}

tests: test class
public class PublicPage extends PageFactory
{
    public static final String URL = "https://rashmi.qa1.snapvcm.com/";

    @FindBy(xpath = "//*[@id=\"viewcontainer\"]/div/div[2]/div[1]/div[1]/div[1]/img")
    private WebElement logo;


    public PublicPage()
    {
        initElements(getChromeDriver(), this);
        openPage();

    }


    public PublicPage openPage()
    {
        getChromeDriver().get(URL);
        WebDriverWait wait = new WebDriverWait(getChromeDriver(), 20);
        wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@id=\"viewcontainer\"]/div/div[2]/div[1]/div[1]/div[2]")));
        Assertions.assertTrue(logo.isDisplayed());

        return this;
    }
}


Screenshot 2019-05-20 at 3.41.11 PM.png

Mark Collin

unread,
May 23, 2019, 3:36:27 AM5/23/19
to Selenium Users
Looks like this line is causing your NullPointerError:

ClassLoader.getSystemClassLoader().getResource("drivers/chromedriver.exe").getPath()

Does the chromedriver file exist in that location?

Rashmi Upari

unread,
May 27, 2019, 6:43:43 AM5/27/19
to Selenium Users
Hi Mark,

yes its in right location, please check screenshot below
https://cl.ly/2ebaf6a1a8a6
Reply all
Reply to author
Forward
0 new messages