Screenshot problems in Appium automation

Source: Internet
Author: User
Tags appium

When you do UI Automation with Appium, you'll find that test reports are important and important in test reports.

Because many companies use Jenkins as a continuous integration tool, the people who perform automated tests see what automation is running, where it fails, and what critical nodes are required for.

How to do it, the current project is so implemented:

1. Implement the function class:

12345678910111213141516171819 publicstaticString screenShot(ShipperAndroidEmulator ae) {    String dir = "screenshot"// TODO    String time = newSimpleDateFormat("yyyyMMdd-HHmmss").format(newDate());    String screenShotPath = dir + File.separator + time + ".png";    AndroidDriver augmentedDriver = null;    augmentedDriver = ae.getAndroid();    try{        File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);        FileUtils.copyFile(sourceFile, new File(screenShotPath));    catch(Exception e) {        e.printStackTrace();        return"Failed to screenshot";    }    returnscreenShotPath.replace("\\""/");}

2. Implement the error-handling class with screenshot:

12345678910 privatevoidhandleFailure(String notice) {    String png = LogTools.screenShot(this);    String log = notice + " >> capture screenshot at "+ png;    logger.error(log);    if(GlobalSettings.baseStorageUrl.lastIndexOf("/") == GlobalSettings.baseStorageUrl.length()) {        GlobalSettings.baseStorageUrl = GlobalSettings.baseStorageUrl.substring(0, GlobalSettings.baseStorageUrl.length() - 1);    }    Reporter.log(log + "<br/>+ GlobalSettings.baseStorageUrl + "/"+ png + "\" />");    Assert.fail(log);}

3. All Appium interface operation classes are processed:

123456789101112 publicvoidclick(By by) {    expectElementExistOrNot(true, by, timeout);    try{        clickTheClickable(by,System.currentTimeMillis(),2500);        handleSuccess("Succeed to click "+ by);    }catch(Exception e){        e.printStackTrace();        handleFailure("Failed to click "+ by);    }    logger.info("Clicked "+ by);}

4. Do not click Time to re-pilot hit operation

private void Clicktheclickable (by byelement, long startTime, int timeOut) throws Exception {
try {
Findelementby (byelement). Click ();
} catch (Exception e) {
if (System.currenttimemillis ()-startTime > TimeOut) {
Logger.warn (byelement+ "is unclickable");
throw new Exception (e);
} else {
Thread.Sleep (500);
Logger.warn (Byelement + "is unclickable, try again");
Clicktheclickable (Byelement, StartTime, TimeOut);
}
}

Problems in Appium automation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.