• appium每次运行如何初始化


    最近测试公司软件遇到一个问题,每次运行Appium测试代码,打开软件都是初始化,每次的新手教程以及无法记住密码一堆问题,导致效率很低,而且定位有时候出问题。

    先看初始化的代码

     1 from appium import webdriver
     2 from time import sleep
     3 from appium.webdriver.common.touch_action import TouchAction
     4 desired_caps = {}
     5 desired_caps['platformName'] = 'Android'
     6 desired_caps['platformVersion'] = '9.0'
     7 desired_caps['deviceName'] = 'b68548ed'
     8 desired_caps['appPackage'] = 'com.kexin.iot'
     9 desired_caps['appActivity'] = '.MainActivity'
    10 
    11 driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
    12 sleep(5)
    13 el1 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View[1]/android.view.View/android.view.View[2]/android.view.View[2]/android.view.View[1]/android.view.View/android.view.View/android.widget.Button")
    14 el1.click()#点击跳过
    15 sleep(2)
    16 el2 = driver.find_element_by_id('android:id/button1')
    17 el2.click()#点击允许GIS定位
    18 sleep(2)
    19 e13 = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View[1]/android.view.View/android.view.View[2]/android.view.View[2]/android.view.View/android.view.View[2]/android.view.View/android.view.View/android.view.View[2]/android.widget.EditText')
    20 e13.send_keys('cc')
    21 e14 = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View[1]/android.view.View/android.view.View[2]/android.view.View[2]/android.view.View/android.view.View[3]/android.view.View/android.view.View/android.view.View[2]/android.widget.EditText')
    22 e14.send_keys('a123456')
    23 e15 = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View[1]/android.view.View/android.view.View[2]/android.view.View[2]/android.view.View/android.widget.Button')
    24 e15.click()#点击登录
    25 sleep(3)

    加上  desired_caps['noReset'] = 'True'

    跳过初始化的代码:上面的新手教程的定位都可以省略了,效率就提升了

     1 from appium import webdriver
     2 from time import sleep
     3 from appium.webdriver.common.touch_action import TouchAction
     4 desired_caps = {}
     5 desired_caps['platformName'] = 'Android'
     6 desired_caps['platformVersion'] = '9.0'
     7 desired_caps['deviceName'] = 'b68548ed'
     8 desired_caps['appPackage'] = 'com.kexin.iot'
     9 desired_caps['appActivity'] = '.MainActivity'
    10 desired_caps['noReset'] = 'True'
    11 
    12 driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
    13 sleep(5)
  • 相关阅读:
    Spark 基本概念及入门
    Cron 表达式详解
    VmWare 网络模式
    微信、支付宝各种支付退款
    Spring Security OAuth2 SSO 单点登录
    Git 入门详解
    基于Spring Boot 2.x 的 Spring Cloud Admin 实践
    Git 提交规范
    Linux 安装 Mysql8.0
    Docker入门
  • 原文地址:https://www.cnblogs.com/huny/p/12605637.html
Copyright © 2020-2023  润新知