UI Watchは不定時のシャッター問題を解決します.

10987 ワード


縁が来たのはあなたです
UIベースのGoogleライブラリのテストシステムでは、第三者のAPKテスト例に対して、タイミングの悪いパチンコ問題があり、テスト例のロバスト性と安定性に大きな影響を与えました.
この問題を解決するために、GoogleはUICwatch類を開発して解決しました.
Google公式サイト類解析住所を添付します.http://developer-android.ir/tools/help/uiautomator/UiWatcher.html#checkForCondition%28%29
 
                                                                                                                        
 
誰ですか
Public Methods
abstract bollan
checkForCodition()
The testing frame ebork cals this handler method atomatially when the frame ework is unable to find a match using the Ui Selector.
つまり、UiSelectorメソッドにマッチが見つからない場合は、uiwatch類を呼び出します.
 
                                                                                                                        
使用方法:
まずクラスのオブジェクトを定義します.例は以下の通りです.
 1 UiWatcher okCancelDialogWatcher = new UiWatcher() {
 2             @Override   //       3             public boolean checkForCondition() {
 4                 UiObject okCancelDialog = new UiObject(new UiSelector().textStartsWith("Lorem ipsum"));
 5                 if(okCancelDialog.exists()){
 6                     Log.w(LOG_TAG, "Found the example OK/Cancel dialog");
 7                     UiObject okButton = new UiObject(new UiSelector().className("android.widget.Button").text("OK"));
 8                     try {
 9                         okButton.click();
10                     } catch (UiObjectNotFoundException e) {
11                         // TODO Auto-generated catch block
12                         e.printStackTrace();
13                     }
14                     
15                     return (okCancelDialog.waitUntilGone(25000));
16                 }
17                 return false;
18             }
19         };
 
次に役割を果たすには、まず登録してからアプリケーションの前に呼び出す必要があります.
    
         public void register Watch(String name、UiWatch watch)
         Registers a UiWatch to run atomaticaly when the testing frame ork is unable to find a match using a Ui Selector.See run Watch()            パラメータ   name  to register the UIWatch
ウォッチ       スウィッチ
         public void
removeWatch(String name) 
Removes a previously register ed UiWatch.See register Watch(String,UiWatch)     パラメータ    name               used to register the UICWatch
 
     public void reetWatch Triggers()
     Reseets aUiWatch that has been triggered.If a UiWatch runs and itscheckForCondation() call returnedtrue,then the UiWatch is consided triggered.See                  egister Watch(String,UiWatch) 
 
  
public void run Watchers()
  This method forces all registered watch ers to run.Seeregister Watch(String,UiWatch) 
         public book has AnyWatch Triggered()
     Checks if any registedUiWatch have triggered.Seeregister Watch(String,UiWatch) Seehas Watch Triggered(String) 
       public boolean hasWatcherTriggered (String watcherName) has triggerred.See

   Checks if a specific registered UiWatch.If a UiWatch runs and its register Watch(String,UiWatch) cal returned checkForCondation()、then the        UiWatch is consided triggered.This helpful ift a watch is detecting errors from ANR or cras dialogs and the test needs to know if a UiWatch has been triggeed.
     Returns         true if triggered else false
 
                                                            
 
デモ:
テストコード:

public void SendMessage(UiDevice dut, Bundle bundle) throws UiObjectNotFoundException, RemoteException, InterruptedException,UIAException{
		int x=dut.getDisplayWidth();
		int y=dut.getDisplayHeight();
		   Thread.sleep(3000);	
		   UiObject SetNum = new UiObject(new UiSelector().packageName("com.p1.chompsms").resourceId("com.p1.chompsms:id/recipients_field")); //    1 ,        。
		   Thread.sleep(10000);	
		   String phone=bundle.getString("phoneNum");	
		  if(SetNum.exists())
		   SetNum.setText(phone);
		 
		   Thread.sleep(1000);
 
uiwatchコード:
 
public void Game_uiwatcher(UiDevice dut, Bundle bundle) throws UiObjectNotFoundException, UIAException, InterruptedException
{
    //  
    UiWatcher okCancelDialogWatcher = new UiWatcher() {
	@Override
	public boolean checkForCondition() {
		
		System.out.println("uiwatcher run ing.....");
		
		UiObject SetTend= new UiObject(new UiSelector().className("oandroid.widget.LinearLayout").index(1).childSelector(new UiSelector().className("android.widget.TextView").index(0)));		  

		System.out.println("uiwatcher run ing.....");
		if(SetTend.exists()){
			
			
			try {
				SetTend.click();
			} catch (UiObjectNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return (SetTend.waitUntilGone(25000));
		}
		return false;
	}
};
//
UiDevice.getInstance().registerWatcher(MYOKCANCELDIALOGWATCHER_STRING, okCancelDialogWatcher);
 
 }
 
uiwatchは び し に して する があります.
ゲームuiwatch()メソッドを して び します.
 そしてテスト SendMessage()が した に ちます.
 
  
  true

 

 

 

 

 

 

 

 

      

142