我有两个类,我想在类“B”中调用类“A”的public void getResult(ITestResult result)方法怎么调用呢?我收到 NullPointerException
头等舱
public class loginPage{
public WebDriver driver;
Utility ut= new Utility();
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest logger;
By EmailId= By.xpath("//*[@name='Email']");
By password = By.xpath("//*[@name='Password']");
By LoginBtn= By.xpath("//*[@id='frmLogIn']/div[4]/button");
public loginPage(WebDriver driver) {
this.driver=driver;
}
@BeforeTest
public void startReport(){
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/ExtentReport.html");
extent = new ExtentReports ();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("Host Name", "SoftwareTestingMaterial");
extent.setSystemInfo("Environment", "Automation Testing");
extent.setSystemInfo("User Name", "Rajkumar SM");
htmlReporter.config().setDocumentTitle("Title of the Report Comes here");
htmlReporter.config().setReportName("Name of the Report Comes here");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.STANDARD);
}
@Test
public void setusername(WebDriver driver)
{
try
{
driver.findElement(EmailId).sendKeys("nilima@mailinator.com");
logger = extent.createTest("setusername");
Assert.assertTrue(true);
logger.log(Status.PASS, MarkupHelper.createLabel("Test Case Passed is setusername", ExtentColor.GREEN));
}
catch (TimeoutException e)
{
System.out.println("Time out exception " + e);
ut.capturescreenshot(driver, "setusername");
}
catch (ElementNotSelectableException e) {
System.out.println("Element not selectable exception " + e);
ut.capturescreenshot(driver, "setusername");
} catch (NoSuchElementException e) {
System.out.println("No such element found " + e);
ut.capturescreenshot(driver, "setusername");
} catch (ElementNotVisibleException e) {
e.printStackTrace();
ut.capturescreenshot(driver, "setusername");
} catch (Exception e) {
System.out.println("Something Wrong" + e);
ut.capturescreenshot(driver, "setusername");
}
}
@Test
public void setpassword(WebDriver driver)
{
try
{
driver.findElement(password).sendKeys("123123");
logger = extent.createTest("setpassword");
Assert.assertTrue(true);
logger.log(Status.PASS, MarkupHelper.createLabel("Test Case Passed is setpassword", ExtentColor.GREEN));
}
catch (TimeoutException e)
{
System.out.println("Time out exception " + e);
ut.capturescreenshot(driver, "setpassword");
}
catch (ElementNotSelectableException e) {
System.out.println("Element not selectable exception " + e);
ut.capturescreenshot(driver, "setpassword");
} catch (NoSuchElementException e) {
System.out.println("No such element found " + e);
ut.capturescreenshot(driver, "setpassword");
} catch (ElementNotVisibleException e) {
e.printStackTrace();
ut.capturescreenshot(driver, "setpassword");
} catch (Exception e) {
System.out.println("Something Wrong" + e);
ut.capturescreenshot(driver, "setpassword");
}
}
@Test
public void Login()
{
try
{
driver.findElement(LoginBtn).click();
String Title="Login | ORGCAP";
String GetTitle = driver.getTitle();
logger = extent.createTest("Login");
Assert.assertEquals(Title, GetTitle);
logger.log(Status.PASS, MarkupHelper.createLabel("Test Case Passed is Login", ExtentColor.GREEN));
}
catch (TimeoutException e)
{
System.out.println("Time out exception " + e);
ut.capturescreenshot(driver, "Login");
}
catch (ElementNotSelectableException e) {
System.out.println("Element not selectable exception " + e);
ut.capturescreenshot(driver, "Login");
} catch (NoSuchElementException e) {
System.out.println("No such element found " + e);
ut.capturescreenshot(driver, "Login");
} catch (ElementNotVisibleException e) {
e.printStackTrace();
ut.capturescreenshot(driver, "Login");
} catch (Exception e) {
System.out.println("Something Wrong" + e);
ut.capturescreenshot(driver, "Login");
}
}
@AfterMethod
public void getResult(ITestResult result){
if(result.getStatus() == ITestResult.FAILURE){
logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " - Test Case Failed", ExtentColor.RED));
logger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + " - Test Case Failed", ExtentColor.RED));
}else if(result.getStatus() == ITestResult.SKIP){
logger.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + " - Test Case Skipped", ExtentColor.ORANGE));
}
}
@AfterTest
public void endReport(){
extent.flush();
}
}
我的第二堂课是
public class login extends TestBuild{
ITestResult result;
@Test()
public void Loginadmin() throws IOException{
TestBuild BrowserSetUp= new TestBuild();
BrowserSetUp.setup();
loginPage lp= new loginPage(driver);
lp.startReport();
lp.setusername(driver);
lp.setpassword(driver);
lp.Login();
lp.getResult(result);
lp.endReport();
}
}
我在以下位置收到 NullPointerException:
if(result.getStatus() == ITestResult.FAILURE) 行。
如何处理?