Appium独立测试自动化初始化脚本

news2024/9/24 8:30:46

1、查看环境初始化参数

确保appium已经开起来了,设置ip ,并点击启动

打开夜神模拟器,点击工具--设置

最下面的版本说明,双击进去

版本号这里再去单击。

直到进入到开发者模式。

可能我们不是开发者模式打开的状态,所以软件访问模拟器时,它有可能不让我们连。

要重启一下模拟器

重启模拟器之后,开发者模式才能生效。

此时再用命令行查看,可以看到设备号。

caps={
        'platformName':'Android',               #设置platformName:手机系统名称Android
        'platformVersion':'7.1.2',              # #设置platformVersion:手机系统版本
        'deviceName':'127.0.0.1:52001' ,        #设置deviceName:设备名称
        'appPackage':'uni.UNI765428A',          #设置appPackage:被测程序包名
        'appActivity':'io.dcloud.PandoraEntry'  #设置appActivity:被测程序活动名
}

手机端参数查看命令有那些。每个人设备及端口号不一样,所以需要单独看。

adb  devices

查看包名

adb shell dumpsys activity activities |findstr mFocusedActivity

打开appium Inspector ,开始定位元素。

比如这个id,先点1混合定位模式,再点2开始定位,点3要定位的元素,最后拷贝它的id或者xpath

定位命令和web没什么不同

driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()

2、test_loginV1.py  跑通流程

先导入必备的包及写上版本说明

#*****************************************
#v1.0:app独立自动化测试 脚本--初始化登录
#*****************************************
#导入类库
import time

from appium.webdriver.webdriver import WebDriver
from appium.webdriver.webdriver import By
#手机参数初始化
#查询程序包名的命令:adb shell dumpsys activity activities| findstr mFocusedActivity#设置appPackage:被测程序包名

定义程序包名的参数


caps={
        'platformName':'Android',               #设置platformName:手机系统名称Android
        'platformVersion':'7.1.2',              # #设置platformVersion:手机系统版本
        'deviceName':'127.0.0.1:52001' ,        #设置deviceName:设备名称
        'appPackage':'uni.UNI765428A',          #设置appPackage:被测程序包名
        'appActivity':'io.dcloud.PandoraEntry'  #设置appActivity:被测程序活动名
}
#启动appium
driver=WebDriver('http://127.0.0.1:4723/wd/hub',caps)

点击允许按钮

#进行元素定位
#点击允许按钮
time.sleep(3)
driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()

#允许电话管理

time.sleep(2)
driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
#输入后台服务器地址

time.sleep(5)
xpath_service='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[1]/android.view.View/android.widget.EditText'
servicepath='https://lefeiwisdom-3pt-2t6a7-www.vip.51env.net'
driver.find_element(By.XPATH,xpath_service).clear()
time.sleep(1)
driver.find_element(By.XPATH,xpath_service).send_keys(servicepath)
#点击确定按钮
time.sleep(3)
xpath_ok="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[2]"
driver.find_element(By.XPATH,xpath_ok).click()
#点击验证码登录按钮

xpath_check='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[4]'
driver.find_element(By.XPATH,xpath_check).click()
time.sleep(2)
#输入手机号码
xpath_phone='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[5]/android.view.View/android.widget.EditText'
# id_phone='c52abd0b-3c7b-4b6f-a2a0-f386d56bebd8'
driver.find_element(By.XPATH,xpath_phone).send_keys('13800138001')
time.sleep(2)
#输入验证码
xpath_checkcode='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[6]/android.view.View/android.widget.EditText'
driver.find_element(By.XPATH,xpath_checkcode).send_keys('111111')
#接受协议
xpath_allow='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[9]'
time.sleep(2)
driver.find_element(By.XPATH,xpath_allow).click()
#登录按钮

time.sleep(2)
xpath_login='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[8]'
driver.find_element(By.XPATH,xpath_login).click()

完成登录

3、test_loginV2.py 面向过程的封装

#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法2:普通用户登录

传递参数driver

