문제

I currently have something working to capture screenshots on iOS for appium tests using java and junit. Before a test finishes it runs this code to get the last visible thing on the screen before killing the connection

@After
public void tearDown() throws Exception {
    if (platform.equals(iOS)) {
        captureScreenshot(testName.getMethodName());
    }
    driver.quit();
}

@SuppressWarnings("Augmenter")
public void captureScreenshot(String testName) {
    String imagesLocation = "target/surefire-reports/screenshot/" + platform + "/";
    new File(imagesLocation).mkdirs(); // Insure directory is there
    String filename = imagesLocation + testName + ".jpg";

    try {
        Thread.sleep(500);
        WebDriver augmentedDriver = new Augmenter().augment(driver);
        File scrFile = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File(filename), true);
    } catch (Exception e) {
        System.out.println("Error capturing screen shot of " + testName + " test failure.");
        // remove old pic to prevent wrong assumptions
        File f = new File(filename);
        f.delete(); // don't really care if this doesn't succeed, but would like it to.
    }
}

This sorta works for android but lately it has completely killed the running test but this might have to do with the device it is trying to get the snapshot of. Before it would save the file but the image would come up blank or broken.

Anyone know how to get image/screen capturing working on android using appium? Perhaps something with UIAutomator?

도움이 되었습니까?

해결책

You can use this method:

public void screenshot(String path_screenshot) throws IOException{
    File srcFile=driver.getScreenshotAs(OutputType.FILE);
    String filename=UUID.randomUUID().toString(); 
    File targetFile=new File(path_screenshot + filename +".jpg");
    FileUtils.copyFile(srcFile,targetFile);
}

It works fine for me.

다른 팁

I happened to find this via Google search with nearly the same problem - Appium screenshots in the Android emulator come up blank. I'm using both the 'native' method much like you describe above - and - the method within the ATU framework.

WebElement appArea = wd.findElementByXPath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]");
ATUReports.add("Main Screen Area Screenshot", LogAs.INFO, new CaptureScreen(appArea));

and both come back blank/transparent. The marginally good news is that the dimension of that blank/transparent image is exactly the size I want to capture - avoiding the status bar where date diffs would cause error on image comparison. That said, it's not much use without actual viewable pixels (for eventual matching of object area grabs to validated baseline images).

I tried setting context to "NATIVE_APP" and nothing seems to help. I am - in a word - vexed. If you've made any progress with this I'd love to read/hear how you got it working. Maybe the next step is to go to the Appium Google Group.

EDIT: I found the core issue in my case - using HAXM acceleration causes the blank screen shots. Note this also affects test run on physical devices if the base device profile set in the test's capabilities is defined with "Host GPU" selected.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top