• Appium + Python 测试 QQ 音乐 APP的一段简单脚本


    1. 大致流程

    +  程序(Python):打开 QQ 音乐,点击一系列接收按键,进入搜索音乐界面,输入『Paradise』,播放第一首音乐。
    

    2. Python 脚本如下

    
    from appium import webdriver
    import time
    
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    
    #  adb shell getprop ro.build.version.release 获得版本号
    desired_caps['platformVersion'] = '6.0'      
    
    desired_caps['deviceName'] = 'Android Emulator'
    #  adb shell dumpsys package packages | grep  "Package ["     获取已安装的 appPackage Name
    desired_caps['appPackage'] = 'com.tencent.qqmusic'
    
    # adb shell dumpsys activity activities | grep  "realActivity"  获得 appActivity
    desired_caps['appActivity'] = '.activity.AppStarterActivity'
    
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    
    # 一系列点击
    # page1  SD
    driver.find_element_by_id('com.tencent.qqmusic:id/y3').click()
    time.sleep(1)
    
    # page2   电话 com.android.packageinstaller:id/permission_allow_button
    driver.find_element_by_id('com.android.packageinstaller:id/permission_allow_button').click()
    # driver.findElementByXPath("//android.widget.Button[@text='始终允许']").click();
    time.sleep(1)
    
    # page3
    driver.find_element_by_id('com.android.packageinstaller:id/permission_allow_button').click()
    time.sleep(1)
    
    # page4  com.tencent.qqmusic:id/v3 跳过
    driver.find_element_by_id('com.tencent.qqmusic:id/v3').click()
    time.sleep(1)
    
    # page5  取消登录
    driver.find_element_by_id('com.tencent.qqmusic:id/lh').click()
    time.sleep(1)
    
    # page6  点击收缩
    driver.find_element_by_id('com.tencent.qqmusic:id/t3').click()
    time.sleep(1)
    
    # page7  
    driver.find_element_by_id('com.tencent.qqmusic:id/a7j').click()
    search_box = driver.find_element_by_id('com.tencent.qqmusic:id/a7j')
    search_box.click()
    search_box.send_keys('paradise')  # 输入检索的歌名,不支持中文(好像?)
    time.sleep(2)
    
    # com.tencent.qqmusic:id/cb3
    driver.find_element_by_id('com.tencent.qqmusic:id/cb3').click()
    time.sleep(1)
    
    # com.tencent.qqmusic:id/a55
    driver.find_element_by_id('com.tencent.qqmusic:id/a55').click()
    time.sleep(1)
    
    
    

    3. 程序运行视频(录屏)

  • 相关阅读:
    洛谷 P2327 [SCOI2005]扫雷 题解
    P1388 算式 题解
    P1281 书的复制 题解
    P2896 [USACO08FEB]一起吃饭Eating Together 题解
    P1140 相似基因 题解
    变量的解构赋值
    let 和 const 命令
    第一阶段站立会议8
    第一阶段站立会议7
    第一阶段站立会议6
  • 原文地址:https://www.cnblogs.com/juking/p/9539239.html
Copyright © 2020-2023  润新知