#*****************************************
#v2.0:app独立自动化测试 脚本--初始化登录
#优化:面向过程的封装
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法2:普通用户登录
#****************************************
#导入类库
import time
from appium.webdriver.webdriver import WebDriver
from appium.webdriver.webdriver import By
#方法0:手机驱动参数初始化
def test_cpas_init():
        # 手机参数初始化
        # ******************************************************************************************
        # 查询程序包名的命令:adb shell dumpsys activity activities| findstr mFocusedActivity#设置appPackage:被测程序包名
        caps = {
                'platformName': 'Android',  # 设置platformName:手机系统名称Android
                'platformVersion': '7.1.2',  # #设置platformVersion:手机系统版本
                'deviceName': '127.0.0.1:52001',  # 设置deviceName:设备名称
                'appPackage': 'uni.UNI765428A',  # 设置appPackage:被测程序包名
                'appActivity': 'io.dcloud.PandoraEntry'  # 设置appActivity:被测程序活动名
        }

        # 启动appium
        driver = WebDriver('http://127.0.0.1:4723/wd/hub', caps)
        # **********************************************************************************
        return driver

#方法1:两个允许按钮+服务器地址+验证码登录
def test_login_init(driver):
         #进行元素定位
        #点击允许按钮
        time.sleep(2)
        driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
        #允许电话管理
        time.sleep(2)
        driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
        #*****************************************************************
        #输入后台服务器地址
        time.sleep(5)
        xpath_service='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[1]/android.view.View/android.widget.EditText'
        servicepath='https://lefeiwisdom-3pt-2t6a7-www.vip.51env.net'
        driver.find_element(By.XPATH,xpath_service).clear()
        time.sleep(1)
        driver.find_element(By.XPATH,xpath_service).send_keys(servicepath)
        #点击确定按钮
        time.sleep(3)
        #***********************************************************************
        xpath_ok="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[2]"
        driver.find_element(By.XPATH,xpath_ok).click()
        #***********************************************************************
        #点击验证码登录按钮
        time.sleep(4)
        xpath_check='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[4]'
        driver.find_element(By.XPATH,xpath_check).click()
        time.sleep(2)
        #********************************************************************************

#方法2:普通用户登录
def user_login_login(driver):
        #输入手机号码
        xpath_phone='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[5]/android.view.View/android.widget.EditText'
        # id_phone='c52abd0b-3c7b-4b6f-a2a0-f386d56bebd8'
        driver.find_element(By.XPATH,xpath_phone).send_keys('13800138001')
        time.sleep(2)
        #输入验证码
        xpath_checkcode='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[6]/android.view.View/android.widget.EditText'
        driver.find_element(By.XPATH,xpath_checkcode).send_keys('111111')
        #接受协议
        xpath_allow='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[9]'
        time.sleep(2)
        driver.find_element(By.XPATH,xpath_allow).click()
        #登录按钮
        time.sleep(2)
        xpath_login='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[8]'
        driver.find_element(By.XPATH,xpath_login).click()

if __name__ == '__main__':
    driver=test_cpas_init()
    test_login_init(driver)
    user_login_login(driver)

4、test_loginV3.py    作者登录

#v3.0:app独立自动化测试 脚本--初始化登录
#优化:面向过程的封装
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法3:作者登录
#*****************************************
#v3.0:app独立自动化测试 脚本--初始化登录
#优化:面向过程的封装
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法3:作者登录
#****************************************
#导入类库
import time
from appium.webdriver.webdriver import WebDriver
from appium.webdriver.webdriver import By
#方法0:手机驱动参数初始化
def test_cpas_init():
        # 手机参数初始化
        # ******************************************************************************************
        # 查询程序包名的命令:adb shell dumpsys activity activities| findstr mFocusedActivity#设置appPackage:被测程序包名
        caps = {
                'platformName': 'Android',  # 设置platformName:手机系统名称Android
                'platformVersion': '7.1.2',  # #设置platformVersion:手机系统版本
                'deviceName': '127.0.0.1:52001',  # 设置deviceName:设备名称
                'appPackage': 'uni.UNI765428A',  # 设置appPackage:被测程序包名
                'appActivity': 'io.dcloud.PandoraEntry'  # 设置appActivity:被测程序活动名
        }

        # 启动appium
        driver = WebDriver('http://127.0.0.1:4723/wd/hub', caps)
        # **********************************************************************************
        return driver

