0

My Java

public class LaunchApplication {
    private String LAUNCHAPPLICATION_STATUS=null;
    private String LAUNCHAPPLICATION_MESSAGE=null;


    @Test
    @Parameters({"RUN_USING_SG","BROWSER_CODE","URL","TITLE","PLATFORM","VERSION"})
    public void LAUNCHAPPLICATION(String RunUsingSG,String BrowserCode,String URL,String Title,String Platform,String Version) throws MalformedURLException
    {
        try
        {
            System.out.println(System.getProperty("user.dir"));
            DesiredCapabilities dc=new DesiredCapabilities();
            if(BrowserCode.equalsIgnoreCase("IE32"))
            {
                System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"/AllDrivers/IEDriverServer_32bit_OS.exe");
                dc.setBrowserName("internet explorer");
                dc.setVersion(Version);
                Config.driver = new InternetExplorerDriver();

            }
            if(BrowserCode.equalsIgnoreCase("IE64"))
            { 
                System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"/AllDrivers/IEDriverServer_64bit_OS.exe");
                dc.setBrowserName("internet explorer");
                dc.setVersion(Version);
                Config.driver = new InternetExplorerDriver();
            }
            if(BrowserCode.equalsIgnoreCase("FF"))
            { 
                FirefoxProfile firefoxProfile = new FirefoxProfile();
                dc.setBrowserName("firefox"); 
                dc.setVersion(Version);
                Config.driver=new FirefoxDriver();
            }
            if(RunUsingSG.equalsIgnoreCase("Y"))
            {
                Config.driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc);

            }

            if(Platform.equalsIgnoreCase("WINDOWS"))
            {dc.setPlatform(org.openqa.selenium.Platform.WINDOWS);}
            Config.driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
            Config.driver.get(URL);
            Config.driver.manage().window().maximize();
            //perform final validation
            if(Config.driver.getTitle().toLowerCase().equalsIgnoreCase(Title))
            {
                LAUNCHAPPLICATION_STATUS="PASS";
                LAUNCHAPPLICATION_MESSAGE="EXPECTED BROWSER TITLE:"+Title+", ACTUAL BROWSER TITLE :"+Config.driver.getTitle()+", FOR THE URL:"+URL;
            }


        }//end of try

        catch(Exception generalException)
        {
            LAUNCHAPPLICATION_STATUS="FAIL";
            LAUNCHAPPLICATION_MESSAGE= "EXPECTED BROWSER TITLE:"+Title+", ACTUAL BROWSER TITLE :"+Config.driver.getTitle()+", FOR THE URL:"+URL+". DETAILS:Exception Occoured:"+generalException.getLocalizedMessage();

        }
    }

    //@BeforeTest
     //public void f1(ITestContext ctx) {

        //  if(ctx.getCurrentXmlTest().getParameter("EXECUTE").equals("NO"))
          //    {
            //  throw new SkipException("skiping this test case");
            //}


}

I am Getting an error of null pointer exception in above code when executing through testng.I don't know why? and when I am executing through junit it is working fine?So Any Help? I Think this may occured because I have declared LAUNCHAPPLICATION_STATUS=null; or any other problem.

org.testng.TestNGException: java.lang.NullPointerException
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:341)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.NullPointerException
at       org.testng.xml.TestNGContentHandler.xmlClasses(TestNGContentHandler.java:342)
at   org.testng.xml.TestNGContentHandler.endElement(TestNGContentHandler.java:693)
at   com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
at   com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at   com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at  com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at  com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at  com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.testng.xml.XMLParser.parse(XMLParser.java:39)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:168)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
... 3 more
2
  • 1
    You didn't mark where you get the exception, nor show the actual stack trace. It's hard to help without those details. Commented Jul 13, 2015 at 14:04
  • @RealSkeptic check now I have mark the error now. Commented Jul 13, 2015 at 14:52

1 Answer 1

1

The exception occurs in TestNGContentHandler.endElement() which is a pretty strong hint that the problem is in your XML file, not your LaunchApplication class. It might be worth filing a bug against TestNG to provide a clearer error message in this case, depending on what the issue ends up being.

Try creating a basic "hello world" @Test, so that you can verify TestNG (and your TestNG configuration) runs at all. If it fails, we know it's a configuration issue. Otherwise if it works you can narrow it down to the specific problematic tests.

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

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.