APP自动化环境脚本(bilibili)_xing2516_新浪博客

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver

caps = {}
caps["deviceName"] = "127.0.0.1:62001"
caps["platformName"] = "Android"
caps["appPackage"] = "tv.danmaku.bili"
caps["appActivity"] = "tv.danmaku.bili.ui.splash.SplashActivity"

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

el2 = driver.find_element_by_id("tv.danmaku.bili:id/app_bar")
el2.click()
el3 = driver.find_element_by_accessibility_id("搜索查询")
el3.click()
el3.send_keys("B站晚会")
el4 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout")
el4.click()
driver.press_keycode(66, undefined, undefined);
el5 = driver.find_element_by_id("tv.danmaku.bili:id/play_button")
el5.click()

driver.quit()


##网易云音乐app
from appium import webdriver
import time

caps = {}
caps["deviceName"] = "127.0.0.1:62001"#连接本机模拟器
caps["platformName"] = "Android"#app所处平台
caps["appPackage"] = "com.netease.cloudmusic"#被测app包名
caps["appActivity"] = ".activity.LoadingActivity"#被测app入口
caps["noReset"] = True # 禁止app在自动化后重置 一些设置(权限等)
caps["newCommandTimeout"] = 3600#连接超时时间 秒
caps["autmationName"] = "UiAutomator2"#指定新驱动UI2

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)#驱动appuim
driver.implicitly_wait(10)
#el1=driver.find_element_by_link_text('每日推荐').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@text="每日推荐"]').click()
#songs=driver.find_elements_by_id("com.netease.cloudmusic:id/ata")[:3]
#songs=songs=driver.find_elements_by_class_name("android.widget.LinearLayout")
#songs=driver.find_element_by_id('com.netease.cloudmusic:id/acx')
aa=driver.find_elements_by_xpath('//*[@text="所念皆星河"]')

for song in aa:
print(song.text)

#driver.quit()

连接夜神模拟器

adb connect 127.0.0.1:62001

 

查找app包名

adb shell dumpsys activity recents | findstr intent

一般cmp后是包名和app入口,cmp=com.netease.cloudmusic/.activity.LoadingActivity

 

Python  安装pip install Appium-Python-Client Selenium

2 自动化测试涉及到的一些基本操作

2.1 查找元素:find_element_by_id,find_element_by_xpath 这两个方法比较常用
2.2 模拟键盘的回车操作 driver.press_keycode(66)
2.3 元素的点击事件ele.click()
2.4模拟输入信息ele.send_keys("输入的内容")
2.5由于网络或者其他原因,到时对应的元素还没有出来,这个时候如果直接获取数据会报错,可以设置固定的等待时间driver.implicitly_wait(3) ,值得单位是秒。这样不需要用sleep的方式



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值