How to solve null pointer exception in selenium webdriver with java -


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()+", url:"+url;             }           }//end of try          catch(exception generalexception)         {             launchapplication_status="fail";             launchapplication_message= "expected browser title:"+title+", actual browser title :"+config.driver.gettitle()+", url:"+url+". details:exception occoured:"+generalexception.getlocalizedmessage();          }     }      //@beforetest      //public void f1(itestcontext ctx) {          //  if(ctx.getcurrentxmltest().getparameter("execute").equals("no"))           //    {             //  throw new skipexception("skiping test case");             //}   } 

i getting error of null pointer exception in above code when executing through testng.i don't know why? , when executing through junit working fine?so help? think may occured because have declared launchapplication_status=null; or other problem.

org.testng.testngexception: java.lang.nullpointerexception @ org.testng.testng.initializesuitesandjarfile(testng.java:341) @ org.testng.remote.remotetestng.run(remotetestng.java:88) @ org.testng.remote.remotetestng.initandrun(remotetestng.java:204) @ org.testng.remote.remotetestng.main(remotetestng.java:175) caused by: java.lang.nullpointerexception @       org.testng.xml.testngcontenthandler.xmlclasses(testngcontenthandler.java:342) @   org.testng.xml.testngcontenthandler.endelement(testngcontenthandler.java:693) @   com.sun.org.apache.xerces.internal.parsers.abstractsaxparser.endelement(unknown source) @   com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scanendelement(unknown source) @   com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl$fragmentcontentdriver.next(unknown source) @  com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl.next(unknown source) @  com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scandocument(unknown source) @  com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.xmlparser.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.abstractsaxparser.parse(unknown source) @ com.sun.org.apache.xerces.internal.jaxp.saxparserimpl$jaxpsaxparser.parse(unknown source) @ com.sun.org.apache.xerces.internal.jaxp.saxparserimpl.parse(unknown source) @ javax.xml.parsers.saxparser.parse(unknown source) @ org.testng.xml.xmlparser.parse(xmlparser.java:39) @ org.testng.xml.suitexmlparser.parse(suitexmlparser.java:17) @ org.testng.xml.suitexmlparser.parse(suitexmlparser.java:10) @ org.testng.xml.parser.parse(parser.java:168) @ org.testng.testng.initializesuitesandjarfile(testng.java:311) ... 3 more 

the exception occurs in testngcontenthandler.endelement() pretty strong hint problem in xml file, not launchapplication class. might worth filing bug against testng provide clearer error message in case, depending on issue ends being.

try creating basic "hello world" @test, can verify testng (and testng configuration) runs @ all. if fails, know it's configuration issue. otherwise if works can narrow down specific problematic tests.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -