jeudi 7 décembre 2017

NullPointerexeption while calling method in Testng [duplicate]

This question already has an answer here:

I am getting NullPointerexeption while calling method in Testng

I tried debugging, the problem is with my CommonLib.selectlist method because everything is fine exept that, please check and provide solution

I am running testcase.java

testcase script

         public class Testcase extends beforeexecution.Login1 {

         public static Xls_Reader exel1;

         @BeforeClass
         public void login() throws IOException, Throwable{

        Login1 x = new Login1(); 
        x.Readproperties(); 
        exel1 = new Xls_Reader(Login1.props.getProperty("TestDataPath")); 
        String siteurl = exel1.getCellData("Login", "TestUrl", 2); 
        String acc = exel1.getCellData("Login", "Account", 2); 
        String passw=exel1.getCellData("Login", "Password", 2); 
        Login1.getDriver(); 
        driver.get(siteurl); 
        /*driver.manage().window().maximize();*/ 
        Login1.logintoapp(acc, passw);
        Thread.sleep(5000); 
        }

         @Test

        public void Executemain() throws InterruptedException{

        String studyname = exel1.getCellData("Login", "Studyname", 2);
        CommonLib.selectlist(studyname);


        String datasheetname=exel1.getCellData("Login", "Form", 2);
        CommonLib.action(datasheetname);

        }

        }

CommonLib Script

            public class CommonLib extends Login1 {

            public static WebDriver driver;
            static ChromeOptions options;

            public static void main(String [] arg){

            }


           public static void selectlist(String studyname) throws 
           InterruptedException{

           WebElement studyxpath = 
           driver.findElement(By.xpath("//select[@id='studyList']"));
           System.out.println(studyxpath);
           Select dropdown = new Select(studyxpath);

           dropdown.selectByVisibleText(studyname);

          }

my login1 Script

          public class Login1 {
          public static Properties props;
          public static WebDriver driver;



          public static void main(String [] arg){

          }


          public  void Readproperties() throws IOException {

          InputStream propertiesFilePath = 

         Login1.class.getClassLoader().getResourceAsStream
         ("Filepath/Config.properties");

       props = new Properties();

      props.load(propertiesFilePath);


      }


     public static WebDriver  getDriver(){
     System.setProperty("webdriver.chrome.driver", 

    "C:\\Users\\aroy\\Desktop\\Sele\\chromedriver_win32\\chromedriver.exe");
    driver = new ChromeDriver();
    return driver;
    }


    public static void logintoapp(String acc, String passw) throws 
     InterruptedException{



    driver.findElement(By.xpath("//input[@id='userName']")).sendKeys(acc);
    driver.findElement(By.xpath("//input[@id='password']")).sendKeys(passw);
    driver.findElement(By.xpath("//button[@id='loginBtn']")).click();
    System.out.println("Login SuccessFully");
    Thread.sleep(5000);
    }

     }

Log

  java.lang.NullPointerException
  at Arexecution.CommonLib.selectlist(CommonLib.java:28)
  at Arexecution.Testcase.Executemain(Testcase.java:52)
  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:669)
   at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
  at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
    at 
  org.testng.internal.TestMethodWorker.invokeTestMethods
  (TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
  at org.testng.TestRunner.privateRun(TestRunner.java:776)
  at org.testng.TestRunner.run(TestRunner.java:634)
  at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
  at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
  at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
  at org.testng.SuiteRunner.run(SuiteRunner.java:334)

Please check and provide solution as my frame work has stopped because of this exeption

Aucun commentaire:

Enregistrer un commentaire