2016-04-07 21 views
0

私はテストの自動化のためにappiumを使用しています。私はビットマップに現在のアプリの画面を格納するビューオブジェクトが必要です。appiumのリソースIDからビューオブジェクトを取得するにはどうすればよいですか?

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

あなたは 'WebElement el'ため' android.view.View'を取得したいですか? – nullpointer

+0

はい、それは私が欲しいものです – Gsquare

+0

あなたの基本目的は何で、なぜ要素の 'View'型が必要ですか? – nullpointer

答えて

0

はこれを試してみてください、それがandroid.widget.RelativeLayout のようなもの(単なる例)を返す必要があります:

View view = el.getAttribute("className"); //get class value of the element 
+0

'el'オブジェクトに対して' findelements() 'メソッドしか得られません。 – Gsquare

+1

@Gsquare:あなたは' driver'に対して試していると思いますし、メソッドは 'WebElement'のために定義されています。 – nullpointer

+0

はい、そうです。しかし、 'e1.getAttribute(" className ")'は文字列を返します。 'View'オブジェクトにどのように割り当てるのですか? – Gsquare

関連する問題