日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python手机app 授权登录_Appium+unittest+python登录app

發布時間:2025/4/17 python 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python手机app 授权登录_Appium+unittest+python登录app 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼:

# coding=utf-8

from appium import webdriver

import time

import unittest

import os

import HTMLTestRunner

class LoginTestLizi(unittest.TestCase):

def setUp(self):

desired_caps = {}

desired_caps['platformName'] = 'Android'

desired_caps['deviceName'] = 'Android Emulator'

desired_caps['platformVersion'] = '6.0'

desired_caps['appPackage'] = 'com.netease.cloudmusic'

desired_caps['appActivity'] = '.activity.LoadingActivity'

self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

def startAPP(self):

wd = self.driver

wd.find_element_by_id("com.netease.cloudmusic:id/arc").click()

wd.find_element_by_id("com.netease.cloudmusic:id/bw4").click()

wd.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()

wd.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()

time.sleep(10) # 睡眠10S等APP啟動完成

def test_login(self):

driver = self.driver

# 進入首頁后點擊‘我的’按鈕

driver.find_element_by_id("com.netease.cloudmusic:id/arc").click()

time.sleep(2)

# 點擊登錄頭像按鈕,進行登錄,跳轉到登錄界面

driver.find_element_by_id('com.netease.cloudmusic:id/pt').click()

time.sleep(2)

# 輸入手機號

driver.find_element_by_id('com.netease.cloudmusic:id/j5').send_keys('16688886666')

#點擊next

driver.find_element_by_id('com.netease.cloudmusic:id/an5').click()

time.sleep(2)

# 輸入驗證碼

driver.find_element_by_id('com.netease.cloudmusic:id/an_').send_keys('1234')

time.sleep(3)

# 點擊確認登錄按鈕

driver.find_element_by_id('com.lizi.app:id/login_button').click()

time.sleep(3)

# 登錄成功,頁面下滑,不然點擊不到設置按鈕

driver.swipe(500, 200, 500, 800, 0)

time.sleep(2)

# 獲取登錄后的昵稱

name = driver.find_element_by_id('com.lizi.app:id/login_username_tv').text

# 添加斷言,若昵稱不正確,則打印錯誤信息

try:

assert 'No_matter' in name

print('loginUser is right')

except AssertionError as e:

print('loginUser is Error')

# 點擊設置按鈕,進入設置頁面

driver.find_element_by_id('com.lizi.app:id/setting_imageView').click()

# 點擊退出按鈕

driver.find_element_by_id('com.lizi.app:id/exit_button').click()

def tearDown(self):

self.driver.quit()

if __name__ == '__main__':

suite = unittest.TestSuite()

suite.addTest(LoginTestLizi('startAPP'))

suite.addTest(LoginTestLizi('test_login'))

filename = 'd:\\app.html'

fb = open(filename, 'wb')

runner = HTMLTestRunner.HTMLTestRunner(stream=fb, title='liziapptestreport', description='liziapp')

runner.run(suite)

fb.close()

總結

以上是生活随笔為你收集整理的python手机app 授权登录_Appium+unittest+python登录app的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。