Screenshots save test results

import org.testng.ITestResult;
import com.unionpay.listener.TestNGListenerWithPost;
@Listeners(TestNGListenerWithPost.class)
public abstract class BaseTest {
    public AndroidDriver<WebElement> driver;
    public BaseTest() { driver = DriverFactory.getDriverByJson(); } @param tr */ public void takeScreenShot(ITestResult tr) {String fileName = tr.getName() +".jpg";
    File dir = new File("target/snapshot");
    if(! dir.exists()) { dir.mkdirs(); } String filePath = dir.getAbsolutePath() +"/" + fileName;
    if(driver ! = null) { try { File scrFile = driver.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File(filePath)); } catch (IOException e) { e.printStackTrace(); }}}}Copy the code

ITestResult

www.jianshu.com/p/74816a200…

Blog.csdn.net/hankle_xu/a… www.cnblogs.com/111testing/… www.programcreek.com/java-api-ex… www.jianshu.com/p/d430c7801…