RF與APPIUM筆記
1、RF訪問mysql數(shù)據(jù)庫
1.1安裝資源包:databaselibrary、pymysqlpip install robotframework-databaselibrarypip install pymysql
1.2導(dǎo)入DatabaseLibrary
1.3應(yīng)用舉例connect to databasepymysql[dbname] rootxxxx172.16.1.xx3306${dbdata}query${select_sql}${ret_data}set variable${dbdata[0][0]}disconnect from database
2、解決每次運(yùn)行都需要安裝Unlock和AppiumSetting
2.1進(jìn)入appium的安裝目錄:\appium-desktop\resources\app\node_modules\appium\node_modules\appium-android-driver\lib編輯這個(gè)文件,找到下面這行罪郊,把它注釋掉繼續(xù)找到下面這兩行,也是把它注釋掉這個(gè)文件就算改完了尚洽,保存并退出悔橄。
2.2接下來改另外一個(gè)文件:找到這個(gè)路徑:\appium-desktop\resources\app\node_modules\appium\node_modules\appium-android-driver\build\lib注意是在build路徑下的lib文件夾編輯這個(gè)文件:找到下面這行,將它注釋掉,并且在該行下方加上一行:繼續(xù)修改以下兩行癣疟,改法同上面這個(gè)一樣:保存并且退出挣柬。重啟appium即可。
3睛挚、通過wifi連接Android設(shè)備3.1首先用USB連接你的Android設(shè)備邪蛔,然后在終端運(yùn)行命令,它可以啟動(dòng)設(shè)備的5555端口使其在網(wǎng)絡(luò)上可以連接竞川。adb tcpip 55553.2斷開USB連接店溢,然后確保設(shè)備和你的電腦連接同一個(gè)無線網(wǎng)絡(luò)。進(jìn)入設(shè)備查看IP地址:設(shè)置—wifi—你連接的wifi—IP地址并在終端運(yùn)行命令adb connect3.3驗(yàn)證是否connect成功
adb devices
4委乌、關(guān)于臨時(shí)彈窗處理的一個(gè)方法
${text} run keyword and return status page should contain text 地區(qū)
Run Keyword Unless '${text}'=='False' Run Keywords click element xpath=${area} AND click element xpath=${enterApp}
5床牧、RF集成安卓toast提示語的匹配
5.1、安裝新版本的APPIUM如:appium-desktop-Setup-1.2.7.exe
下載地址:https://testerhome.com/topics/680
需要使用Uiautomator2才能選擇到toast的信息
5.2遭贸、集成find toast方法到APPIUMLIBRARY
路徑\Python27\Lib\site-packages\AppiumLibrary\keywords\_element.py
①導(dǎo)入需要用到的模塊
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
②定義find toast函數(shù)
? ? def find_toast(self, message):
? ? ? ? """Finds an element by Android Toast
? ? ? ? :Args:
? ? ? ? - message - The message for preparing.
? ? ? ? """
? ? ? ? application = self._current_application()? ##獲取當(dāng)前的驅(qū)動(dòng)
? ? ? ? try:
? ? ? ? ? ? toast_loc = ("xpath", ".//*[contains(@text,'%s')]"%message)
? ? ? ? ? ? WebDriverWait(application, 6, 0.5).until(expected_conditions.presence_of_element_located(toast_loc))
? ? ? ? ? ? self._info("Toast has been found: %s ."%message)
? ? ? ? except:
? ? ? ? ? ? self._info("Not found toast")
5.3戈咳、啟動(dòng)APP時(shí),需要切換UI選擇器
需要增加的信息:automationName=Uiautomator2 noReset=true
5.4壕吹、find toast方法的使用
直接使用并填寫需要匹配的內(nèi)容
匹配成功:
匹配失斨堋:
6、獲取APP包名和ACTIVITY
6.1確保設(shè)備連接上電腦
6.2執(zhí)行adb logcat >D:/log(日志在D盤耳贬,文件為log)
6.3啟動(dòng)APP
6.4啟動(dòng)完成后踏堡,在命令提示框按Ctrl + C,停止打印日志
6.5打開日志文件咒劲,搜索 displayed 即可