Appium基础学习之 | UiAutomator与Junit的关系

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ouyanggengcheng/article/details/86301516

在《Appium基础学习之 | UiAutomator使用》文章中大概介绍了UiAutomator的使用,把代码打包成jar后推送到Android设备上并运行。然后在回顾一下《Appium基础学习之 | Appium执行日志流程分析》中讲解到的,Appium其中一个重要的步骤就是把一个Bootstrap.jar推送到Android设备,这样结合来说,应该更好的理解Appium与UiAutomator的关系了吧。Bootstrap.jar就如在使用UiAutomator中代码通过ant打包后形成的jar,那么在看看Appium的执行日志,是如何运行Bootstrap.jar的。

如上图,看shell命令,很清楚了,跟在使用UiAutomator中运行是一样的。

接下来再继续看看UiAutomator又是基于什么运行的呢?在使用UiAutomator的时候,需要extends继承UiAutomatorTestCase类,所以来看UiAutomator的UiAutomatorTestCase源码:

package com.android.uiautomator.testrunner;

import android.content.Context;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.view.inputmethod.InputMethodInfo;

import com.android.internal.view.IInputMethodManager;
import com.android.uiautomator.core.UiDevice;

import junit.framework.TestCase;

import java.util.List;

/**
 * UI automation test should extend this class. This class provides access
 * to the following:
 * {@link UiDevice} instance
 * {@link Bundle} for command line parameters.
 * @since API Level 16
 */
public class UiAutomatorTestCase extends TestCase {

...........代码省略

}

看上面代码,发现UiAutomatorTestCase实际上是extends继承TestCase,而从import来看,TestCase是属于junit中的类,这里就可以得到结论,所有的执行都是交给Junit来执行的。

其他关于UiAutomator源码分析请参考:https://blog.csdn.net/zhubaitian/column/info/uiautomatorpriciple

猜你喜欢

转载自blog.csdn.net/ouyanggengcheng/article/details/86301516