#方法1:两个允许按钮+服务器地址+验证码登录
def test_login_init(driver):
         #进行元素定位
        #点击允许按钮
        time.sleep(2)
        driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
        #允许电话管理
        time.sleep(2)
        driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
        #*****************************************************************
        #输入后台服务器地址
        time.sleep(5)
        xpath_service='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[1]/android.view.View/android.widget.EditText'
        servicepath='https://lefeiwisdom-3pt-2t6a7-www.vip.51env.net'
        driver.find_element(By.XPATH,xpath_service).clear()
        time.sleep(1)
        driver.find_element(By.XPATH,xpath_service).send_keys(servicepath)
        #点击确定按钮
        time.sleep(3)
        #***********************************************************************
        xpath_ok="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[2]"
        driver.find_element(By.XPATH,xpath_ok).click()
        #***********************************************************************
        #点击验证码登录按钮
        time.sleep(4)
        xpath_check='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[4]'
        driver.find_element(By.XPATH,xpath_check).click()
        time.sleep(2)
        #********************************************************************************

#方法3:作者登录
def test_author_login(driver):
        time.sleep(5)
        #切换到作者登录标签
        xpath_author='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[3]'
        driver.find_element(By.XPATH,xpath_author).click()
        time.sleep(2)
        #输入手机号码
        xpath_phone='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[5]/android.view.View/android.widget.EditText'
        # id_phone='c52abd0b-3c7b-4b6f-a2a0-f386d56bebd8'
        driver.find_element(By.XPATH,xpath_phone).send_keys('13900139001')
        time.sleep(2)
        #输入验证码
        xpath_checkcode='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[6]/android.view.View/android.widget.EditText'
        driver.find_element(By.XPATH,xpath_checkcode).send_keys('111111')
        #接受协议
        xpath_allow='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[9]'
        time.sleep(2)
        driver.find_element(By.XPATH,xpath_allow).click()
        #登录按钮
        time.sleep(2)
        xpath_login='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[8]'
        driver.find_element(By.XPATH,xpath_login).click()

if __name__ == '__main__':
    driver=test_cpas_init()
    test_login_init(driver)
    test_author_login(driver)

5、test_loginV4.py #优化:面向过程的封装,可选哪种方法的登录

#*****************************************
#v4.0:app独立自动化测试 脚本--初始化登录
#优化:面向过程的封装,可选哪种方法的登录
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法2:普通用户登录/作者登录
#****************************************
#*****************************************
#v4.0:app独立自动化测试 脚本--初始化登录
#优化:面向过程的封装,可选哪种方法的登录
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法2:普通用户登录/作者登录
#****************************************
#导入类库
import time
from appium.webdriver.webdriver import WebDriver
from appium.webdriver.webdriver import By
#方法0:手机驱动参数初始化
def test_cpas_init():
        # 手机参数初始化
        # ******************************************************************************************
        # 查询程序包名的命令:adb shell dumpsys activity activities| findstr mFocusedActivity#设置appPackage:被测程序包名
        caps = {
                'platformName': 'Android',  # 设置platformName:手机系统名称Android
                'platformVersion': '7.1.2',  # #设置platformVersion:手机系统版本
                'deviceName': '127.0.0.1:52001',  # 设置deviceName:设备名称
                'appPackage': 'uni.UNI765428A',  # 设置appPackage:被测程序包名
                'appActivity': 'io.dcloud.PandoraEntry'  # 设置appActivity:被测程序活动名
        }

        # 启动appium
        driver = WebDriver('http://127.0.0.1:4723/wd/hub', caps)
        # **********************************************************************************
        return driver

#方法1:两个允许按钮+服务器地址+验证码登录
def test_login_init(driver):
         #进行元素定位
        #点击允许按钮
        time.sleep(2)
        driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
        #允许电话管理
        time.sleep(2)
        driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
        #*****************************************************************
        #输入后台服务器地址
        time.sleep(5)
        xpath_service='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[1]/android.view.View/android.widget.EditText'
        servicepath='https://lefeiwisdom-3pt-2t6a7-www.vip.51env.net'
        driver.find_element(By.XPATH,xpath_service).clear()
        time.sleep(1)
        driver.find_element(By.XPATH,xpath_service).send_keys(servicepath)
        #点击确定按钮
        time.sleep(3)
        #***********************************************************************
        xpath_ok="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[2]"
        driver.find_element(By.XPATH,xpath_ok).click()
        #***********************************************************************
        #点击验证码登录按钮
        time.sleep(4)
        xpath_check='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[4]'
        driver.find_element(By.XPATH,xpath_check).click()
        time.sleep(2)
        #********************************************************************************



