appium+python自动化代码

# coding=utf-8

from appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
import time
import pytest
import allure


desired_caps = {
    "platformName": "Android",
    # 安卓-版本
    "platformVersion": "12.0.0",
    "deviceName": "M2012K11C",
    # 设备名称
    "appPackage": "com.juanvision.EseeNetProj",
    # app包名
    "appActivity": "com.juanvision.modulelogin.activity.SplashActivity",
    # cmd查看获取 启动包
    "noReset": True
    # 不清缓存,登录
    }
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
wait=WebDriverWait(driver,30)


@allure.feature('设备进入设备预览')  # feature定义功能
@pytest.mark.repeat(50)




class Test_set():

  def test_1(self):
    var=1
    ifshebei=False
    while var==1 :
            time.sleep(2)
            try:
                driver.find_element_by_xpath(
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.ImageView")
                print("True")
                ifshebei = True

            except:
                print("False")
            if ifshebei==True:
                print("app成功使用!")
                # com.juanvision.EseeNetProj:id/dev_rb
                break
            else:
                print("重启app失败,继续重")
                driver.start_activity("com.juanvision.EseeNetProj","com.juanvision.modulelogin.activity.SplashActivity")

    try:
            # textvalue = driver.find_element_by_xpath(
            #  "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.ImageView").text
            # print("---------------" + textvalue + "---------------")
            el1 = driver.find_element_by_xpath(
                "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.ImageView")
            el1.click()
            # allure.attach(driver.get_screenshot_as_png(), "成功截图", allure.attachment_type.PNG)
            # wait.until(lambda x: x.find_element_by_id("com.juanvision.EseeNetProj:id/item_play_iv")).click()#播放
            time.sleep(3)
            wait.until(lambda x: x.find_element_by_id("com.juanvision.EseeNetProj:id/title_back_iv")).click()#返回
    except:
            time.sleep(3)
            allure.attach(driver.get_screenshot_as_png(), "运行失败截图", allure.attachment_type.PNG)

            assert False




        # 超时时间为30s,每隔1秒搜索一次元素是否存在,如果元素存在返回定位对象并退出
        #time.sleep(2)
        #driver.tap([(761,372)])
        #wait.until(lambda x: x.find_element_by_id("com.juanvision.EseeNetProj:id/common_title_back_fl")).click()

 

posted @ 2022-04-19 15:44  代码是肥钦喔  阅读(184)  评论(0编辑  收藏  举报