更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢!

简介:adb命令是常用的Android命令行,自动化、代码调试、手工排查问题都会用的到,这里将常用的一些命令行封装成为C#函数,在C#的自动化框架中可以直接调用。

详细内容如下:
 
获取当前app页:
adb -s 设备号 shell \dumpsys activity \| findstr mFocusedActivity
查看设备状态:
adb devices
手机截屏保存到电脑:
adb pull /sdcard/screen.jpg screen.jpg
 
唤醒 安卓 Apk:
public static bool WakeupAndroidApk( string activity)
        {
            string output = GetCmdOutput("adb shell \"am start -n " + activity + "\"");
            return output.Contains("Success" );
        }
 
关闭当前 应用: 
         public static bool closeCurrentActivity( string activity)
        {
            string output = GetCmdOutput("adb -s " + udid + " shell \"pm clear " + activity);
            return output.Contains("Success" );
        }
按屏幕坐标点击:
         public static void Tap( int X, int Y)
        {
            GetCmdOutput( String.Format("adb -s {0} shell input tap {1} {2}" , udid, X, Y));
        }
 
检查当前 应用:
         public static bool CheckCurrentActivity( string activity)
        {
            string output = GetCmdOutput("adb -s " + udid + " shell \"dumpsys activity \"");
            string[] lines = output.Split('\n' );
            string target = "" ;
            Regex reg = new Regex( ".*mFocusedActivity.*");
            foreach(string line in lines)
            {
                if (reg.IsMatch(line))
                {
                    target = line;
                    break;
                }
            }
            return target.Contains(activity);
        }
 
 
        /// <summary>
        /// 打开指定浏览器
        /// </summary>
        /// <param name="browserAndroidApk"> 浏览器</param>
        public static void OpenSpecialBrowser( string browserAndroidApk)
        {
            GetCmdOutput( "adb -s " + udid + " shell am start " + browserAndroidApk);
        }
 
        /// <summary>
        /// 按手机屏幕坐标点击
        /// </summary>
        /// <param name="x"> x坐标</param>
        /// <param name="y"> y坐标</param>
        public static void Tap( int x, int y)
        {
            GetCmdOutput( "adb -s " + udid + " shell input tap " + x + " " + y);
        }
 
        public static void Tab()
        {
            GetCmdOutput( "adb -s " + udid + " shell input keyevent 61" );
        }
 
        /// <summary>
        /// 输入keyevent值对应的字符
        /// </summary>
        /// <param name="key"> keyevent值</param>
        public static void Tab( string key)
        {
            GetCmdOutput( "adb -s " + udid + " shell input keyevent " + "key");
        }
 
        /// <summary>
        /// 输入URL地址
        /// </summary>
        /// <param name="URL"> URL地址</param>
        public static void InputURL( string URL)
        {
            GetCmdOutput( "adb -s " + udid + " shell input text " + URL);
        }
 
        public static void Enter()
        {
            GetCmdOutput( "adb -s " + udid + " shell input keyevent 66" );
        }
 
        /// <summary>
        /// 清理指定的浏览器
        /// </summary>
        /// <param name="browserAndroidApk"> 浏览器</param>
        public static void ClearBrowser( string browserAndroidApk)
        {
            GetCmdOutput( "adb -s " + udid + " shell pm clear " + browserAndroidApk);
        }
 
        /// <summary>
        /// 卸载指定的App
        /// </summary>
        /// <param name="APPAndroidApk"> App</param>
        public static void UninstallApp( string APPAndroidApk)
        {
            GetCmdOutput( "adb -s " + udid + " uninstall " + APPAndroidApk);
        }
 
        /// <summary>
        /// 关闭当前进程Activity
        /// </summary>
        /// <param name="activity"> Activity</param>
        /// <returns> 返回清理结果 </returns>
        public static bool closeCurrentActivity( string activity)
        {
            string output = GetCmdOutput("adb -s " + udid + " shell \"pm clear " + activity);
            return output.Contains("Success" );
        }
 
感谢阅读,作者原创技术文章,转载请注明出处

