本文主要是介绍android studio2.2配置uiautomator2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、 SDK Manager需要安装Android Support Repository。
2、 build.gradle配置(Module中的gradle)
defaultConfig {… …testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
// … …
dependencies {… …/***********************************/androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {exclude group: 'com.android.support', module: 'support-annotations'})androidTestCompile('com.android.support.test.uiautomator:uiautomator-v18:2.1.2', {exclude group: 'com.android.support', module: 'support-annotations'})androidTestCompile('com.android.support.test:rules:0.5', {exclude group: 'com.android.support', module: 'support-annotations'})androidTestCompile('com.android.support.test:runner:0.5', {exclude group: 'com.android.support', module: 'support-annotations'})/***********************************/
}
3、 编写测试类,测试类需要放到“androidTest”下:
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiAutomatorInstrumentationTestRunner;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;import org.junit.runner.RunWith;import static android.support.test.InstrumentationRegistry.getInstrumentation;/****/
@RunWith(AndroidJUnit4.class)
public class ApplicationTest extends UiAutomatorInstrumentationTestRunner {private UiDevice uiDevice;public void testDemo() throws UiObjectNotFoundException {uiDevice = UiDevice.getInstance(getInstrumentation());UiObject btn1 = uiDevice.findObject(new UiSelector().description(""));}
}
这篇关于android studio2.2配置uiautomator2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!