Appium配置安装流程:
1.下载并安装Node.js:https://nodejs.org/en/about/releases/
2.下载Appium server desktop版本, 并安装 :Appium site: http://appium.io/
3.下载安卓模拟器:夜神模拟器:https://www.yeshen.com/
4.Appium与夜神模拟器连接:
1)进入夜神模拟器的安装路径,找到nox_adb.exe,
在此目录下打开CMD, 输入nox_adb.exe connect 127.0.0.1:62001回车。
会显示already connected to 127.0.0.1:62001
2)然后在CMD中再输入adb devices回车,就会显示:
List of devices attached
127.0.0.1:62001 devices
3)如果第1步出现:unable to connect to 127.0.0.1:62001: cannot connect to 127.0.0.1:62001,
先关闭夜神模拟器,再执行步骤1,正常后,再打开夜神模拟器,再执行步骤2即可。
5.下载安装PyCharm工具:网上搜一下下载安装,一般下载社区版即可,如果下载专业版本的,
可以下周2018年1月6日的,可以破解。
6.下载Python解释器的版本并安装:一般下载3.5.4及以上版本即可。
7.安装Appium-Python-Client:通过python的pip install Appium-Python-Client命令来下载安装。
注意:配置相关环境变量
1)安装JDK,并配置环境变量path
2)安装Android SDK,并配置环境变量
3)Android SDK中的tools中bin下的uiautomatorviewer.bat的功能与appium类似,也可以获取APP的元素
4)获取APP的元素,同样可以使用selenium的WebDriver来去做操作。
Code case:
import pytest
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from a_config import test_para
# desired capability, put this in config file(test_para)
desired_caps = {
"platformName": "Android",
"platformVersion": "9",
"automationName": "Appium",
# "app": "Settings",
# "appPackage": "com.android.settings"
# "appActivity": ".Settings"
}
# get driver
app_driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', test_para.desired_caps)
@pytest.fixture(scope='function', autouse=True)
def my_fixture_cls():
# init and back to desktop
for i in range(3):
app_driver.back()
print('Init desktop')
class TestAppLaunch:
def test_app_settings_app_launch(self):
# click setting app
app_driver.find_element(By.XPATH, '//android.widget.FrameLayout[@content-desc="设置"]/android.widget.ImageView[1]').click()
print('\nClick Settings app icon')
# back to desktop
sleep(1)
app_driver.back()
print('Back to desktop')
if __name__ == '__main__':
pytest.main(['-vs'
, 'd_func/demo/test_launch_app_waitlist.py::TestAppLaunch::test_app_launch'
, '--reruns=0'])
# os.system('allure generate ./c_report/allure_report_temp -o ./c_report/allure_report --clean')