在Testng中调用方法时的NullPointerexeption

时间:2017-12-06 17:55:55

标签: java selenium testing webdriver selenium-chromedriver

我在Testng中调用方法时得到NullPointerexeption

我试过调试,问题出在我的CommonLib.selectlist方法上,因为一切都很好,请检查并提供解决方案

我正在运行testcase.java

testcase脚本

         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脚本

            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);

          }

我的login1脚本

          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);
    }

     }

日志

  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)

请检查并提供解决方案,因为我的框架工作因此操作而停止

0 个答案:

没有答案