#方法2:作者登录
def test_author_login(driver,usertype):
        time.sleep(5)
        if usertype==1:
                #切换到作者登录标签
                xpath_author='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[3]'
                driver.find_element(By.XPATH,xpath_author).click()
                userphone='13900139001'
        else:
                userphone='13800138001'
        time.sleep(2)
        #输入手机号码
        xpath_phone='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[5]/android.view.View/android.widget.EditText'
        # id_phone='c52abd0b-3c7b-4b6f-a2a0-f386d56bebd8'
        driver.find_element(By.XPATH, xpath_phone).send_keys(userphone)
        time.sleep(2)
        #输入验证码
        xpath_checkcode='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[6]/android.view.View/android.widget.EditText'
        driver.find_element(By.XPATH,xpath_checkcode).send_keys('111111')
        #接受协议
        xpath_allow='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[9]'
        time.sleep(2)
        driver.find_element(By.XPATH,xpath_allow).click()
        #登录按钮
        time.sleep(2)
        xpath_login='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[8]'
        driver.find_element(By.XPATH,xpath_login).click()

if __name__ == '__main__':
    #进行哪种方法的登录
    #usertype=0 表示普通用户登录,=1为作者登录
    usertype=int(input("请输入数字,0 表示普通用户登录,1为作者登录"))
    driver=test_cpas_init()
    test_login_init(driver)
    test_author_login(driver,usertype)

6、test_loginV5.py #优化:面向对象的封装,可选哪种方法的登录

#v5.0:app独立自动化测试 脚本--初始化登录
#优化:面向对象的封装,可选哪种方法的登录
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法2:普通用户登录/作者登录
#将以上方法封装到测试类中
#*****************************************
#v5.0:app独立自动化测试 脚本--初始化登录
#优化:面向对象的封装,可选哪种方法的登录
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法2:普通用户登录/作者登录
#将以上方法封装到测试类中
#****************************************
#导入类库
import time
from appium.webdriver.webdriver import WebDriver
from appium.webdriver.webdriver import By
class Test_login():
        #方法0:手机驱动参数初始化
        def test_cpas_init(self):
                # 手机参数初始化
                # ******************************************************************************************
                # 查询程序包名的命令:adb shell dumpsys activity activities| findstr mFocusedActivity#设置appPackage:被测程序包名
                caps = {
                        'platformName': 'Android',  # 设置platformName:手机系统名称Android
                        'platformVersion': '7.1.2',  # #设置platformVersion:手机系统版本
                        'deviceName': '127.0.0.1:52001',  # 设置deviceName:设备名称
                        'appPackage': 'uni.UNI765428A',  # 设置appPackage:被测程序包名
                        'appActivity': 'io.dcloud.PandoraEntry'  # 设置appActivity:被测程序活动名
                }

                # 启动appium
                driver = WebDriver('http://127.0.0.1:4723/wd/hub', caps)
                # **********************************************************************************
                return driver

        #方法1:两个允许按钮+服务器地址+验证码登录
        def test_login_init(self,driver):
                 #进行元素定位
                #点击允许按钮
                time.sleep(2)
                driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
                #允许电话管理
                time.sleep(2)
                driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
                #*****************************************************************
                #输入后台服务器地址
                time.sleep(5)
                xpath_service='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[1]/android.view.View/android.widget.EditText'
                servicepath='https://lefeiwisdom-3pt-2t6a7-www.vip.51env.net'
                driver.find_element(By.XPATH,xpath_service).clear()
                time.sleep(1)
                driver.find_element(By.XPATH,xpath_service).send_keys(servicepath)
                #点击确定按钮
                time.sleep(3)
                #***********************************************************************
                xpath_ok="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[2]"
                driver.find_element(By.XPATH,xpath_ok).click()
                #***********************************************************************
                #点击验证码登录按钮
                time.sleep(4)
                xpath_check='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[4]'
                driver.find_element(By.XPATH,xpath_check).click()
                time.sleep(2)
                #********************************************************************************



        #方法2:普通用户登录/作者登录
        def test_author_login(self,driver,usertype):
                time.sleep(5)
                if usertype==1:
                        #切换到作者登录标签
                        xpath_author='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[3]'
                        driver.find_element(By.XPATH,xpath_author).click()
                        userphone='13900139001'
                else:
                        userphone='13800138001'
                time.sleep(2)
                #输入手机号码
                xpath_phone='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[5]/android.view.View/android.widget.EditText'
                # id_phone='c52abd0b-3c7b-4b6f-a2a0-f386d56bebd8'
                driver.find_element(By.XPATH, xpath_phone).send_keys(userphone)
                time.sleep(2)
                #输入验证码
                xpath_checkcode='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[6]/android.view.View/android.widget.EditText'
                driver.find_element(By.XPATH,xpath_checkcode).send_keys('111111')
                #接受协议
                xpath_allow='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[9]'
                time.sleep(2)
                driver.find_element(By.XPATH,xpath_allow).click()
                #登录按钮
                time.sleep(2)
                xpath_login='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[8]'
                driver.find_element(By.XPATH,xpath_login).click()

