Robotium截圖設置

Robotium截圖設置

1、前提條件

在被測試的應用中添加對SD卡的讀寫權限,文件爲AndroidManifest.xml,添加以下標示

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>


2、使用solo的takeScreenshot方法來截取當前頁面


takeScreenshot

public void takeScreenshot()
Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.


使用該方法時,如果文件目錄不存在,則會自動創建,且生成的圖片文件格式如下

271113-054228.jpg, 其中27爲日,11爲月,13爲年,其他的爲時分秒,且文件默認格式爲jpg

代碼實現爲:

solo.sleep(10000) ;
        solo.takeScreenshot() ;
        solo.sleep(1000) ;



takeScreenshot

public void takeScreenshot(String name)
Takes a screenshot and saves it with the specified name in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.
Parameters:
name - the name to give the screenshot


使用該方法時,可以自定義生成的文件名字,且可以自動創建文件目錄

代碼實現爲:

solo.sleep(10000) ;
        solo.takeScreenshot("test") ;
        solo.sleep(1000) ;

生成的文件爲test.jpg



takeScreenshot

public void takeScreenshot(String name,
                           int quality)
Takes a screenshot and saves the image with the specified name in "/sdcard/Robotium-Screenshots/". Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.
Parameters:
name - the name to give the screenshot
quality - the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality)


使用該方法可以對生成的圖片進行壓縮,大小從0到100,值越小越失真

代碼實現:

solo.sleep(10000) ;
        solo.takeScreenshot("test100",100) ;
        solo.sleep(1000) ;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章