Appium 手机app自动化测试

在学习了Python之后,这两天写了一个小的自动化程序来一起分享。

首先说明的是,图片你需要上传到你的模拟器上面。

# 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

# http://appium.io/docs/en/writing-running-appium/caps/index.html
import os
from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time

caps = {}
caps["automationName"] = "UiAutomator2"
caps["platformName"] = "Android"
caps["deviceName"] = "127.0.0.1:21503"  # 使用自己的手机devices name

caps['noReset'] = True
caps['fullReset'] = False
caps['appPackage'] = "com.sina.weibolite"
caps['appActivity'] = "com.sina.weibo.SplashActivity"

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
driver.implicitly_wait(30)
import os
jpgfile = os.path.join(os.path.dirname(__file__),'helloworld.jpg')
# 推送图片
driver.push_file('/sdcard/DCIM/helloworld.jpg',source_path=jpgfile)
#
while True:
    try:
        create_btn_android = 'new UiSelector().className("android.widget.TextView").index(0).resourceId("com.sina.weibolite:id/titleSave")'
        driver.find_element_by_android_uiautomator(create_btn_android).click()
        break
    except NoSuchElementException:
        driver.find_element_by_android_uiautomator('new UiSelector().text("不了,谢谢").index(0)').click()

weibo_content = """
今天搭建一起做app 自动化测试,学习了很多知识。

学习了如下内容:
1.appium 环境配置
2.元素定位
3.自动发微博
"""

edit_id='com.sina.weibolite:id/edit_view'
driver.find_element_by_id(edit_id).send_keys(weibo_content)

# 发图片
image_android = 'new UiSelector().resourceId("com.sina.weibolite:id/tvTitle").text("相册").index(1)'
driver.find_element_by_android_uiautomator(image_android).click()

# 选择第一张
first_image_android = 'new UiSelector().resourceId("com.sina.weibolite:id/photo_album_grideview_item_select").index(2)'
driver.find_element_by_android_uiautomator(first_image_android).click()


driver.find_element_by_accessibility_id('下一步').click()


driver.find_element_by_id('com.sina.weibolite:id/btn_confirm_edit').click()

send_btn_android='new UiSelector().resourceId("com.sina.weibolite:id/titleSave").text("发送").index(0)'

driver.find_element_by_android_uiautomator(send_btn_android).click()

driver.quit()

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值