UiAutomator 简单测试脚本示例

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;

public class UiClickTest extends UiAutomatorTestCase {


    public void testClick() throws UiObjectNotFoundException{             // case名需要以 test 打头
        pressBack();     // 执行case前先返回退出之前的页面
        UiDevice.getInstance().pressHome();     // 回到home页面
        
        UiObject alarm = new UiObject(new UiSelector().resourceId("com.sec.android.app.clockpackage:id/alarm_item"));
        
        alarm.clickBottomRight();
        
        UiObject cancel = new UiObject(new UiSelector().resourceId("com.sec.android.app.clockpackage:id/Menu_Cancel"));
        
        cancel.click();

    }
    
    public void test2() throws UiObjectNotFoundException{
        pressBack();
        UiDevice.getInstance().pressHome();
        UiObject Contacts = new UiObject(new UiSelector().text("Contacts"));
        Contacts.dragTo(150, 250, 5);
    }
    
    

    
    public void test3() throws UiObjectNotFoundException{
        pressBack();
        UiDevice.getInstance().pressHome();
        UiObject Contacts = new UiObject(new UiSelector().text("Contacts"));
        Contacts.dragTo(150, 250, 5);
    }
    
    public void test_not_found_test(){
        assertTrue(true);
    }
    
    void pressBack(){
        UiDevice.getInstance().pressBack();
        UiDevice.getInstance().pressBack();
        UiDevice.getInstance().pressBack();
        UiDevice.getInstance().pressBack();
        UiDevice.getInstance().pressBack();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值