Pycharm + appium + python automated test APP (real machine)
Prerequisites: 1. Android SDK 2. jdk environment variable
1. Install pycharm https://www.jetbrains.com/pycharm/download/#section=windows install node.js http://nodejs.cn/download/
2. Install appium http://appium.io/ (note the installation of these two files)
3.Open pycharm --file--setting--project: project name --python Interpreter
If it is not installed, click the + sign to enter the appium-Python-Client installation (after installing these, you need to configure the environment variables. I will take a screenshot directly for everyone)
After configuring the environment variables, you need to check whether they have been installed normally.
cmd open a command prompt, enter appium-doctor and press enter
After setting up the environment, you can start your automated testing journey.
4. Start appium
5. Select advanced settings (1) Enter the server address 127.0.0.1 (2) Start the server
6. Right-click on the Pycharm project name, new Python file, enter the file name and start writing code
# -*- coding: UTF-8 -*-
import time
from appium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
# from selenium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'#平台 名称
desired_caps['platformVersion'] = '10' #Android 版本号
desired_caps['deviceName'] = '60d8a48d'#设备名称(cmd -- adb devices 确保手机连接电脑正常)
desired_caps['appPackage'] = '项目包名'
desired_caps['appActivity'] = '.ui.SplashActivity'#要打开的app入口Activity
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(2)
#打开app后允许的权限
def always_allow(driver, number=6):
for i in range(number):
loc = ("xpath", "//*[@text='始终允许']")
try:
e = WebDriverWait(driver, 1, 0.5).until(EC.presence_of_element_located(loc))
e.click()
except:
pass
if __name__ == "__main__":
# 调用始终允许函数
always_allow(driver)
time.sleep(1)
driver.find_element_by_id("alert_ok").click()
time.sleep(2)
homebar = driver.find_elements_by_id("messages")
homebar[3].click()
time.sleep(1)
driver.find_element_by_id("lly_login").click()
time.sleep(1)
def login(driver, edphones="18513147424", edPasss="123456"):
driver.find_element_by_id("btn_ByPass").click()
time.sleep(1)
edPhone = driver.find_element_by_id("et_Phone")
edPhone.send_keys(edphones)
edPass = driver.find_element_by_id("et_Code")
edPass.send_keys(edPasss)
time.sleep(1)
driver.find_element_by_id("btn_Login").click()
time.sleep(2)
pass
login(driver)
time.sleep(1)
homebar[0].click()
Start your automated testing journey quickly.