简体   繁体   中英

Robotium - How to take a screenshot and open from inside the test case

I'm trying to write a tests case that takes a screenshot of the screen, and them loads this screenshot for image processing. So far I found the following method

solo.takeScreenshot()

The takeScreenshot() method saves the picture in “/sdcard/Robotium-Screenshots/” folder on device.

Is there any method I could use to access the file saved in this folder?

Thanks!

You can tell robotium what file name to use for the screenshot. Robotium will save the file asynchronously so you need to wait for the file to appear using it.

    solo.takeScreenshot("ScreenshotFile");
    final File file = new File(Environment.getExternalStorageDirectory() + "/Robotium-Screenshots/", "ScreenshotFile" + ".jpg");
    final int TIMEOUT = 5000;
    assertTrue(solo.waitForCondition(new Condition() {
        @Override
        public boolean isSatisfied() {
            return file.exists();
        }
    }, TIMEOUT));
    HERE IS WHERE YOU CAN DO WHATEVER YOU WANT WITH file

Of course in subsequent runs the file will exist before you run the test. You either need to clean up the file or generate a new file name for each test run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM