-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetry.java
More file actions
41 lines (34 loc) · 1.76 KB
/
Copy pathRetry.java
File metadata and controls
41 lines (34 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.codacy;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import com.relevantcodes.extentreports.LogStatus;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public class Retry extends BaseTest implements IRetryAnalyzer {
private int count = 0;
private static int maxTry = 1; //Run the failed test 2 times
@Override
public boolean retry(ITestResult iTestResult) {
if (!iTestResult.isSuccess()) { //Check if test not succeed
if (count < maxTry) { //Check if maxtry count is reached
count++; //Increase the maxTry count by 1
iTestResult.setStatus(ITestResult.FAILURE); //Mark test as failed
extendReportsFailOperations(iTestResult); //ExtentReports fail operations
return true; //Tells TestNG to re-run the test
}
} else {
iTestResult.setStatus(ITestResult.SUCCESS); //If test passes, TestNG marks it as passed
}
return false;
}
public void extendReportsFailOperations(ITestResult iTestResult) {
Object testClass = iTestResult.getInstance();
WebDriver webDriver = ((BaseTest) testClass).getDriver();
String base64Screenshot = "data:image/png;base64," + ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.BASE64);
ExtentTestManager.getTest().log(LogStatus.FAIL, "Test Failed",
ExtentTestManager.getTest().addBase64ScreenShot(base64Screenshot));
ExtentTestManager.getTest().log(LogStatus.FAIL, "Test Failed",
iTestResult.getThrowable());
}
}