五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

技術分享 | app自動化測試(Android)--觸屏操作自動化

2022-10-09 10:19 作者:愛測軟件測試  | 我要投稿

導入TouchAction

  • Python 版本

from appium.webdriver.common.touch_action import TouchAction

  • Java 版本

import io.appium.java_client.TouchAction;

常用的手勢操作

press 按下

TouchAction 提供的常用的手勢操作有如下操作:

  • press 按下

  • release 釋放

  • move_to/moveTo 移動

  • tap 點擊

  • long_press/longPress 長按

  • wait 等待

  • cancel 取消

  • perform 執(zhí)行

TouchAction 提供的 press( ) 方法可以實現(xiàn)對元素或者坐標的按下操作。通常會結合 release( ) 方法實現(xiàn)對某個元素的點擊(包括按下和抬起兩個動作)。

在某個控件上執(zhí)行 press 操作,用法如下:

  • Python 版本

按下某個元素,用法如下:

press(WebElement el)

在坐標為(x,y)的點執(zhí)行 press 操作,用法如下:

press(int x, int y)

  • Java 版本

在坐標為(x,y)的點執(zhí)行 press 操作,用法如下:

press(int x, int y)

release 釋放

釋放操作,可以結合其它的事件使用。代表該系列動作的一個結束標志。在某個控件上執(zhí)行釋放操作,用法如下:

  • Python 版本

release(WebElement el)

也可以在上一個操作結束之后執(zhí)行 release,不添加任何參數(shù),用法如下:

release()

  • Java 版本

release()

移動

以控件為目標,從一個點移動到該目標上,用法如下:

  • Python 版本

move_to(WebElement el)

以(x,y)點為目標,從一個點移動到該目標,用法如下:

move_to(WebElement el, int x, int y)

  • Java 版本

以(x,y)點為目標,從一個點移動到該目標,用法如下:

moveTo(WebElement el, int x, int y)

qrcode.ceba.ceshiren.com

tap 點擊

在某個控件的中心點上點擊一下,用法如下:

  • Python 版本

tap(WebElement el)

以控件 el 的左上角為基準,沿著 x 軸向右移動 x 單位,沿著 y 軸向下移動 y 單位。在該點上點擊,用法如下:

tap(WebElement el, int x, int y)

以(x,y)坐標點為目標點擊,用法如下:

tap(int x, int y)

  • Java版本

只提供坐標點擊,用法如下:

tap(int x, int y)

長按

長按某一控件,用法如下:

  • Python 版本

long_press(WebElement el)

以(x,y)點為目標實現(xiàn)長按,用法如下:

long_press(int x, int y)

在控件的左上角的 x 坐標偏移 x 單位,y 左邊偏移 y 單位的坐標上長按。用法如下:

long_press(WebElement el, int x, int y)

  • Java 版本

只提供坐標點擊,用法如下:

longPress(int x, int y)

等待

等待,單位為毫秒??梢栽诓僮魇录倪^程中,短暫的停留幾秒再繼續(xù)操作。用法如下:

  • Python 版本

wait(long timeout)

  • Java 版本

wait(long timeout)

cancel 取消

可以取消執(zhí)行事件鏈中的事件,用法如下:

  • Python 版本

cancel()

  • Java 版本

cancel()

執(zhí)行 perform

執(zhí)行事件鏈中的事件,一般最后會調(diào)用這個方法,順序執(zhí)行事件鏈中的動作。用法如下:

  • Python 版本

perform()

  • Java 版本

perform()

案例

打開測試應用,從元素 “Views” 文本滑動到 “Accessibility” 元素,創(chuàng)建一個測試文件代碼如下:

測試 app 官方下載地址:appium/sample-code/apps at master · appium/appium · GitHub

#!/usr/bin/env python

# -*- coding: utf-8 -*-?

# 測試文件 test_touchaction.py?

from appium import webdriver

from appium.webdriver.common.touch_action import TouchAction

class TestTouchAction():?

? ?def setup(self): ? ??

