• [UiAutomator篇][3] 打开音乐应用的测试脚本


    package qq.test;
    
    
    import android.content.Context;
    import android.content.Intent;
    import android.support.test.InstrumentationRegistry;
    import android.support.test.filters.SdkSuppress;
    import android.support.test.runner.AndroidJUnit4;
    import android.support.test.uiautomator.By;
    import android.support.test.uiautomator.UiDevice;
    import android.support.test.uiautomator.Until;
    
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    
    import static org.hamcrest.core.IsNull.notNullValue;
    import static org.junit.Assert.assertThat;
    
    /**
     * Instrumentation test, which will execute on an Android device.
     *
     * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
     */
    @RunWith(AndroidJUnit4.class)
    @SdkSuppress(minSdkVersion = 18)
    public class ChangeTextBehaviorTest {
    
        private static final String BASIC_SAMPLE_PACKAGE
                = "com.android.music";
        private static final int LAUNCH_TIMEOUT = 5000;
        private static final String STRING_TO_BE_TYPED = "UiAutomator";
        private UiDevice mDevice;
    
        public void startMainActivityFromHomeScreen() {
            // Initialize UiDevice instance
            mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    
            // Start from the home screen
            mDevice.pressHome();
    
            // Wait for launcher
            final String launcherPackage = mDevice.getLauncherPackageName();
            assertThat(launcherPackage, notNullValue());
            mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
                    LAUNCH_TIMEOUT);
    
            // Launch the app
            Context context = InstrumentationRegistry.getContext();
            final Intent intent = context.getPackageManager()
                    .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
            // Clear out any previous instances
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            context.startActivity(intent);
    
            // Wait for the app to appear
            mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
                    LAUNCH_TIMEOUT);
        }
        @Test
        public void testMusic(){
            startMainActivityFromHomeScreen();
        }
    
    }
    
  • 相关阅读:
    deepin linux 安装 mysql
    Django根据现有数据库建立model
    轻松学习正则表达式
    ubuntu 下安装 wxpython2.8
    Robot framework + appium环境搭建
    使用 robotframework 自动化测试系列 二 -----环境搭建
    使用 robotframework 自动化测试系列 一 -----简介
    执行robot framework 的测试用例 命令行pybot使用方式
    SQLAlchemy的使用---外键ForeignKey数据库创建与连接
    SQLAlchemy的使用---增删改查
  • 原文地址:https://www.cnblogs.com/liuzhipenglove/p/6837484.html
Copyright © 2020-2023  润新知