如果本机应用程序中的屏幕截图被限制,则如何在APPIUM中获取屏幕截图

时间:2018-09-10 10:39:58

标签: appium screenshot appium-android android-uiautomator uiautomatorviewer

我正在通过Java&Appium致力于一个本机应用程序的自动化。屏幕截图在该应用程序中受到限制,因此我无法拍摄屏幕截图,也无法通过UIAutomator检查元素。有什么办法可以解决这个问题。

2 个答案:

答案 0 :(得分:0)

尝试以Java方式拍摄屏幕快照而不是使用Apache Commons

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;

public void takeScreenShot(String fileName) {

    try {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenRectangle = new Rectangle(screenSize);
        Robot robot = new Robot();
        BufferedImage image = robot.createScreenCapture(screenRectangle);
        ImageIO.write(image, "png", new File(fileName));
        System.out.println("saved.."+fileName);

    } catch (Exception e) {
        e.printStackTrace();
    }

答案 1 :(得分:0)

尝试此方法并在需要截屏时调用它,这将创建一个截屏,并将名称传递给您的项目目录中的方法。

// Learning about pointers and C-coding techniques.

#include <stdio.h>

/* Is there a way to define the int-pointer age WITHOUT the int variable auxAge? */

int main()  // no command-line params being passed
{
    int auxAge = 12345;
    int* age = &auxAge;
    // *age is an int, and age is an int* (i.e. age is a pointer-to-an-int, just an address to somewhere in memory where data defining some int is expected)
    // do stuff with my *age int e.g. "(*age)++;" or "*age = 37;"
    return 0;
}

此处提供了一些解释。看看是否有帮助

https://developers.perfectomobile.com/display/TT/Capturing+screen+shots+using+Appium