In the following code, I am trying to get my driver from the class A to class B. Class B can’t have a constructor and I tried making a base class, but either Class A gets driver null or Class B gets driver null.
Can someone point out what I am doing wrong?
Class A :
@Listeners(CustomListener.class)
public class AjoutPanier {
public WebDriver driver;
@BeforeTest
public void LaunchWebsite() {
// Launch Chrome
System.setProperty(“webdriver.chrome.driver”, “C:\chromedriver.exe”);
driver = new ChromeDriver();
// Acces Website
driver.get(“https://pileouface.07zr.lu/fr/home/”);
driver.manage().window().maximize();
Reporter.log(FormatMessageSucces + ” Chrome is Opened</font>”);
}…..}
Class B :
public class CustomListener extends AjoutPanier implements ITestListener{
@Override
public void onTestFailure(ITestResult result) {
// TODO Auto-generated method stub
System.out.println(“TestFailure acces”);
File file = ((TakesScreenshot)b.driver).getScreenshotAs(OutputType.FILE);
File ScreenshotName = new File(“.//ScreenShots//test.png”);
System.out.println(“Files done”);
try {
System.out.println(“try”);
FileUtils.copyFile(file, ScreenshotName);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(“catch”);
e.printStackTrace();
}
Reporter.log(“</br><img src='”+ ScreenshotName +”‘/>”);
System.out.println(“*******Screenshot captured********”);
}
}