0

Console

FAILED CONFIGURATION: @BeforeMethod setUp
java.lang.NullPointerException
    at com.ecinteractive.base.TestBase.initialization(TestBase.java:50)
    at com.ecinteractive.testcases.LoginPageTest.setUp(LoginPageTest.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
    at org.testng.TestNG.run(TestNG.java:1031)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED CONFIGURATION: @BeforeMethod setUp
SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED CONFIGURATION: @BeforeMethod setUp
SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED: loginPageTitleTest
SKIPPED: logoImageTest
SKIPPED: loginTest

===============================================
    Default test
    Tests run: 3, Failures: 0, Skips: 3
    Configuration Failures: 1, Skips: 5
===============================================


===============================================
Default suite
Total tests run: 3, Failures: 0, Skips: 3
Configuration Failures: 1, Skips: 5
===============================================

[TestNG] Time taken by org.testng.reporters.EmailableReporter@2d127a61: 0 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@290dbf45: 16 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 15 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@4e41089d: 0 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@7181ae3f: 32 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@4e4aea35: 31 ms

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

LoginPageTest Class

package com.ecinteractive.testcases;

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.ecinteractive.base.TestBase;
import com.ecinteractive.pages.HomePage;
import com.ecinteractive.pages.LoginPage;

public class LoginPageTest extends TestBase {
    LoginPage loginPage;
    HomePage homePage;



    public LoginPageTest() {
        super();


    }

    @BeforeMethod

    public void setUp() {
        initialization();
        this.loginPage = new LoginPage();


    }

@Test (priority=1)
public void loginPageTitleTest() {
    String title = loginPage.validateLoginPageTitle();
    Assert.assertEquals(title, "Login | ECi - QA Site 1");

}
@Test(priority=2)
public void logoImageTest() {
    boolean flag =loginPage.validateLogo() ;
    Assert.assertTrue(flag);

}

@Test(priority=3)
public void loginTest() {
    homePage= loginPage.login(prop.getProperty("username"), prop.getProperty("password"));

}






@AfterMethod

public void tearDown() {
    driver.quit();

}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++

Test Base Class

package com.ecinteractive.base;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.ecinteractive.util.TestUtil;

public class TestBase {

    public static WebDriver driver;
    public static Properties prop;

    public TestBase() {

        try {

            prop = new Properties();
            FileInputStream ip = new FileInputStream(
                    System.getProperty("user.dir") + "/src/main/java/com/ecinteractive" + "/config/config.properties");
            prop.load(ip);

        } catch (FileNotFoundException e) {
            e.printStackTrace();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void initialization() {
        String browserName = prop.getProperty("browser");

        if (browserName.equals("chrome")) {
            System.setProperty("webdriver.chrome.driver", "/Drivers/chromedriver.exe");
            driver = new ChromeDriver();

        } else if (browserName.equals("FF")) {
            System.setProperty("webdriver.gecko.driver", "/Drivers/geckodriver.exe");
            driver = new FirefoxDriver();

        }
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);

        driver.get(prop.getProperty("url"));

}
}
++++++++++++++++++++++++++++

Config.properties

url =

username = password =

browser = chrome

LoginPage.java

package com.ecinteractive.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import com.ecinteractive.base.TestBase;

public class LoginPage extends TestBase {

    //Page Factory -OR

    @FindBy(id="UserName")
    WebElement UserName;


    @FindBy(id="Request_Password")
    WebElement Request_Password;

    @FindBy(xpath="//span[contains(text(),'Login')]")
    WebElement loginBtn;

    @FindBy(xpath="//div[@class='logo']")
    WebElement logo;


    //Now we need to initialize all the OR so we create a Constructor
    // this is current class 

    public LoginPage() {
        PageFactory.initElements(driver, this);

    }

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

    }
    public boolean validateLogo() {
        return logo.isDisplayed();      
    }
    public HomePage login(String un, String pwd) {
        UserName.sendKeys(un);
        Request_Password.sendKeys(pwd);
        loginBtn.click();


        return new HomePage();

    }
}
14
  • Please add the loginclass, now you have added only the loginclasstest. The problem is mostly because you are not passing driver instinct to loginpage declaration.
    – PDHide
    Mar 22 '20 at 7:58
  • try this solution :stackoverflow.com/questions/60703284/… Mar 22 '20 at 12:54
  • PDHide i just added. Thank you
    – dhakals
    Mar 22 '20 at 16:24
  • @dhakals , are you sure your initialization() method works fine and driver is properly initialized? do you see the browser opening ?
    – PDHide
    Mar 22 '20 at 17:47
  • 1
    @PDHide. Thank you so much. using contains instead of equals worked. you are Awesome. Thank you so much for your time for a new contributor like me. It is greatly appreciated. Thank you so much again.
    – dhakals
    Mar 22 '20 at 20:53
1

the exception shown is:

FAILED CONFIGURATION: @BeforeMethod setUp
java.lang.NullPointerException
    at com.ecinteractive.base.TestBase.initialization(TestBase.java:50)

So from (TestBase.java:50), we can say that the exception was thrown at line 50 of TestBase class.

On analyzing the line 50 of TestBase, we can see the code that throws the error is:

driver.manage().window().maximize();

This shows that the driver object was not initialized properly,

so try to print browserName and see whether you are actually getting the value you need, because it seems that the code is not entering any of the if statements.

I hardcoded the value browsername="chrome" and things worked fine. So it looks like prop.getproperty("browser") doesn't give chrome, try printing it before the if statement. Ensure there is no space or characters

And also see if there is any trailing or leading spaces fpr browserName value. remove it before comparison or use browserName.contains("chrome") instead of browserName.equals("chrome")

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.