UiAutomator 求助 UIAutomator2 运行是弹 Instrumentation run failed due to 'java.lang.SecurityException'错误

零度 · 2018年03月22日 · 最后由 圈圈 回复于 2019年01月16日 · 2802 次阅读

小弟在运营 uiautomator2 脚本时,一运行脚本就报 Instrumentation run failed due to 'java.lang.SecurityException'错误,求助怎么解决,之前能够运行的脚本 现在重新运行也都报这个错误

03/22 11:07:38: Launching Camera_K5703Q
No apk changes detected since last installation, skipping installation of E:\AndroidStudioProjects\Record\app\build\outputs\apk\debug\app-debug.apk
$ adb shell am force-stop com.lava.record
No apk changes detected since last installation, skipping installation of E:\AndroidStudioProjects\Record\app\build\outputs\apk\androidTest\debug\app-debug-androidTest.apk
$ adb shell am force-stop com.lava.record.test
Running tests

$ adb shell am instrument -w -r -e debug false -e class com.lava.record.Autotest.Camera_K5703Q com.lava.record.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Test running failed: Instrumentation run failed due to 'java.lang.SecurityException'

运行脚本如下:
@RunWith(AndroidJUnit4.class)
//进入相机切换模式拍照
public class Camera_K5703Q
{
UiDevice device;
Instrumentation instrumentation;

//初始化
@Before
public void setUp() {
instrumentation = InstrumentationRegistry.getInstrumentation();
device = UiDevice.getInstance(instrumentation);
}

//脚本代码
@Test
public void test_case() throws IOException {
Assitant assitant = new Assitant();
Log.e(Constants.TAG, Constants.PACKAGE+ Camera_K5703Q.class.getPackage().getName());
Log.e(Constants.TAG, Constants.STARTCASE + getClass().getSimpleName());
Log.e(Constants.TAG, Constants.START_TIME + assitant.getCurrentScreenDate());
Log.e(Constants.TAG, Constants.MODLE + assitant.ismodel());
UiObject shutterPhoto = assitant.findUiobjectById(Res.Camera.shutterPhoto);
UiObject shutterVideo = assitant.findUiobjectById(Res.Camera.shutterVideo);
UiObject W6500 = assitant.findUiobjectByText(Res.Camera.W6500);
UiObject Video = assitant.findUiobjectByText(Res.Camera.shutterVideo);
UiObject meiyan = assitant.findUiobjectByText(Res.Camera.meiyan);
UiObject yepai = assitant.findUiobjectByText(Res.Camera.yepai);
UiObject photo = assitant.findUiobjectByText(Res.Camera.photo);

try {

assitant.UiWatcherException();
device.runWatchers();
assitant.startapp(Res.Camera.packageName,Res.Camera.mainActivity);
assitant.waited(2000);
Log.v(Constants.TAG, "相机 \n");
assitant.waited(2000);

//循环拍照切换模式
for (int i = 0; i < 3; i++) {

for (int j=0;j<3;j++){
shutterPhoto.click();
assitant.waited(2000);
W6500.click();
assitant.waited(2000);
shutterPhoto.click();
assitant.waited(5000);
Video.click();
assitant.waited(2000);
shutterVideo.click();
shutterVideo.click();
assitant.waited(2000);
meiyan.click();
assitant.waited(2000);
shutterPhoto.click();
assitant.waited(2000);
yepai.click();
assitant.waited(2000);
shutterPhoto.click();
assitant.waited(2000);
photo.click();
assitant.waited(2000);

}

}
device.pressBack();
assitant.waited(2000);
device.pressHome();
Log.v(Constants.TAG, "pressHome \n");
assitant.waited(2000);
device.removeWatcher(Res.uiWatcherName);
Log.e(Constants.TAG, Constants.RESULT+ Constants.SUCCESS);
}
catch (Throwable e ) {
assitant.takeShot(getClass().getSimpleName()+"_"+assitant.getCurrentScreenDate(),"exception");
e.printStackTrace();
Log.e(Constants.TAG, "ErrorMsg:" + assitant.getErrorMsg(e));
Log.e(Constants.TAG, Constants.RESULT+Constants.FAIL);
assitant.backtohome(2);
}
finally {
Log.e(Constants.TAG,
Constants.End_TIME + assitant.getCurrentScreenDate());
Log.e(Constants.TAG, Constants.EndCASE + getClass().getSimpleName());
assitant.backtohome(2);
}

}

}

共收到 1 条回复 时间 点赞

求问,解决了这个问题了吗

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册