if __name__ == '__main__':
    #进行哪种方法的登录
    #usertype=0 表示普通用户登录,=1为作者登录
    usertype=int(input("请输入数字,0 表示普通用户登录,1为作者登录"))
    #实例化测试类对象
    obj=Test_login()
    driver=obj.test_cpas_init()
    obj.test_login_init(driver)
    obj.test_author_login(driver,usertype)

7、test_loginV6.py  将以上方法封装到测试类中,将参数变为属性

#*****************************************
#v6.0:app独立自动化测试 脚本--初始化登录
#优化:面向对象的封装,可选哪种方法的登录
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法2:普通用户登录/作者登录
#将以上方法封装到测试类中,将参数变为属性
#****************************************
#*****************************************
#v6.0:app独立自动化测试 脚本--初始化登录
#优化:面向对象的封装,可选哪种方法的登录
#方法0:手机驱动参数输出化设置
#方法1:两个允许按钮+服务器地址+验证码登录
#方法2:普通用户登录/作者登录
#将以上方法封装到测试类中,将参数变为属性
#****************************************
#导入类库
import time
from appium.webdriver.webdriver import WebDriver
from appium.webdriver.webdriver import By
class Test_login():
        #方法0:手机驱动参数初始化
        def test_cpas_init(self):
                # 手机参数初始化
                # ******************************************************************************************
                # 查询程序包名的命令:adb shell dumpsys activity activities| findstr mFocusedActivity#设置appPackage:被测程序包名
                caps = {
                        'platformName': 'Android',  # 设置platformName:手机系统名称Android
                        'platformVersion': '7.1.2',  # #设置platformVersion:手机系统版本
                        'deviceName': '127.0.0.1:52001',  # 设置deviceName:设备名称
                        'appPackage': 'uni.UNI765428A',  # 设置appPackage:被测程序包名
                        'appActivity': 'io.dcloud.PandoraEntry'  # 设置appActivity:被测程序活动名
                }

                # 启动appium
                self.driver = WebDriver('http://127.0.0.1:4723/wd/hub', caps)
                # **********************************************************************************


        #方法1:两个允许按钮+服务器地址+验证码登录
        def test_login_init(self):
                 #进行元素定位
                #点击允许按钮
                time.sleep(2)
                self.driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
                #允许电话管理
                time.sleep(2)
                self.driver.find_element(By.ID,'com.android.packageinstaller:id/permission_allow_button').click()
                #*****************************************************************
                #输入后台服务器地址
                time.sleep(5)
                xpath_service='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[1]/android.view.View/android.widget.EditText'
                servicepath='https://lefeiwisdom-3pt-2t6a7-www.vip.51env.net'
                self.driver.find_element(By.XPATH,xpath_service).clear()
                time.sleep(1)
                self.driver.find_element(By.XPATH,xpath_service).send_keys(servicepath)
                #点击确定按钮
                time.sleep(3)
                #***********************************************************************
                xpath_ok="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[2]"
                self.driver.find_element(By.XPATH,xpath_ok).click()
                #***********************************************************************
                #点击验证码登录按钮
                time.sleep(4)
                xpath_check='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[4]'
                self.driver.find_element(By.XPATH,xpath_check).click()
                time.sleep(2)
                #********************************************************************************



        #方法2:普通用户登录/作者登录
        def test_author_login(self,usertype):
                time.sleep(5)
                if usertype==1:
                        #切换到作者登录标签
                        xpath_author='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[3]'
                        self.driver.find_element(By.XPATH,xpath_author).click()
                        userphone='13900139001'
                else:
                        userphone='13800138001'
                time.sleep(2)
                #输入手机号码
                xpath_phone='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[5]/android.view.View/android.widget.EditText'
                # id_phone='c52abd0b-3c7b-4b6f-a2a0-f386d56bebd8'
                self.driver.find_element(By.XPATH, xpath_phone).send_keys(userphone)
                time.sleep(2)
                #输入验证码
                xpath_checkcode='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[6]/android.view.View/android.widget.EditText'
                self.driver.find_element(By.XPATH,xpath_checkcode).send_keys('111111')
                #接受协议
                xpath_allow='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[9]'
                time.sleep(2)
                self.driver.find_element(By.XPATH,xpath_allow).click()
                #登录按钮
                time.sleep(2)
                xpath_login='/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.webkit.WebView/android.webkit.WebView/android.view.View[8]'
                self.driver.find_element(By.XPATH,xpath_login).click()

