Within the following code, I’m attempting to get my driver from the category A to class B. Class B cannot have a constructor and I attempted making a base class, however both Class A will get driver null or Class B will get driver null.
Can somebody level out what I’m doing mistaken?
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 Web site
driver.get("https://pileouface.07zr.lu/fr/house/");
driver.handle().window().maximize();
Reporter.log(FormatMessageSucces + " Chrome is Opened");
}.....}
Class B :
public class CustomListener extends AjoutPanier implements ITestListener{
@Override
public void onTestFailure(ITestResult end result) {
// TODO Auto-generated methodology stub
System.out.println("TestFailure acces");
File file = ((TakesScreenshot)b.driver).getScreenshotAs(OutputType.FILE);
File ScreenshotName = new File(".//ScreenShots//check.png");
System.out.println("Recordsdata achieved");
attempt {
System.out.println("attempt");
FileUtils.copyFile(file, ScreenshotName);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("catch");
e.printStackTrace();
}
Reporter.log("");
System.out.println("*******Screenshot captured********");
}
}