[uiautomator篇]recent
def Recent(self): d = Device('9410519008004c22098b') displayWidth = int(d.info.get("displayWidth")) displayHeight = int(d.info.get("displayHeight")) d.press.recent() if d(text="No recent items").wait.exists(timeout=2000): print "Cleared recent items" return True if d(descriptionContains="Dismiss").wait.exists(timeout=2000): for i in range(50): if d(text="CLEAR ALL").wait.exists(timeout=2000): d(text="CLEAR ALL").click() if d(description="Apps list",index=3).wait.exists(timeout=2000): print "Cleared recent items" return True else: print "Fail to clear recent items" return False else: d.swipe(displayWidth/2,displayHeight/4,displayWidth/2,3*displayHeight/4,steps=30) i+=1 else: print "Fail to find CLEAR ALL " return False else: print "EXCEPTION CLEAR RECENT ITEMS" return True
java version
package com.yang.clicktest; import com.android.uiautomator.core.UiDevice; import com.android.uiautomator.core.UiObject; import com.android.uiautomator.core.UiObjectNotFoundException; import com.android.uiautomator.core.UiSelector; import com.android.uiautomator.testrunner.UiAutomatorTestCase; import android.os.RemoteException; public class UiClickTest4 extends UiAutomatorTestCase { public void test() throws RemoteException, UiObjectNotFoundException, InterruptedException{ UiDevice.getInstance().pressRecentApps(); UiObject recentapp = new UiObject(new UiSelector().resourceId("com.android.systemui:id/dismiss_task")); do{ recentapp.waitForExists(2000); if(recentapp.exists()){ recentapp.swipeLeft(5); } }while(recentapp.exists()); } }