hxdlovewb
hxdlovewb
2017-08-01 05:23

UIautomator 测试脚本 可运行,运行不正常,不停止。代码如下

  • 脚本
  • 测试

package com.example.helloworld.test;

import java.io.File;
import java.security.PublicKey;

import android.os.RemoteException;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class TestForMcLTEContact1 extends UiAutomatorTestCase{
public void testformcltecontact1() throws RemoteException {
try {
while (UiDevice.getInstance().isScreenOn()) {
//System.out.println("灭屏状态");
// }else{
if (new UiObject(new UiSelector().description("应用")).exists()) {
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/1.png"));
new UiObject(new UiSelector().description("应用")).click();
if (new UiObject(new UiSelector().text("集群")).exists()) {
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/2.png"));
new UiObject(new UiSelector().text("集群")).click();
if (new UiObject(new UiSelector().resourceId("com.bjkyhx.McLTE:id/main_contacts")).exists()) {
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/4.png"));
UiDevice.getInstance().pressHome();
UiDevice.getInstance().sleep();
}
}
else {
UiDevice.getInstance().swipe(300, 300, 400, 500, 50);
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/3.png"));
new UiObject(new UiSelector().text("集群")).click();
if (new UiObject(new UiSelector().resourceId("com.bjkyhx.McLTE:id/main_bottom")).exists()) {
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/5.png"));
}
}

            }
        }
    } catch (Exception e) {
        // TODO: handle exception
        //System.out.println(e.toString());
    }
}

}
调了一上午了,求解答!
图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答