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

歡迎訪問 生活随笔!

生活随笔

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

python

登录python自动化_Appium+Python实现自动化登录

發布時間:2024/7/23 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 登录python自动化_Appium+Python实现自动化登录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#Appium+Python實現自動化測試

Appium簡介 官方的概述為: Appium is an open source test automation framework for use with native, hybrid and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol.

Appium是一個開源的測試自動化框架,用于本地、混合和移動Web應用程序。

它使用WebDevices協議驅動iOS、Android和Windows應用程序。也就是可以用它來幫助我們實現自動化測試,代替人為的點擊,每次發版都能夠按照案例清單完整的跑一套流程,保證當前版本的穩定性。

支持多種語言開發定制 python,javaSprict,java,ruby,Objective C,php,.net,RobotFramework 其中Android SDK ≥ 16

支持多平臺 mac和Windows

Appium 安裝方式

1:直接安裝Appium客戶端

Appium官網,點擊downLoad即可

2:命令行本地安裝 1:安裝node 2:npm install -g appium 3:npm install -g appium-doctor appium-doctor是檢查你的本地環境是否正常的工具 注:如果權限問題請加上sudo,appium-doctor在新版appium已經移除,需要利用npm安裝 sudo npm install -g appium-doctor,安裝完成后輸入appium-doctor檢測環境是否正常 如果遇到缺少js文件錯誤,說明你的node版本太低,需要升級nodejs,升級的方式為 1: sudo npm cache clean -f 清楚nodejs的cache 2:sudo npm install -g n 管理npm的工具 3:sudo n stable 升級node 4: sudo npm install npm@latest -g 更新npm 4:node -v查看node版本(最新為11.4.0) 再次運行appium-doctor查看本地環境配置是否正常,不正常修復即可

安裝Python 安裝方式網上很多,不在闡述,目前我用的是python3.7 推薦的ide為:Pycharm

編寫自動化用例 我們的這次用的apk為微信

希望能夠通過appium幫我們實現微信登錄并跳轉到我的->個人信息界面from appium import webdriver import time class UiTest(object): def __init__(self): # 設備信息 self.config = { "platformName": "Android", "platformVersion": "5.1.1", "deviceName": "Pixel XL", "automationName": "app", "app": '/Users/davidxiong/Desktop/wx.apk', } # 有多重模擬點擊方式: # 1:坐標, # 2:id # 3:xpath # 4:name,這邊我采用坐標和xpath,因為微信的元素id會動態改變 # 手機號元素路徑 self.phone = '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.EditText' # 手機號點擊登錄元素路徑 self.phone_enter = '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.Button[2]' # 密碼路徑 self.pass_word = '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.EditText' # 密碼確認路徑 self.pass_word_enter = '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.Button[2]' # 關閉匹配框 self.close_match = '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.Button[1]' # 個人中心 self.mine_info = '//android.widget.FrameLayout[@content-desc="當前所在頁面,與的聊天"]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/com.tencent.mm.ui.mogic.WxViewPager/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ListView/android.widget.LinearLayout[1]/android.widget.RelativeLayout/android.widget.LinearLayout' self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.config) # editText輸入 def edit_input(self, et_id, content, xpath='', timer=-1): if xpath == '': pl = self.driver.find_element_by_id(et_id) else: pl = self.driver.find_element_by_xpath(xpath) if timer != -1: time.sleep(timer) pl.send_keys(content) # 點擊事件 def click(self, btn_id, xpath='', timer=-1): if timer != -1: time.sleep(timer) if xpath == '': self.driver.find_element_by_id(btn_id).click() else: self.driver.find_element_by_xpath(xpath).click() def run(self): time.sleep(2) # 點擊登錄 self.driver.tap([(259, 1773)]) # 輸入手機號 self.edit_input('ht', '你的賬號', xpath=self.phone, timer=1) # 點擊下一步,這邊采用xpath self.click('akb', xpath=self.phone_enter) # 輸入密碼 time.sleep(2) self.edit_input('ht', '密碼', xpath=self.pass_word, timer=1) # 登錄R self.click('akb', xpath=self.pass_word_enter) time.sleep(8) # 關閉提示匹配通訊錄彈出框 self.click('akb', xpath=self.close_match) # 等地同步數據 time.sleep(30) # 點擊我的,這邊采用坐標 self.driver.tap([(933, 1823)]) # 查看我的個人信息 self.click('akb', xpath=self.mine_info) if __name__ == "__main__": UiTest().run()

總結

以上是生活随笔為你收集整理的登录python自动化_Appium+Python实现自动化登录的全部內容,希望文章能夠幫你解決所遇到的問題。

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