|
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= "";
Initializing log files
if (Environment. getexternalstoragestate (). Equals (Environment. media_mounted)) {
SLOG = environment. getexternalstoragedirectory (). GetAbsolutePath ();
Try {
Fout = new File (slog,filename);
OutStream = new fileoutputstream (Fout,true); The true here is append
Sdata=sdata + "\ n";
Outstream.write (Sdata.getbytes ());
Outstream.flush ();
Outstream.close ();
fout=null;
}
Catch (Exception e) {
E.printstacktrace ();
}
}Else{
System. out. println ("The phone does not have an SD card");
}
}
Public void Testdemo () throws uiobjectnotfoundexception {
1. Launch 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. Enter the main interface
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 ("Cinema"));
Tv1.click ();
3. Click Cinema
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. Matches
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. Seating
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 ());
Seat-cut Map
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");
}
}
|