9q13nh 发表于 2024-8-17 18:16:53

手把手教你运用Python操控手机微Xapp(最新教程)


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">/1 前言/</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> <span style="color: black;">近期</span>在做手机APP自动化测试,<span style="color: black;">必须</span>安appium,并配置环境变量,网上虽然有<span style="color: black;">非常多</span>教程,<span style="color: black;">然则</span>随着版本的更新总有<span style="color: black;">各样</span>各样的坑,本文以亲身踏坑经历给<span style="color: black;">大众</span><span style="color: black;">仔细</span>介绍一下<span style="color: black;">怎样</span>正确安装appium。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">/2 <span style="color: black;">第1</span>步:安装Adroid SDK/</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 1、<span style="color: black;">根据</span>网上的教程,先下载Adroid SDK,网址为</p>https://www.androiddevtools.cn/,如下图所示。
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/c9e5cd3299aa4996b578f7931ea1299f~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=tOuASviOZnpGybF0mYUSfsjzUIM%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 2、下载过程很顺利,如下图所示。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/c1898d7aba0f4404988e9b69f894c7b4~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=ztxHVCXQOOgo1R6kaa7%2F03Y%2Bwvw%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 3、之后点击SDK Manager.exe文件,<span style="color: black;">发掘</span>没反应。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/e0fd786dfc1a4a4d81d821cc73cee259~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=wPdHvaasBu%2FkmR%2FfkILlLZnN9os%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 4、遂百度寻找答案,大多<span style="color: black;">处理</span>办法如下图所示:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/6fad4e95e88344c5aad6b910f5436197~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=vG1pZ8bInbG0wD4Sk7rEeS2j2Vw%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">5、然而<span style="color: black;">根据</span><span style="color: black;">以上</span><span style="color: black;">过程</span>并<span style="color: black;">无</span>“神奇”的打开,这个问题让我纠结了一下午,最后我不得不跳出这个坑,<span style="color: black;">选取</span>安装Android Studio,<span style="color: black;">由于</span>在它里面<span style="color: black;">亦</span><span style="color: black;">能够</span>安装Adroid SDK,下载<span style="color: black;">位置</span>为</p>http://www.android-studio.org/,<span style="color: black;">全部</span>下载过程很顺利,安装过程<span style="color: black;">亦</span>很顺利,<span style="color: black;">然则</span>到最后弹出如下错误:

    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/f1e45324052f4556a94aefc9be103a85~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=6L2zbd4VV1YnAqJnp98S4A7G6xE%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">6、<span style="color: black;">原由</span>是<span style="color: black;">第1</span>次安装,<span style="color: black;">起步</span>后,检测到电脑<span style="color: black;">无</span>SDK。<span style="color: black;">第1</span>个<span style="color: black;">处理</span>办法是在安装的目录下找到:bin\idea.properties打开(用记事本)这个文件末尾添加一行disable.android.first.run=true,<span style="color: black;">而后</span>就<span style="color: black;">能够</span>打开Android Studio了,<span style="color: black;">然则</span>这个<span style="color: black;">办法</span>治标不治本,只能顺利打开这个软件,<span style="color: black;">然则</span><span style="color: black;">不可</span>安装SDK。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">7、第二个<span style="color: black;">处理</span>办法是,不翻墙的<span style="color: black;">状况</span>下,<span style="color: black;">通常</span>都是修改host文件:C:\Windows\System32\drivers\etc\hosts,如下图所示。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/58aa5cba42c746f8b12a36e3e34b0eb3~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=z9ceNDJujHBOC2atTSG2nVz4zBI%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 8、在最下面加如上两行命令,再打开Android Studio就能用了,在Android Studio软件下面这个界面<span style="color: black;">能够</span>下载安装所需的Android版本,这一步到此就大功告<span style="color: black;">成为了</span>。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/6200f3f10eb646c49ff24306ad3a037f~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=p%2B27G7W9Crs8bqB3%2F7ricfVg3y0%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">/3 第二步:下载安装JAVA/</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">网址为</p>https://www.oracle.com/technetwork/java/javase/downloads/index.html,我安装的是jdk-13.0.1,<span style="color: black;">根据</span>如下配置环境变量:

    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1、系统变量名:JAVA_HOME,变量值:C:\Program Files\Java\jdk-13.0.1;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2、系统变量名:CLASSPATH,变量值:%java_home%\lib。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">然则</span>网上<span style="color: black;">非常多</span>教程CLASSPATH的变量值为:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p6-sign.toutiaoimg.com/pgc-image/4157883fbf1f4ab5b0ab551d0ccfd674~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=DRATmud2FLYr%2FILaOTbWq6dwamo%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这是老版本的环境变量配置方式,新版本jdk-13.0.1文件夹下是<span style="color: black;">无</span>dt.jar和tools.jar的,<span style="color: black;">大众</span><span style="color: black;">必定</span>要<span style="color: black;">重视</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">/4 第三步:安装appium/</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1、这一步比较简单,基本<span style="color: black;">无</span>坑,直接在appium官网下载安装<span style="color: black;">就可</span>,打开后如下图所示。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/023a1a4f9c634b1cbf36c0324a13b5fb~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=RhqHn7Is9VocFkx5Pc60fLVK%2BFc%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 2、点击Start Server v1.8.1,进入如下界面,如下图所示。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/4462cbe871634a059c1e50161ba7e06e~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=8oYxnM3JaFwymcpNj3QN6%2BhhPYY%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">我<span style="color: black;">已然</span>配置好了参数,platformName为系统类型,deviceName为手机型号,appPackage和appActivity都<span style="color: black;">表率</span>手机app的标志,此处<span style="color: black;">表率</span><span style="color: black;">微X</span>app,点击Start Session。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 3、手机界面就<span style="color: black;">表示</span>出来了,<span style="color: black;">已然</span>打开了<span style="color: black;">微X</span>,到这一步appium安装及环境搭建<span style="color: black;">已然</span><span style="color: black;">所有</span>完成,如下图所示。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/dd7beaf3c24849f18c0b1a3fe36a799b~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=bCH37ydD0Lsqm98Us%2FIBh4TLbGw%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">/5 第四步:撸代码/</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 1、部分代码截图如下图所示。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/60fc6d2b14c24114a3edbec12b19c854~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=EYsXxlE%2F%2BMeDCHoiAM4l94nLSjc%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2、执行此代码<span style="color: black;">亦</span><span style="color: black;">能够</span>如第三步<span style="color: black;">同样</span>打开<span style="color: black;">微X</span>登录界面,下面就<span style="color: black;">能够</span>像selenium操作网页一样用appium对<span style="color: black;">微X</span>app界面的元素执行点击、输入等操作了,<span style="color: black;">倘若</span>不<span style="color: black;">晓得</span>某个按键的元素,<span style="color: black;">能够</span>在appium客户端点击某按钮,<span style="color: black;">而后</span>它的元素信息就在右侧<span style="color: black;">表示</span>出来了,如下图所示。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/8d907c81dfb4432d8ccbc9cda43c9d9f~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723894229&amp;x-signature=GnWUs2Htn0e2cFBemmxXmrYkNS4%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">此刻</span>你就<span style="color: black;">能够</span>随心所欲的对<span style="color: black;">微X</span>进行自动化测试了。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">/6 结语/</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">本文<span style="color: black;">重点</span>介绍了<span style="color: black;">运用</span>Python代码实现操控手机<span style="color: black;">微X</span>app,教程写的相对<span style="color: black;">基本</span><span style="color: black;">有些</span>,<span style="color: black;">然则</span>部分细节方面还是节省了<span style="color: black;">非常多</span>,<span style="color: black;">大众</span>在尝试的过程中肯定还会有<span style="color: black;">各样</span>问题。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> <span style="color: black;">另一</span>本文<span style="color: black;">触及</span>的Pyhton代码,我<span style="color: black;">已然</span>上传到Github了,感兴趣的小伙伴们,<span style="color: black;">能够</span>去<span style="color: black;">瞧瞧</span>,觉得不错,记得给个Star噢!</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 感谢<span style="color: black;">大众</span>的阅读!</p>




4lqedz 发表于 2024-9-26 10:01:09

楼主的文章非常有意义,提升了我的知识水平。

wrjc1hod 发表于 2024-10-25 03:45:55

我深感你的理解与共鸣,愿对话长流。

m5k1umn 发表于 2024-11-5 08:21:16

楼主的文章非常有意义,提升了我的知识水平。
页: [1]
查看完整版本: 手把手教你运用Python操控手机微Xapp(最新教程)