porps.put("reuse", 0);
porps.put("app", “/Users/xxx/xxxx.app”);
<dependency>
<groupId>macaca.webdriver.client</groupId>
<artifactId>macacaclient</artifactId>
<version>1.0.48</version>
</dependency>
private Double[] getElementLocation(Element element) {
Double[] location = new Double[2];
try {
JSONObject elementRect = (JSONObject) element.getRect();
location[0] = Double.valueOf(elementRect.get("x").toString()) + Double.valueOf(elementRect.get("width").toString()) / 2;
location[1] = Double.valueOf(elementRect.get("y").toString()) + Double.valueOf(elementRect.get("height").toString()) / 2;
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
<dependency>
<groupId>macaca.java</groupId>
<artifactId>biz</artifactId>
<version>0.0.7</version>
<type>jar</type>
</dependency>
private void scrollByLocation(double xPoint, double yPoint, int direction, int step) {
JSONObject obj = new JSONObject();
try {
switch (direction) {
case RIGHT: {
driver.drag(Double.valueOf(xPoint), Double.valueOf(yPoint), Double.valueOf(xPoint + step), Double.valueOf(yPoint), 0.05D, step);
break;
}
case LEFT: {
if (step > xPoint) {
driver.drag(Double.valueOf(step), Double.valueOf(yPoint), Double.valueOf(0), Double.valueOf(yPoint), 0.05D, step);
} else {
driver.drag(Double.valueOf(xPoint), Double.valueOf(yPoint), Double.valueOf(xPoint - step), Double.valueOf(yPoint), 0.05D, step);
}
break;
}
case UP: {
if (step > yPoint) {
driver.drag(Double.valueOf(xPoint), Double.valueOf(step), Double.valueOf(xPoint), Double.valueOf(yPoint), 0.05D, step);
} else {
driver.drag(Double.valueOf(xPoint), Double.valueOf(yPoint), Double.valueOf(xPoint), Double.valueOf(yPoint - step), 0.05D, step);
}
break;
}
case DOWN: {
driver.drag(Double.valueOf(xPoint), Double.valueOf(yPoint), Double.valueOf(xPoint), Double.valueOf(yPoint + step), 0.05D, step);
break;
}
}
} catch (Exception e) {
handleFailure(e.getMessage());
}
}
public static String screenShot(BaseMacacaClient driver, String ScreenshotPath) {
String screenShotPath=null;
try {
// 判断是否存在对应目录,不存在的话则创建
File file = new File(ScreenshotPath);
if (!file.exists() || !file.isDirectory()) {
// 没有目录 创建截屏目录
System.out.println("没有screenshot目录,创建目录");
boolean isMkdirSucc = file.mkdir();
if (isMkdirSucc) {
System.out.println("创建screenshot目录成功");
} else {
System.out.println("创建screenshot目录失败");
}
} else {
System.out.println("存在screenshot目录");
}
String time = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
String screenShotName = time + ".png";
screenShotPath = ScreenshotPath + "/" + screenShotName;
driver.saveScreenshot(screenShotPath);
} catch (Exception e) {
// TODO: handle exception
logger.info("Can't save screenshot");
logger.error(e.getMessage());
}
return screenShotPath;
}
总结个人在使用过程中遇到的一些问题,希望能帮助到广大的 macaca 使用者,非常感谢 macaca 的开发者团队能开源这么好的东西给我们使用