? ?caps = {} ? ? ??

?? caps['platformName'] = 'Android' ? ?

? ?caps['platformVersion'] = '6.0' ? ? ?

? ??caps['deviceName'] = 'emulator-5554' ??

? ? ?caps['appPackage'] = 'io.appium.android.apis'?

? ? caps['appActivity'] = 'io.appium.android.apis.ApiDemos' ? ? ? ?self.driver = webdriver.Remote(\ ? ?

? ?"http://127.0.0.1:4723/wd/hub", caps) ? ? ? ?self.driver.implicitly_wait(5) ?

?def teardown(self): ? ??

? ?self.driver.quit() ??

?def test_touchaction_unlock(self): ? ?

?? ?# 點擊 Views ? ??

? ?el1 = self.driver.find_element_by_accessibility_id( ? ?

? ? ? ?"Views") ? ??

? ?# 點擊 Accessibility ? ??

? ?el2 = self.driver.find_element_by_accessibility_id( ? ? ? ? ? ?"Accessibility") ??

? ? ?# TouchAction 滑動操作 ? ??

? ?action = TouchAction(self.driver) ? ? ? ?action.press(el1).wait(100).move_to\ ? ? ? ?(el2).wait(100).release().perform()

public class TouchActionTest { ?

?static AppiumDriver driver; ?

?@BeforeAll ?

?public static void beforeAll() throws MalformedURLException { ? ? ? ?DesiredCapabilities caps = new DesiredCapabilities(); ? ? ? ?caps.setCapability("deviceName", "emulator-5554"); ? ? ? ?caps.setCapability("platformName", "Android"); ? ? ? ?caps.setCapability("appPackage", "io.appium.android.apis"); ? ? ? ?caps.setCapability("appActivity", "io.appium.android.apis.\ ? ? ? ?ApiDemos"); ? ?

? ?URL appiumServer = new URL("http://127.0.0.1:4723/wd/hub"); ? ? ? ?driver = new AndroidDriver(appiumServer, caps); ? ? ? ?driver.manage().timeouts().implicitlyWait(10, \ ?

? ? ?TimeUnit.SECONDS); ?

?} ?

?@Test ?

??void test() { ??

? ??// 創(chuàng)建 TouchAction 對象 ? ?

? ?TouchAction action = new TouchAction<>(driver); ? ?

? ?// TouchAction 滑動操作 ? ? ?

?action.press(PointOption.point((int) (width * 0.5), \ ??

? ? ?(int) (height * 0.8))).waitAction(WaitOptions.\ ? ? ? ?waitOptions(Duration.ofSeconds(2))).moveTo(\ ? ? ? ?PointOption.point((int) (width * 0.5), \? ? ?

?? (int) (height * 0.2))).release().perform(); ?

?}

}

以上兩段代碼實現(xiàn)了相同的操作,創(chuàng)建了一個 TouchAction 對象,調(diào)用里面的 press() 方法實現(xiàn)起點元素的點擊,使用 wait() 方法在事件之間添加等待,使用 move_to()/moveTo() 方法完成手勢的移動操作,然后調(diào)用 release() 方法來完成手勢的抬起,最后調(diào)用 perform() 方法對添加到 TouchAction 中的事件鏈順序執(zhí)行。


技術分享 | app自動化測試(Android)--觸屏操作自動化的評論 (共 條)

分享到微博請遵守國家法律
东光县| 南乐县| 大连市| 望都县| 土默特右旗| 梅河口市| 东乌珠穆沁旗| 旌德县| 闸北区| 时尚| 克东县| 铅山县| 香格里拉县| 潜江市| 华池县| 惠东县| 开封县| 盱眙县| 庐江县| 寿阳县| 灌南县| 深州市| 上饶市| 新化县| 洛南县| 汉源县| 呼伦贝尔市| 红原县| 兰州市| 绥滨县| 贵南县| 纳雍县| 枣庄市| 四平市| 江城| 姚安县| 浪卡子县| 清新县| 兴山县| 华坪县| 于都县|