将常用的Android adb shell 命令行封装为C#静态函数的更多相关文章

  1. 自动化测试系列:将常用的Android adb shell 命令行封装为C#静态函数

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 简介:adb命令是常用的Android命令行,自动化.代码调试.手工排查问题都会用的到,这里将常用的一些命令行封装 ...

  2. 【安卓手机通用】android adb shell 命令大全

    浏览:3116 | 更新:2013-10-17 17:05 | 标签:安卓 android 一.[什么是shell] Linux系统的shell作为操作系统的外壳,为用户提供使用操作系统的接口.它是命 ...

  3. Android adb shell命令大全

    1. 显示系统中全部Android平台: android list targets 2. 显示系统中全部AVD(模拟器): android list avd 3. 创建AVD(模拟器): androi ...

  4. android adb shell 命令大全

    1. 显示系统中全部Android平台: android list targets 2. 显示系统中全部AVD(模拟器): android list avd 3. 创建AVD(模拟器): androi ...

  5. adb shell命令行

    d: cd D:\software\adt-bundle-windows-x86-20131030\sdk\platform-tools ————————> sdk的路径 adb shell s ...

  6. Android 常用adb shell 命令

    原文地址http://blog.csdn.net/rain_butterfly/article/details/40894807 调试Android程序有时需要adb shell 命令,adb全称An ...

  7. Android 常用adb shell 命令(转)

    调试Android程序有时需要adb shell 命令,adb全称Android Debug Bridge ,就是起到调试桥的作用. 通过adb我们可以在Eclipse中通过DDMS来调试Androi ...

  8. 【android】android 常用adb 和 adb shell 命令

    db是SDK自带的工具,可实现桥接功能:adb shell 可以与手机系统建立交互,是基于andoid Linux系统下的操作 ADB常用命令: 1. 查看设备         adb  device ...

  9. Android adb shell 常用命令

    Ø  简介 adb 命令是 Android SDK 中自带的一个调试工具,可以调试电脑中的手机或者模拟器,使用 adb 命令前需要将 sdk 中的 platform-tools 目录添加到环境变量中. ...

随机推荐

  1. CodeForces-2015 HIAST Collegiate Programming Contest-Gym-100952A-Who is the winner?

    A. Who is the winner? time limit per test 1 second memory limit per test 64 megabytes input standard ...

  2. C# 构造器总结

    在C#中,构造器分为实例构造器和类型构造器, 一.实例构造器 构造引用类型的对象时,在调用实例 构造器之前,为对象分配的内存总是归0,没有被构造器显示重写的字段都保证获得0或null的值 在一个类中, ...

  3. 内核知识第12讲,SSDT表.以用户模式到系统模式的两种方式.

    内核知识第12讲,SSDT表.以用户模式到系统模式的两种方式. 一丶IDT解析. 我们知道.IDT表中存放着各种中断信息.比如当我们调用int 3的时候,则会调用IDT表中的第三项来进行调用. 而函数 ...

  4. LAMP LNMP 和 LNMPA

    LAMP指的是:Linux+Apache+MySQL+Perl/PHP/Python LAMP是一个缩写,它指一组通常一起使用来运行动态网站或者服务器的自由软件: Linux,操作系统:  Apach ...

  5. Tomcat下的Server.xml配置文件详解

    自15年毕业到现在已经入行两年多了,一直以来没有深入的了解过tomcat的详细配置,只懂修改一下端口号.在网上找了些相关资料来支撑这篇文章,深入了解server.xml文件各配置的作用 <?xm ...

  6. linux 硬软链接区别

    linux 硬软链接区别 linux的软连接(symbolic link or soft link)类似于windows的快捷方式:而硬链接(hard link)机制有点像copy,不过不同的是,带有 ...

  7. CCF系列之矩阵(201512-5)

    试题名称: 矩阵 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 创造一个世界只需要定义一个初状态和状态转移规则. 宏观世界的物体运动规律始终跟物体当前的状态有关,也就是说只要 ...

  8. forward和redirect

    Forward和Redirect代表了两种请求转发方式:直接转发和间接转发. 直接转发方式(Forward),客户端和浏览器只发出一次请求,Servlet.HTML.JSP或其它信息资源,由第二个信息 ...

  9. hdevelop (halcon)处理大分辨率图像问题

    HALCON 的ide有2种模式:hdevelop 和hdevelop xl hdevelop 适用于普通分辨率的图像,小于等于 32k x 32k : hdevelop xl适用于大分辨率的图像,大 ...

  10. Git-远程仓库的使用

    Git修改远程仓库地址 1.修改命令 git remote set-url origin [url] 例如:$ git remote set-url origin gitlab@gitlab.chum ...