0

Can someone pls help with this

 package IEProjects;

    import java.io.File;

    import org.junit.BeforeClass;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.testng.Assert;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.Test;

    public class TestIEBrowser {


              static String driverPath = "IE driver path";
              public WebDriver driver;             


                @BeforeClass
                public void setUp() {
                    System.out.println("my IE");
                    System.out.println("launching IE browser");
                    System.setProperty("webdriver.ie.driver","C:\\IEDriverServer_Win32_3.3.0\\IEDriverServer.exe");

                    driver = new InternetExplorerDriver();
                    driver.manage().window().maximize();
                }

                @Test
                public void testGooglePageTitleInIEBrowser() {
                    driver.navigate().to("http://www.google.com");
                    String strPageTitle = driver.getTitle();
                    System.out.println("Page title: - "+strPageTitle);
                    Assert.assertTrue(strPageTitle.equalsIgnoreCase("Google"), "Page title doesn't match");
                }

                @AfterClass
                public void tearDown() {
                    if(driver!=null) {
                        System.out.println("Closing IE browser");
                        driver.quit();
        }

    }
    }

here is the error below, i appreciate your prompt reply.

FAILED: testGooglePageTitleInIEBrowser java.lang.NullPointerException at IEProjects.TestIEBrowser.testGooglePageTitleInIEBrowser(TestIEBrowser.java:32) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeMethod(Invoker.java:661) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:744) at org.testng.TestRunner.run(TestRunner.java:602) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================

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

Thank you

1
  • Are you able to debug to tell what value the variables on line 32 have? Commented Apr 21, 2017 at 13:40

2 Answers 2

2

The root cause is because driver is not initialized properly.

I think you are incorrectly import beforeClass annotation from Junit instead of testNG, and thus causing setUp method not called and resulting driver not initialized

please change import into import org.testng.annotations.BeforeClass;

Sign up to request clarification or add additional context in comments.

Comments

1

The IE browser is not able to launch due to the annotation being wrong wherein you have used the JUNIT annotation instead of TestNg.

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.