if __name__ == '__main__':
    #进行哪种方法的登录
    #usertype=0 表示普通用户登录,=1为作者登录
    usertype=int(input("请输入数字,0 表示普通用户登录,1为作者登录"))
    #实例化测试类对象
    obj=Test_login()
    obj.test_cpas_init()
    obj.test_login_init()
    obj.test_author_login(usertype)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2159901.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

fo-dicom是如何实现DICOM 的网络通信功能

一、前言 前面的文章,我们介绍了fo-dicom是一个怎样的开源库等一些内容: fo-dicom,第一个基于.NET Standard 2.0 开发的DICOM开源库fo-dicom开源库是如何满足 DICOM标准的基本要求fo-dicom开发之DICOM数据解析:常见数据类型及处…

自学前端的正确姿势是...

师傅带进门,修行在个人。 在前端自学成才的道路上,有些人走的很快,有些人却举步维艰。 为什么会这样子呢?因为他们没有掌握自学前端的正确姿势。 在介绍应该要怎样自学前端之前,首先来看下,自学前端容易…

JavaWeb--小白笔记07:servlet对表单数据的简单处理

这里的servlet对表单数据的处理是指使用IDEA创建web工程,再创建html和class文件进行连接,实现html创建一个表单网页,我们对网页中的表单进行填充,可以通过class文件得到网页我们填充的内容进行打印到控制台。 一登录系统页面---h…

[vulnhub] w1r3s.v1.0

https://www.vulnhub.com/entry/w1r3s-101,220/ 思路:红队笔记 主机发现端口扫描 使用nmap扫描网段类存活主机 因为靶机是我最后添加的,所以靶机IP是133 nmap -sP 192.168.75.0/24 // Starting Nmap 7.93 ( https://nmap.org ) at 2024-09-20 09:09 CST…

MySQL 数据库安装(详细教程)

文章目录 一、前言二、下载 MySQL2.1 安装包方式2.2 压缩包方式(推荐) 三、安装 MySQL3.1 解压 MySQL 文件3.2 配置环境变量3.3 初始化 data 目录3.4 安装 MySQL 服务3.5 开启 MySQL 服务3.6 修改 MySQL 密码 四、卸载 MySQL4.1 停止 MySQL 服务4.2 删除…

MySQL record 08 part

数据库连接池: Java DataBase Connectivity(Java语言连接数据库) 答: 使用连接池能解决此问题, 连接池,自动分配连接对象,并对闲置的连接进行回收。 常用的数据库连接池: 建立数…

【WRF运行第三期】服务器上运行WRF模型(官网案例-Hurricane Matthew)

【WRF运行第三期】运行WRF模型(官网案例-Hurricane Matthew) 官网案例-Hurricane Matthew介绍0 创建DATA文件夹1 WPS预处理1.1 解压GRIB数据(ungrib.exe)1.1.1 解压GRIB数据---GFS(Matthew案例研究数据)1.1…

Bytebase 2.22.3 - 一键回滚 PostgreSQL DML 变更

🚀 新功能 支持一键回滚 PostgreSQL DML 变更。 🎄 改进 优化 DML 事前备份和回滚体验: 引导用户创建 bbdataarchive 数据库。如果没有 bbdataarchive 数据库,无法开启备份功。用户现在可以在创建工单之后开启或关闭备份功能&a…

PyCharm远程连接AutoDL服务器实现程序调试

