package com.uia.example.my; import org.apache.http.util.EncodingUtils; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Rect; import android.os.Environment; import com.android.uiautomator.core.UiObject; import com.android.uiautomator.core.UiObjectNotFoundException; import com.android.uiautomator.core.UiScrollable; import com.android.uiautomator.core.UiSelector; import com.android.uiautomator.testrunner.UiAutomatorTestCase; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class TAppWorkAssistV1 extendsUiAutomatorTestCase { public StringsLog; public Filefout =null; public FileOutputStreamoutStream=null; public void write2file(String filename,String sData) { String sLog=""; //初始化記錄檔 if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ sLog = Environment.getExternalStorageDirectory().getAbsolutePath(); try{ fout = new File(sLog,filename); outStream = new FileOutputStream(fout,true); //此處的true是append sData=sData +"\n"; outStream.write(sData.getBytes()); outStream.flush(); outStream.close(); fout=null; } catch(Exception e){ e.printStackTrace(); } }else{ System.out.println("該手機沒有SD卡"); } } public void testDemo() throws UiObjectNotFoundException { //1. 啟動app getUiDevice().pressHome(); UiObject allAppsButton = new UiObject(new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow(); UiObject appsTab = new UiObject(new UiSelector().text("Apps")); appsTab.click(); UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true)); UiObject settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()),"Efilm"); settingsApp.clickAndWaitForNewWindow(); //2. 進入主介面 System.out.println("into main view"); System.out.println(getUiDevice().waitForWindowUpdate("com.eshore.efilm", 60000)); System.out.println("intoed main view"); UiObject tv1 = new UiObject(new UiSelector().text("影院")); tv1.click(); //3.點擊影院 UiObject oyy= new UiObject(new UiSelector().description("cinema_row")); System.out.println("wait yingyuan come out"); oyy.waitForExists(60000); System.out.println("yingyuan come out"); oyy.clickAndWaitForNewWindow(); System.out.println("click yingyuan"); //4.場次 UiObject occ= new UiObject(new UiSelector().description("LinearLayout10")); System.out.println("wait changci come out"); oyy.waitForExists(60000); System.out.println("changci come out"); occ.clickAndWaitForNewWindow(); System.out.println("click changci"); //5.座位 UiObject oseat= new UiObject(new UiSelector().description("cinema_shows_list_item").index(0).childSelector(new UiSelector().description("LinearLayout10"))); System.out.println("wait seat come out"); oseat.waitForExists(5000); int h=getUiDevice().getDisplayHeight(); int w=getUiDevice().getDisplayWidth(); System.out.println("(h/2,w/2)="+h/2+","+w/2); getUiDevice().click(h/2,w/2); //System.out.println("seat count:"+String.valueOf(oseat.getChildCount())); //System.out.println("seat getText:"+ oseat.getText()); //截座位元影像 Process process; try { process = Runtime.getRuntime().exec("screencap /mnt/sdcard/EfilmFailSnapShot01.png"); try { process.waitFor(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //takeScreenShots("EfilmSeatSnapShot"); } } |