tengo un código de prueba donde realiza un AssertEquals del resultado de una operación matemática en la página, https://testsheepnz.github.io/BasicCalculator.html la cosa es que estoy tratando de realizar un screenshot cuando el test falle, exite una manera de que el código realice una acción cuando el test falle o salga exitoso?
public class prueba_screenshot {
EdgeDriver driver;
Select operation;
By operationlocator = By.id("selectOperationDropdown");
By number1locator = By.id("number1Field");
By number2locator = By.id("number2Field");
By calculatebuttonlocator = By.id("calculateButton");
By resultlocator = By.id("numberAnswerField");
By screenshotlocator = By.cssSelector("div[class='col-lg-12 text-left']");
String numero1 = "5";
String numero2 = "3";
String result = "";
String resultEsperado = "7";
ITestResult resultadoprueba;
boolean finalmente = true;
@BeforeSuite
public void SetUp() throws InterruptedException {
driver = new EdgeDriver();
driver.manage().window().maximize();
driver.get("https://testsheepnz.github.io/BasicCalculator.html");
Thread.sleep(10000);
}
@Test
public void testConScreenshot() throws InterruptedException{
driver.findElement(number1locator).sendKeys(numero1);
driver.findElement(number2locator).sendKeys(numero2);
operation = new Select(driver.findElement(operationlocator));
operation.selectByValue("0");
driver.findElement(calculatebuttonlocator).click();
Thread.sleep(5000);
result = driver.findElement(resultlocator).getAttribute("value");
Assert.assertEquals(result, resultEsperado);
}
@AfterSuite
public void Teardown(){
driver.close();
}
}
Este es la acción que quiero agregar en dado caso que el test testConScreenshot falle
Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
ImageIO.write(screenshot.getImage(), "jpg", new File("C:\\Users\\raine\\Desktop\\test\\page(2).jpg"));