医疗协助平台网站建设方案,网页设计与制作论文题目,网站建设分什么行业,淄博企业网站设计公司『App自动化测试之Appium应用篇』| Appium常用API及操作 1 press_keycode1.1 键盘操作1.2 关于KeyCode1.3 press_keycode源码1.4 电话键相关1.5 控制键相关1.6 基本按键相关1.7 组合键相关1.8 符号键相关1.9 使用举例 2 swip方法2.1 swip说明2.2 swip使用方法2.3 使用示例 3 sc… 『App自动化测试之Appium应用篇』| Appium常用API及操作 1 press_keycode1.1 键盘操作1.2 关于KeyCode1.3 press_keycode源码1.4 电话键相关1.5 控制键相关1.6 基本按键相关1.7 组合键相关1.8 符号键相关1.9 使用举例 2 swip方法2.1 swip说明2.2 swip使用方法2.3 使用示例 3 scroll方法4 drag_and_drop方法5 TouchAction方法5.1 tap方法5.2 press方法5.3 release方法5.4 wait方法5.5 move_to方法 1 press_keycode
1.1 键盘操作
press_keycode是Appium的键盘相关函数可以实现键盘的相关操作比如返回、按键、音量调节等等函数使用方法为
driver.press_keycode(KeyCode)1.2 关于KeyCode
以上press_keycode方法中传入参数KeyCode而KeyCode是对应的键值码其可以传入对应的键值名也可以传入具体键值名的值对应数字。
1.3 press_keycode源码
press_keycode源码如下 def press_keycode(self, keycode: int, metastate: Optional[int] None, flags: Optional[int] None) - WebDriver:Sends a keycode to the device.Android only. Possible keycodes can be foundin http://developer.android.com/reference/android/view/KeyEvent.html.Args:keycode: the keycode to be sent to the devicemetastate: meta information about the keycode being sentflags: the set of key event flagsReturns:Union[WebDriver, Keyboard]: Self instanceext_name mobile: pressKeyargs {keycode: keycode}if metastate is not None:args[metastate] metastateif flags is not None:args[flags] flagstry:self.assert_extension_exists(ext_name).execute_script(ext_name, args)except UnknownMethodException:# TODO: Remove the fallbackself.mark_extension_absence(ext_name).execute(Command.PRESS_KEYCODE, args)return cast(WebDriver, self)从源码中可以看出想要找到对应的键值名可以直接去官网查看。
1.4 电话键相关
以下为部分非全部仅参考电话键相关键值名
键值名说明键值KEYCODE_HOMEHOME键3KEYCODE_BACK返回键4KEYCODE_CALL拨号键5KEYCODE_EKDCALL挂机键6KEYCODE_VOLUME_UP音量增加键24KEYCODE_VOLUME_DOWN音量减减键25KEYCODE_POWER电源键26KEYCODE_CAMERA拍照键27KEYCODE_MENU菜单键82KEYCODE_NOTIFICATION通知键83KEYCODE_SEARCH搜索键84
1.5 控制键相关
以下为部分非全部仅参考控制键相关键值名
键值名说明键值KEYCODE_DPAD_UP导航键 向上19KEYCODE_DPAD_DOWN导航键 向下20KEYCODE_DPAD_LEFT导航键 向左21KEYCODE_DPAD_RIGHT导航键 向右22KEYCODE_DPAD_CENTER导航键 确定键23KEYCODE_TABTAB键61KEYCODE_ENTER回车键66KEYCODE_DEL退格键67KEYCODE_ESCAPEESC键111KEYCODE_FORWARD_DEL删除键112KEYCODE_CAPS_LOCK大写锁定键115KEYCODE_SCROLL_LOCK滚动锁定键116
1.6 基本按键相关
以下为部分非全部仅参考基本按键相关键值名其中按键0-9键值为7-16比如
键值名说明键值KEYCODE_0按键’0’7KEYCODE_1按键’1’8KEYCODE_2按键’2’9
其中字母A-Z的键值为29-54比如
键值名说明键值KEYCODE_A按键’A’29KEYCODE_B按键’B’30KEYCODE_C按键’C’31
1.7 组合键相关
以下为部分非全部仅参考组合键相关键值名
键值名说明KEYCODE_ALT_LEFTALTLIFTKEYCODE_ALEERT_RIGHTALT_RIGHTKEYCODE_CTRL_LEFTCtrl_lEFTKEYCODE_CTRL_RIGHTCtrl_RIGHTKEYCODE_SHIFT_LEFTShiftlEFTKEYCODE_SHIFT_RIGHTShiftRIGHT
1.8 符号键相关
以下为部分非全部仅参考符号键相关键值名
键值名说明KEYCODE_PLUS按键’’KEYCODE_MINUS按键’-’KEYCODE_STAR按键’*’KEYCODE_SLASH按键’/’KEYCODE_EQUALS按键’’KEYCODE_AT按键’’KEYCODE_POUND按键’#’KEYCODE_SPACE空格键
1.9 使用举例
使用方法为
driver.press_keycode(4) # 返回键
driver.press_keycode(84) # 搜索键或者可以使用keyevent方法
driver.keyevent(66) # 回车键
driver.keyevent(67) # 退格键2 swip方法
2.1 swip说明
swip()方法是从一个坐标位置滑动到另一个坐标位置也就是说两点之间的滑动。
2.2 swip使用方法
可以查看swip源码来看下如何使用 def swipe(self, start_x: int, start_y: int, end_x: int, end_y: int, duration: int 0) - WebDriver:Swipe from one point to another point, for an optional duration.Args:start_x: x-coordinate at which to startstart_y: y-coordinate at which to startend_x: x-coordinate at which to stopend_y: y-coordinate at which to stopduration: defines the swipe speed as time taken to swipe from point a to point b, in ms.Usage:driver.swipe(100, 100, 100, 400)Returns:Union[WebDriver, ActionHelpers]: Self instancetouch_input PointerInput(interaction.POINTER_TOUCH, touch)actions ActionChains(self)actions.w3c_actions ActionBuilder(self, mousetouch_input)actions.w3c_actions.pointer_action.move_to_location(start_x, start_y)actions.w3c_actions.pointer_action.pointer_down()if duration 0:actions.w3c_actions ActionBuilder(self, mousetouch_input, durationduration)actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)actions.w3c_actions.pointer_action.release()actions.perform()return cast(WebDriver, self)从以上看需要至少四个参数swipe(self, start_x: int, start_y: int, end_x: int, end_y: int);
2.3 使用示例
比如坐标从100,200滑动到300,400
driver.swipe(100, 200, 300, 400)再比如从400,500滑动到600,700持续3秒
driver.swipe(400, 500, 600, 700, 3000)3 scroll方法
scroll()方法是从一个元素滑动到另一个元素直到页面自动停止使用方法为 def scroll(self, origin_el: WebElement, destination_el: WebElement, duration: Optional[int] None) - WebDriver:Scrolls from one element to anotherArgs:origin_el: the element from which to begin scrolling (center of element)destination_el: the element to scroll to (center of element)duration: defines speed of scroll action when moving from originalEl to destinationEl.Default is 600 ms for W3C spec.Usage:driver.scroll(el1, el2)比如从用户名滑动到密码输入框
user_name driver.find_element(AppiumBy.XPATH, //*[text用户名])
user_passwd driver.find_element(AppiumBy.XPATH, //*[text密码])
driver.scroll(user_name, user_passwd)4 drag_and_drop方法
drag_and_drop()方法从一个元素滑动到另一个元素第二个元素代替第一个元素原本屏幕上的位置使用方法为 def drag_and_drop(self, origin_el: WebElement, destination_el: WebElement) - WebDriver:Drag the origin element to the destination elementArgs:origin_el: the element to dragdestination_el: the element to drag toReturns:Union[WebDriver, ActionHelpers]: Self instance比如
user_name driver.find_element(AppiumBy.XPATH, //*[text用户名])
user_passwd driver.find_element(AppiumBy.XPATH, //*[text密码])
driver.drag_and_drop(user_name, user_passwd)5 TouchAction方法
TouchAction可实现手势的操作比如滑动、拖动、长按等操作使用方法是先需要导入TouchAction
from appium.webdriver.common.touch_action import TouchAction5.1 tap方法
tap()方法模拟手指对某个元素或坐标按下并快速抬起使用方法为 def tap(self,element: Optional[WebElement] None,x: Optional[int] None,y: Optional[int] None,count: int 1,) - TouchAction:Perform a tap action on the elementArgs:element: the element to tapx : x coordinate to tap, relative to the top left corner of the element.y : y coordinate. If y is used, x must also be set, and vice versa比如
TouchAction(driver).tap(user_name).perform()5.2 press方法
press()方法是手指一直按下使用方法 def press(self,el: Optional[WebElement] None,x: Optional[int] None,y: Optional[int] None,pressure: Optional[float] None,) - TouchAction:Begin a chain with a press down action at a particular element or pointArgs:el: the element to pressx: x coordiate to press. If y is used, x must also be sety: y coordiate to press. If x is used, y must also be set比如
TouchAction(driver).press(x100, y200).perform()5.3 release方法
release()方法是模拟手指抬起使用方法 def release(self) - TouchAction:End the action by lifting the pointer off the screenReturns:TouchAction: Self instanceself._add_action(release, {})return self比如
TouchAction(driver).press(x100, y200).release().perform()5.4 wait方法
wait()方法是模拟手指等待使用方法为 def wait(self, ms: int 0) - TouchAction:Pause for ms milliseconds.Args:ms: The time to pauseReturns:TouchAction: Self instance比如按下等待3秒后抬起
TouchAction(driver).press(x100, y200).wait(3000).release().perform()5.5 move_to方法
move_to()方法是模拟手指移动使用方法 def move_to(self, el: Optional[WebElement] None, x: Optional[int] None, y: Optional[int] None) - TouchAction:Move the pointer from the previous point to the element or point specifiedArgs:el: the element to be moved tox: x coordiate to be moved to. If y is used, x must also be sety: y coordiate to be moved to. If x is used, y must also be setReturns:TouchAction: Self instance比如
TouchAction(driver).press(x400, y500).move_to(500, 600).perform()
文章转载自: http://www.morning.rqhdt.cn.gov.cn.rqhdt.cn http://www.morning.nfdty.cn.gov.cn.nfdty.cn http://www.morning.qhvah.cn.gov.cn.qhvah.cn http://www.morning.fgsqz.cn.gov.cn.fgsqz.cn http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn http://www.morning.dytqf.cn.gov.cn.dytqf.cn http://www.morning.ygkb.cn.gov.cn.ygkb.cn http://www.morning.c7623.cn.gov.cn.c7623.cn http://www.morning.dkqbc.cn.gov.cn.dkqbc.cn http://www.morning.c7627.cn.gov.cn.c7627.cn http://www.morning.gklxm.cn.gov.cn.gklxm.cn http://www.morning.mrckk.cn.gov.cn.mrckk.cn http://www.morning.qjngk.cn.gov.cn.qjngk.cn http://www.morning.xesrd.com.gov.cn.xesrd.com http://www.morning.zgnng.cn.gov.cn.zgnng.cn http://www.morning.ggqcg.cn.gov.cn.ggqcg.cn http://www.morning.nbwyk.cn.gov.cn.nbwyk.cn http://www.morning.nxstj.cn.gov.cn.nxstj.cn http://www.morning.bpmtj.cn.gov.cn.bpmtj.cn http://www.morning.qgmwt.cn.gov.cn.qgmwt.cn http://www.morning.0small.cn.gov.cn.0small.cn http://www.morning.mhpkz.cn.gov.cn.mhpkz.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.smj79.cn.gov.cn.smj79.cn http://www.morning.mwwnz.cn.gov.cn.mwwnz.cn http://www.morning.rqhn.cn.gov.cn.rqhn.cn http://www.morning.wjhnx.cn.gov.cn.wjhnx.cn http://www.morning.wngpq.cn.gov.cn.wngpq.cn http://www.morning.rqhn.cn.gov.cn.rqhn.cn http://www.morning.tstwx.cn.gov.cn.tstwx.cn http://www.morning.tqsnd.cn.gov.cn.tqsnd.cn http://www.morning.kgphd.cn.gov.cn.kgphd.cn http://www.morning.krtcjc.cn.gov.cn.krtcjc.cn http://www.morning.msgnx.cn.gov.cn.msgnx.cn http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn http://www.morning.bkylg.cn.gov.cn.bkylg.cn http://www.morning.kpwdt.cn.gov.cn.kpwdt.cn http://www.morning.mngh.cn.gov.cn.mngh.cn http://www.morning.cpmwg.cn.gov.cn.cpmwg.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn http://www.morning.supera.com.cn.gov.cn.supera.com.cn http://www.morning.qrpdk.cn.gov.cn.qrpdk.cn http://www.morning.zxqxx.cn.gov.cn.zxqxx.cn http://www.morning.qmpbs.cn.gov.cn.qmpbs.cn http://www.morning.gmwdl.cn.gov.cn.gmwdl.cn http://www.morning.pqyms.cn.gov.cn.pqyms.cn http://www.morning.cfpq.cn.gov.cn.cfpq.cn http://www.morning.tcfhs.cn.gov.cn.tcfhs.cn http://www.morning.tbqxh.cn.gov.cn.tbqxh.cn http://www.morning.dbxss.cn.gov.cn.dbxss.cn http://www.morning.dswtz.cn.gov.cn.dswtz.cn http://www.morning.okiner.com.gov.cn.okiner.com http://www.morning.nspbj.cn.gov.cn.nspbj.cn http://www.morning.mhmsn.cn.gov.cn.mhmsn.cn http://www.morning.ymqrc.cn.gov.cn.ymqrc.cn http://www.morning.xbxks.cn.gov.cn.xbxks.cn http://www.morning.knsmh.cn.gov.cn.knsmh.cn http://www.morning.xnpj.cn.gov.cn.xnpj.cn http://www.morning.tbhlc.cn.gov.cn.tbhlc.cn http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn http://www.morning.ymqrc.cn.gov.cn.ymqrc.cn http://www.morning.dktyc.cn.gov.cn.dktyc.cn http://www.morning.fzwf.cn.gov.cn.fzwf.cn http://www.morning.qbfwb.cn.gov.cn.qbfwb.cn http://www.morning.xxwhz.cn.gov.cn.xxwhz.cn http://www.morning.dnycx.cn.gov.cn.dnycx.cn http://www.morning.jwfqq.cn.gov.cn.jwfqq.cn http://www.morning.wclxm.cn.gov.cn.wclxm.cn http://www.morning.cgntj.cn.gov.cn.cgntj.cn http://www.morning.jcbmm.cn.gov.cn.jcbmm.cn http://www.morning.zrgsg.cn.gov.cn.zrgsg.cn http://www.morning.eronghe.com.gov.cn.eronghe.com http://www.morning.pmbcr.cn.gov.cn.pmbcr.cn http://www.morning.dqwkm.cn.gov.cn.dqwkm.cn http://www.morning.ktrdc.cn.gov.cn.ktrdc.cn http://www.morning.wmmqf.cn.gov.cn.wmmqf.cn http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn http://www.morning.sgmgz.cn.gov.cn.sgmgz.cn http://www.morning.rblqk.cn.gov.cn.rblqk.cn