环境搭建
- JDK
- SDK
- node.js
- Python
- Appium
Appium-Python-Client
pip install Appium-Python-Client /pip3 install Appium-Python-Client 有时需要翻墙才下得动sublime Text 3
编写脚本
脚本API
- appium.webdriver
# -*- coding: utf-8 -*-
import os
# from selenium import webdriver
from appium import webdriver
from appium.webdriver.mobilecommand import MobileCommand
from selenium.webdriver.common import action_chains, keys
from appium.webdriver.common import touch_action,multi_action
import time
# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
desired_caps = {}
desired_caps['device'] = 'Android'
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = 'Galaxy S6 edge+'
desired_caps['browserName'] = ''
# desired_caps['version'] = '6.0'
desired_caps['app'] = PATH('D:\\APK\\sss\\ssss_s.apk')
desired_caps['app-package'] = 'com.example.android.contactmanager'
desired_caps['app-activity'] = '.controller.LaunchActivity'
# desired_caps['noReset'] = 'True'
desired_caps['chromedriverExecutable'] = PATH('D:\\tools\\aotuTest\\Appium\\node_modules\\appium\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe')
desired_caps['resetKeyboard'] = 'True'
desired_caps['unicodeKeyboard'] = 'True'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
action = action_chains.ActionChains(driver)
weview:切换到webview
driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {"name":"WEBVIEW_com.sse.android.ssegwapp"})
native:切换到native
driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {"name":"NATIVE_APP"})