我正在使用appium进行测试自动化。我需要将view对象存储到当前应用程序屏幕的位图中。
public Bitmap takeScreenShot(View view) {
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
view.buildDrawingCache();
if(view.getDrawingCache() == null) return null;
Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
view.destroyDrawingCache();
return snapshot;
}
AppiumDriver driver = new AndroidDriver(new URL(""),capabilities);//capabilities and URL are set
WebElement el = driver.findElement(By.id("com.example.app:id/video_view"));
View view = ?? //get view object from el
takeScreenShot(view);
答案 0 :(得分:0)
试试这个,它应该返回类似android.widget.RelativeLayout
的东西(只是一个例子):
View view = el.getAttribute("className"); //get class value of the element