1.下载地址:http://appium.io/

 

2.appium设置

{
  "platformName": "Android",     # 系统
  "platformVersion": "5.1.1",       # 系统版本
  "deviceName": "127.0.0.1:62001",     # 连接的机器
  "appPackage": "cn.rongcloud.kaixinliao",    # 包名称
  "appActivity": "cn.rongcloud.kaixinliao.ui.activity.SplashActivity"   包版本
 "noReset": true  # 跳过启动空白页
}

  

3.获取appPackage和appActivity

aapt dump badging C:\Users\yu\Desktop\cn.rongcloud.kaixinliao.App.apk(包的文件名称)
aapt dump badging C:\Users\yu\Desktop\cn.rongcloud.kaixinliao.App.apk(包的文件名称) | find "launchable-activity"
或
1. adb shell # 连接虚拟机
2. logcat | grep cmp=   回车
3. 打开app

4.也是模拟器启动appium APP显示倒着   在夜神模拟器 设置  改为手机

5.dome

# pip install Appium-Python-Client

from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import time

# 设备信息
cap = {
    "platformName": "Android",
    "platformVersion": "5.1.1",
    "deviceName": "127.0.0.1:62001",
    "appPackage": "com.tal.kaoyan",
    "appActivity": "com.tal.kaoyan.ui.activity.SplashActivity",
    "noReset": True
}

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", cap)


def get_size():
    # 获取屏幕大小
    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']
    return (x, y)


try:
    # 是否跳过
    if WebDriverWait(driver, 3).until(
            lambda x: x.find_element_by_xpath("//android.widget.TextView[@resource-id='com.tal.kaoyan:id/tv_skip']")):
        driver.find_element_by_xpath("//android.widget.TextView[@resource-id='com.tal.kaoyan:id/tv_skip']").click()
except:
    pass
try:
    # 登入
    if WebDriverWait(driver, 3).until(lambda x: x.find_element_by_xpath(
            "//android.widget.EditText[@resource-id='com.tal.kaoyan:id/login_email_edittext']")):
        driver.find_element_by_xpath(
            "//android.widget.EditText[@resource-id='com.tal.kaoyan:id/login_email_edittext']").send_keys(
            "yu17682303516")
        time.sleep(1)
        driver.find_element_by_xpath(
            "//android.widget.EditText[@resource-id='com.tal.kaoyan:id/login_password_edittext']").send_keys(
            "yu1064145110")
        time.sleep(1)
        driver.find_element_by_xpath(
            "//android.widget.Button[@resource-id='com.tal.kaoyan:id/login_login_btn']").click()
        time.sleep(1)

except:
    pass


# 点击研讯
if WebDriverWait(driver, 3).until(lambda x: x.find_element_by_xpath(
        "//android.view.View[@resource-id='com.tal.kaoyan:id/date_fix']/android.widget.RelativeLayout[3]/android.widget.LinearLayout[1]/android.widget.ImageView[1]")):
    driver.find_element_by_xpath(
        "//android.view.View[@resource-id='com.tal.kaoyan:id/date_fix']/android.widget.RelativeLayout[3]/android.widget.LinearLayout[1]/android.widget.ImageView[1]").click()
    time.sleep(1)
    l = get_size()

    x1 = int(l[0] * 0.5)
    y1 = int(l[1] * 0.75)
    y2 = int(l[1] * 0.25)

    # 滑动操作
    while True:
        driver.swipe(x1, y1, x1, y2)
        time.sleep(0.5)

6.连续滑动

 

def get_size(self):
    x = self.driver.get_window_size()['width']
    y = self.driver.get_window_size()['height']
    return (x, y)

def data(self):
    # 获取数据
    if WebDriverWait(self.driver, 3).until(lambda x: x.find_element_by_xpath(
            "//android.widget.ImageView[@resource-id='cn.rongcloud.kaixinliao:id/rc_left']")):
        self.driver.find_element_by_xpath(
            "//android.widget.ImageView[@resource-id='cn.rongcloud.kaixinliao:id/rc_left']").click()
        time.sleep(10)

    size = self.get_size()
    while True:
        try:
            x1 = int(size[0] * 0.5)
            y1 = int(size[0] * 0.25)
            y2 = int(size[1] * 0.75)
            # self.driver.swipe(x1, y2, x1, y1, 1000)  # 1000毫秒内完成滑动
            from appium.webdriver.common.touch_action import TouchAction
            TouchAction(self.driver).press(x=x1, y=y1).wait(300).move_to(x=x1, y=y2).wait(500).move_to(x=x1, y=y1).wait(500).move_to(x=x1, y=y2).wait(500).move_to(x=x1, y=y1).wait(500).release().perform()  # 连续移动
            time.sleep(3)
            print('-' * 100)
            html = self.driver.page_source
            print('b' * 100)
            print(html)
            print('b' * 100)