本文详细介绍了如何在Pycharm中配置SSH和SFTP,以便于在AOTUDL服务器上进行代码修改、调试。步骤包括新建工程、配置SFTP连接、设置Rootpath和Mapping,以及实现自动上传和下载文件的功能。远程服务器编辑调试只是试用于专业版本的pycharm,我的…

【LLM学习之路】9月22日 第九天 自然语言处理

【LLM学习之路】9月22日 第九天 直接看Transformer 第一章 自然语言处理 自然语言处理发展史 只要看的足够多,未必需要理解语言 统计语言模型发展史 统计语言模型: 判断一个句子是否合理,就计算这个句子会出现的概率 缺点是句子越长越…

微软推迟在MDM设备上启用OOBE强制更新 因为IT管理员反馈称缺乏控制

微软很久之前就计划在 Windows 10/11 OOBE 期间强制下载更新,即若检测到系统本身属于旧版本例如并未安装最新累积更新,则在 OOBE 期间强制下载最新累积更新并自动安装。这种更新方式已经在面向消费者的设备上启用,而上周微软则是在适用于企业…

盘点那些功能强大的思维导图在线工具,你用过几个

如果我们日常遇到比较繁杂的信息需要梳理,那我比较推荐使用思维导图在线工具进行梳理。这些工具可以通过图形化的方式展示各种信息之间的关系。这篇文章我将要介绍几款好用的思维导图工具帮我们更好的组织思维。 1.福晰思维导图 链接一下:https://www.…

GPIO与MIO控制LED——ZYNQ学习笔记2

一、GPIO简介 ZYNQ 分为 PS 和 PL 两部分,那么器件的引脚( Pin)资源同样也分成了两部分。 ZYNQ PS 中的外设可以通过 MIO( multiplexed I/O,多路复用 I/O)模块连接到 PS 端的引脚上,也可以通过 …

HTML讲解(三)通用部分

目录 1.空格标记 2.特殊文字的标记 3.注释语句 4.对文字字体的设置 5.修改文字形态 6.换行标记 7.居中标记 8.水平线标记 9.设置滚动弹幕 1.空格标记 在HTML中,我们想打印空格并不能直接敲一个空格键,因为如果是敲空格键,那无论你敲…

【JUC并发编程系列】深入理解Java并发机制:Volatile从底层原理解析到高级应用技巧(六、Volatile关键字、JMM、重排序、双重检验锁)

文章目录 【JUC并发编程系列】深入理解Java并发机制:Volatile从底层原理解析到高级应用技巧(六、Volatile关键字、JMM、重排序、双重检验锁)1. Volatile的特性2. Volatile的用法3. CPU多核硬件架构剖析4. JMM内存模型4.1 主要特性4.2 JMM 的工作原理4.3 实现机制 5.…

Leetcode面试经典150题-39.组合总数进阶:40.组合总和II

本题是扩展题,真实考过,看这个题之前先看一下39题 Leetcode面试经典150题-39.组合总数-CSDN博客 给定一个候选人编号的集合 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数…

Docker:解决开发运维问题的开源容器化平台

云计算de小白 Docker是一个开源的容器化平台,可以将应用程序及其依赖的环境打包成轻量级、可移植的容器。 Docker为什么这么受欢迎呢?原因很简单:Docker可以解决不同环境一致运行的问题,而且占用资源少,速度快。 所以好的东西…

链式队列操作

文章目录 🍊自我介绍🍊概述🍊链式队列代码linkstack.clinkstack.hmain.c 你的点赞评论就是对博主最大的鼓励 当然喜欢的小伙伴可以:点赞关注评论收藏(一键四连)哦~ 🍊自我介绍 Hello,大家好&…

OmniPeek 空口抓包软件安装指导

OmniPeek 空口抓包软件安装指导 1 双击omnp75安装包---Unzip解压缩 生成install包 2 进入install文件夹点击setup开始进入安装界面 3 点击install Omnipeek 4 点击next,勾选手动安装

云原生虚拟化kubevirt安装

kubevirt 介绍 Kubevirt 是 Redhat 开源的一套以容器方式运行虚拟机的项目,通过 kubernetes 云原生方式来管理虚拟机生命周期。它通过使用自定义资源(CRD)和其它 Kubernetes 功能来无缝扩展现有的集群,以提供一组可用于管理虚拟机…