appium automated preparation

appium

1, based on the testing framework python

  • Programming language: python client
  • IDE: pycharm
  • Client installation package: appium_python_client
  • Multiple versions of isolation Tools: venv
  • Domestic rely source: http: //pypi.douban.com/simple/
  • Testing framework: pytest, unittest, nose recommendation pytest

The advantages and disadvantages of pytest and unittest

2, code waits

Implicit wait:
1、定义:服务端在设置的时间内不断查找元素,直到查找到元素或达到等待时间为止,作用于全局
2、代码:driver.implicitly_wait(10)
Explicit waiting:
1、定义:客户端(即用例端)固定等待设置的时间,作用于特定代码快
2、代码:
from time import sleep 
sleep(20)

** Note: ** implicit and explicit wait wait can be combined using an implicit global wait, in particular explicit wait until the

3, common targeting

  • List item
  • id
  • accessbilityID
  • XPath
    -className not used
    the -image
    -UIautomator2 Andrews
    -XCUITest IOS

4, common positioning method

findElementByXXX ()
findElementBy (By, value) using the design patterns #PO

5, commonly used automation API

  • click
  • sendkeys
  • swipe
  • TouchActions
TouchActions

1, define: tap operation performed on the element
the Perform The ON A tap Action Element
2, using the method:

from appium.webdriver.common.touch_action import TouchAction
// ...
actions = TouchAction(driver)
actions.tap_and_hold(20, 20)
actions.move_to(10, 100)
actions.release()
actions.perform()

3, chaining:
Example: performing press - drag - Press release - commit operation

	TouchAction(driver).long_press().move_to().release().perform()
swipe

1. Definition: Optional from one point to another slide, duration
Swipe from One Point to Another Point, for optional AN DURATION
2, method: driver.swipe()
3, applicability:
for a different resolution phones NA, absolutely can not be used position, the relative position should be used, such as for subsequent encapsulation compatibility testing method to deal swipe

6、 pytest

Command line installation pytest: pip install -U pytest
pytest successful installation screenshots
View pytest version: pytest --version
This IS pytest Version 5.3.5. . .
Based pytest script:

from appium import webdriver
class TestDemo:
    def setup(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'  # 设备系统
        desired_caps['platformVersion'] = '6.0.1'  # 设备系统版本
        desired_caps['deviceName'] = '127.0.0.1:62001' # 设备名称
        desired_caps['appPackage'] = '包名'  # 测试app包名
        desired_caps['appActivity'] = 'app启动参数'  
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)  # 启动app
        self.driver.implicitly_wait(20) #设置隐式等待

    def test_lanuch(self):
        driver = self.driver
        # 等待10秒
        driver.implicitly_wait(10)
        # #同意协议
        el1 = driver.find_element_by_id("tv.danmaku.bili:id/agree")
        el1.click()
        # 定位游戏手柄
        el2 = driver.find_element_by_xpath(
        "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.support.v4.widget.DrawerLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.LinearLayout/android.view.ViewGroup/android.support.v7.widget.LinearLayoutCompat/android.widget.FrameLayout[1]/android.widget.ImageView[2]")
        el2.click()

    def teardown(self):

        self.driver.quit()

Before running start

Activate the phone / emulator
Start APPium

Direct start APPium Server console

Published 99 original articles · won praise 43 · views 160 000 +

Guess you like

Origin blog.csdn.net/mayanyun2013/article/details/104315331