错误
[RemoteTestNG] detected TestNG version 6.14.2
Total rows are 5
[Utils] [ERROR] [Error] java.lang.NullPointerException
at appops_main_home.LaunchPortalData.passUNamePwd(LaunchPortalData.java:41)
at appops_main_home.LaunchPortal.TestDataFeed(LaunchPortal.java:60)
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:124)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45)
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:131)
at org.testng.internal.Parameters.handleParameters(Parameters.java:706)
at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:49)
at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:37)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:923)
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:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
SKIPPED: Loginapp
java.lang.RuntimeException: java.lang.NullPointerException
at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:49)
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:131)
at org.testng.internal.Parameters.handleParameters(Parameters.java:706)
at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:49)
at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:37)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:923)
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:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.NullPointerException
at appops_main_home.LaunchPortalData.passUNamePwd(LaunchPortalData.java:41)
at appops_main_home.LaunchPortal.TestDataFeed(LaunchPortal.java:60)
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:124)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45)
... 22 more
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
===============================================
这是我的代码
package appops_main_home;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
//import utility.Constant;
//import excel.input.login.LaunchPortalData;
public class LaunchPortal
{
ChromeDriver driver ;
@Test(dataProvider = "testdata")
public void Loginapp(String W3ID, String W3Pwd) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\KalaivaniBaskaran\\Desktop\\088619\\Selenium\\Jar & drivers\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get("http://testurl");
driver.findElement(By.id("desktop")).sendKeys(W3ID);
driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div/form/input[4]")).sendKeys(W3Pwd);
driver.findElement(By.id("btn_signin")).click();
Assert.assertTrue("Invalid credentials", driver.getTitle().matches("Hybrid Cloud Portal"));
System.out.println("Login successful");
}
@AfterMethod
public void closebrowser()
{
driver.quit();
}
@DataProvider(name="testdata")
public Object[][] TestDataFeed()
{
LaunchPortalData config = new LaunchPortalData("C:\\Users\\KalaivaniBaskaran\\Desktop\\088619\\test excel datas\\Usernamepwd_AppOps.xlsx");
int r = config.Rowcountcalculator();
System.out.println("Total rows are "+r);
Object[][] credentials = new Object[r][2];
for (int i=0; i<r; i++)
{
credentials[i][0] = config.passUNamePwd(0, i, 0);
credentials[i][1] = config.passUNamePwd(0, i, 1);
}
return credentials;
}
}
这是数据
package appops_main_home;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
public class LaunchPortalData {
XSSFWorkbook wb ;
XSSFSheet sheet0;
public LaunchPortalData(String excelPath) {
try {
File src = new File(excelPath);
FileInputStream fis = new FileInputStream(src);
wb = new XSSFWorkbook(fis);
sheet0 = wb.getSheetAt(0);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int Rowcountcalculator()
{
int Rowcount = sheet0.getLastRowNum();
return Rowcount;
}
public String passUNamePwd(int sheetnumb, int row, int column)
{
String data = wb.getSheetAt(sheetnumb).getRow(row).getCell(column).getStringCellValue();
return data;
}}
答案 0 :(得分:0)
请按照以下说明更改您的passUNamePwd
public String passUNamePwd(int sheetnumb, int rowIndex, int columnIndex)
{
XSSFSheet sheet=wb.getSheetAt(sheetnumb);
String data="";
Row row=sheet.getRow(rowIndex);
Cell c=row.getCell(columnIndex, row.RETURN_BLANK_AS_NULL);
if(c==null){
data="";
}
else{
data=row.getCell(columnIndex).getStringCellValue();
}
return data;
}