码迷,mamicode.com
首页 > 其他好文 > 详细

111

时间:2017-12-20 20:14:42      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:/tmp   获取默认   取消   ppi   orm   ppa   推荐   message   sql   

Appium 常用的API函数 获取信息类API get_app_string() 获取默认系统语言对应的Strings.xml文件内的数据。 get_app_string(String language) 查找某一个语言环境对应的字符串文件Strings.xml内数据。 current_activity() 获取当前activity,比如(.ApiDemos) App安装与卸载类API (1)根据bundleId来判断该应用是否已经安装 is_app_installed(String bundleId) (2)安装app,appPath为应用的本地路径 install_app(String appPath) (3)卸载app.bundleId在android中代表的是包名,而在ios中有专门的bundleId号。 remove_app(String bundleId) (4)关闭应用,其实就是按home键把应用置于后台 close_app() (5)启动应用 launch_app() (6)先closeApp然后在launchAPP reset_app() 文件操作类API (1)将字符数组用64位格式写到远程目录的某个文件中。也可以理解为把本地文件push到设备上。 push_file(String remotePath, byte[] base64Data) (2)将设备上的文件pull到本地硬盘上 pull_file(String remotePath) (3)将设备上的文件夹pull到本地硬盘上,一般远程文件为/data/local/tmp下的文件。 pull_folder(String remotePath) 设置相关类API (1)设置手机的网络连接状态,可以开关蓝牙、wifi、数据流量。通过NetworkConnectionSetting中的属性来设置各个网络连接的状态。 set_network_connect(NetworkConnectionSetting connection) (2)得到当前网络的状态 get_network_connection() 用户操作类API (1)ios隐藏键盘 hide_keyboard() (2)隐藏键盘,只能用于ios上。 hide_keyboard(String strategy, String keyName) (3)按下某个键,具体哪个键由key值决定,key值定义在AndroidKeyCode类中 send_key_event(int key) (4)执行一个touch动作,该touch动作是由TouchAction封装的。 perform_touchAction(TouchAction touchAction) (5)点击element控件中心点按下,duration*5毫秒秒后松开,如此重复fingers次。 tap(int fingers, WebElement element, int duration) (6)点击(x,y)点按下,duration*5毫秒后松开,如此重复fingers次。 tap(int fingers, int x, int y, int duration) (7)从(startx,starty)滑到(endx,endy),分duration步滑,每一步用时是5毫秒。 swipe(int startx, int starty, int endx, int endy, int duration) (8)2个手指操作控件,从对角线向中心点滑动。 pinch(WebElement el) (9)以(x,y)为基准,计算得出(x,y-100),(x,y+100)两个点,然后2个手指按住这两个点同时滑到(x,y) pinch(int x, int y) (10)与pinch(el)的动作刚好相反。两个手指由控件的中心点慢慢向控件的左顶点后右底点滑动。 zoom(WebElement el) (11)和pinch(x,y)相反。两个手指从(x,y)点开始向(x,y-100)和(x,y+100)滑动。 zoom(int x, int y) (12)锁屏多少秒后解锁 lock_screen(int seconds) (13)模拟摇晃手机 shake() (14)滚动到某个text属性为指定的字符串的控件 scroll_to(String text) (15)滚动方向由element1到element2 scroll(element1,element2) (16)滚动到某个text属性包含传入的字符串的控件 scroll_to_exact(String text) (17)设置上下文 context(String name) (18)可用上下文 get_context_handles() (19)当前上下文 get_context() (20)设置屏幕横屏或者竖屏 rotate(ScreenOrientation orientation) (21)获取当前屏幕的方向 get_orientation() 获取控件类API Seleniumdriver find_element_by_id find_elements_by_id find_element_by_name find_elements_by_name find_element_by_link_text find_elements_by_link_text find_element_by_partial_link_text find_elements_by_partial_link_text find_element_by_tag_name find_elements_by_tag_name find_element_by_xpath find_elements_by_xpath find_element_by_class_name find_elements_by_class_name find_element_by_css_selector find_elements_by_css_selector appiumdriver find_element_by_ios_uiautomation find_elements_by_ios_uiautomation find_element_by_android_uiautomator find_elements_by_android_uiautomator find_element_by_accessibility_id find_elements_by_accessibility_id AppiumDriver的辅助类 主要针对手势操作,比如滑动、长按、拖动等。 TouchAction的原理是讲一系列的动作放在一个链条中,然后将该链条传递给服务器。服务器接受到该链条后,解析各个动作,逐个执行。 TouchAction() 在控件上执行press操作 press(WebElement el) 在坐标为(x,y)的点执行press操作 press(int x, int y) 在控件el的左上角的x坐标偏移x单位,y左边偏移y单位的坐标上执行press操作。 press(WebElement el, int x, int y) 释放操作,代表该系列动作的一个结束标志。 release() 以el为目标,从另一个点移动到该目标上 move_to(WebElement el) 以(x,y)点为目标,从另一个点移动到该目标上 move_to( int x, int y) 在控件的中心点上敲击一下 tap(WebElement el) 在(x,y)点轻击一下 tap(int x, int y) 以控件el的左上角为基准,x轴向右移动x单位,y轴向下移动y单位。在该点上轻击。 tap(WebElement el, int x, int y) 代表一个空操作,等待一段时间 wait_action() 等待ms秒 wait_action(int ms) 控件长按 long_press(WebElement el) 点长按 long_press(int x, int y) 偏移点长按 long_press(WebElement el, int x, int y) 取消执行该动作 cancel() Appium Python API 1.contexts 返回当前会话中的上下文,使用后可以识别H5页面的控件 用法 driver.contexts 2. current_context 返回当前会话的当前上下文 用法driver. current_context 3. context 返回当前会话的当前上下文。 用法driver. Context 4.切换到默认的上下文 (context) 将上下文切换到默认上下文 # python driver.switch_to.context(None) 4.find_element_by_ios_uiautomation find_element_by_ios_uiautomation(self, uia_string): 通过iOS uiautomation查找元素 用法driver. find_element_by_ios_uiautomation(‘elements’) 5. find_element_by_accessibility_id find_element_by_accessibility_id(self, id): 通过accessibility id查找元素 用法driver.find_element_by_accessibility_id(‘id’) 6.scroll scroll(self, origin_el, destination_el): 从元素origin_el滚动至元素destination_el 用法 driver.scroll(el1,el2) 7. drag_and_drop drag_and_drop(self, origin_el, destination_el): 将元素origin_el拖到目标元素destination_el 用法 driver.drag_and_drop(el1,el2) 8.tap tap(self, positions, duration=None): 模拟手指点击(最多五个手指),可设置按住时间长度(毫秒) 用法 driver.tap([(x,y),(x1,y1)],500) 9. swipe swipe(self, start_x, start_y, end_x, end_y, duration=None): 从A点滑动至B点,滑动时间为毫秒 用法 driver.swipe(x1,y1,x2,y2,500) 10.flick flick(self, start_x, start_y, end_x, end_y): 按住A点后快速滑动至B点 用法 driver.flick(x1,y1,x2,y2) 11.pinch pinch(self, element=None, percent=200, steps=50): 在元素上执行模拟双指捏(缩小操作) 用法 driver.pinch(element) 12.zoom zoom(self, element=None, percent=200, steps=50): 在元素上执行放大操作 用法 driver.zoom(element) 13.reset reset(self): 重置应用(相当于卸载重装应用) 用法 driver.reset() 14. hide_keyboard hide_keyboard(self, key_name=None, key=None, strategy=None): 隐藏键盘,iOS使用key_name隐藏,安卓不使用参数 driver.hide_keyboard() 15. keyevent keyevent(self, keycode, metastate=None): 发送按键码(安卓仅有),按键码可以上网址中找到 用法 dr.keyevent(‘4’) 16. press_keycode press_keycode(self, keycode, metastate=None): 发送按键码(安卓仅有),按键码可以上网址中找到 用法 driver.press_ keycode(‘4’) driver.keyevent(‘4’)与driver.press_ keycode(‘4’) 功能实现上一样的,都是按了返回键 17. long_press_keycode long_press_keycode(self, keycode, metastate=None): 发送一个长按的按键码(长按某键) 用法 driver.long_press_keycode(‘4’) 18.current_activity current_activity(self): 获取当前的activity, 只能在 Android 上使用 用法 print(driver.current_activity()) 19. wait_activity wait_activity(self, activity, timeout, interval=1): 等待指定的activity出现直到超时,interval为扫描间隔1秒,即每隔几秒获取一次当前的activity,返回的True 或 False 用法driver.wait_activity(‘.activity.xxx’,5,2) 20. background_app background_app(self, seconds): 把当前应用放到后台运行app多少秒 用法 driver.background_app(5) 置后台5秒后再运行 21.is_app_installed is_app_installed(self, bundle_id): 检查app是否有安装,返回 True or False 用法 driver.is_app_installed(“com.example.android.apis”) 22.install_app install_app(self, app_path): 安装app,app_path为安装包路径 用法 driver.install_app(path/to/my.apk) 23.remove_app remove_app(self, app_id): 删除app 用法 driver.remove_app(“com.xxx.”) 24.launch_app launch_app(self): 启动app。根据服务关键字 (desired capabilities) 启动会话 (session) 。请注意这必须在设定 autoLaunch=false 关键字时才能生效。这是用来继续进行使用了 autoLaunch=false 关键字时的初始化(Launch) 流程的。启动指定的 app/activities ,你可以使用 start_activity 做到这个效果 用法 driver.launch_app() 25.close_app close_app(self): 关闭app 用法 driver.close_app() 启动和关闭app运行好像会出错 26. start_activity start_activity(self, app_package, app_activity, **opts): 在测试过程中打开任意活动。如果活动属于另一个应用程序,该应用程序的启动和活动被打开。这是一个安卓的方法 用法 driver.start_activity(app_package, app_activity) 27.lock lock(self, seconds): 锁屏一段时间 iOS专有 用法 driver.lock(5) 28.shake shake(self): 摇一摇手机 用法 driver.shake() 29.open_notifications open_notifications(self): 打系统通知栏(仅支持API 18 以上的安卓系统) 用法 driver.open_notifications() 30.network_connection network_connection(self): 返回网络类型 数值 用法 driver.network_connection 31. set_network_connection set_network_connection(self, connectionType): 设置网络类型 用法 先加载from appium.webdriver.connectiontype import ConnectionType dr.set_network_connection(ConnectionType.WIFI_ONLY) ConnectionType的类型有 NO_CONNECTION = 0 AIRPLANE_MODE = 1 WIFI_ONLY = 2 DATA_ONLY = 4 ALL_NETWORK_ON = 6 32. available_ime_engines available_ime_engines(self): 返回安卓设备可用的输入法 用法print(driver.available_ime_engines) 33.is_ime_active is_ime_active(self): 检查设备是否有输入法服务活动。返回真/假。 安卓 用法 print(driver.is_ime_active()) 34.activate_ime_engine activate_ime_engine(self, engine): 激活安卓设备中的指定输入法,设备可用输入法可以从“available_ime_engines”获取 用法 driver.activate_ime_engine(“com.android.inputmethod.latin/.LatinIME”) 35.deactivate_ime_engine deactivate_ime_engine(self): 关闭安卓设备当前的输入法 用法 driver.deactivate_ime_engine() 36.active_ime_engine active_ime_engine(self): 返回当前输入法的包名 用法 driver.active_ime_engine 37. toggle_location_services toggle_location_services(self): Toggle the location services on the device. Android only. 打开安卓设备上的位置定位设置 用法 driver.toggle_location_services() 38.set_location set_location(self, latitude, longitude, altitude): 设置设备的经纬度 - latitude纬度 - String or numeric value between -90.0 and 90.00 - longitude经度 - String or numeric value between -180.0 and 180.0 - altitude海拔高度- String or numeric value 用法 driver.set_location(纬度,经度,高度) 39.tag_name tag_name(self): 返回元素的tagName属性 经实践返回的是class name 用法 element.tag_name() 40.text text(self): 返回元素的文本值 用法 element.text() 41.click click(self): 点击元素 用法 element.click() 42.submit submit(self): 提交表单 用法 暂无 43.clear clear(self): 清除输入的内容 用法 element.clear() 44.get_attribute get_attribute(self, name): 1、获取 content-desc 的方法为 get_attribute("name") ,而且还不能保证返回的一定是 content-desc (content-desc 为空时会返回 text 属性值) 2、get_attribute 方法不是我们在 uiautomatorviewer 看到的所有属性都能获取的(此处的名称均为使用 get_attribute 时使用的属性名称): 可获取的: 字符串类型: name(返回 content-desc 或 text) text(返回 text) className(返回 class,只有 API=>18 才能支持) resourceId(返回 resource-id,只有 API=>18 才能支持) Example:: # Check if the "active" CSS class is applied to an element. is_active = "active" in target_element.get_attribute("class") 用法 暂无 45.is_selected is_selected(self): 返回元素是否选择。可以用来检查一个复选框或单选按钮被选中。 用法 element.is_slected() 46.is_enabled is_enabled(self): 返回元素是否可用True of False 用法 element.is_enabled() 47.find_element_by_id find_element_by_id(self, id_): 通过元素的ID定位元素 用法 driver. find_element_by_id(“id”) 48. find_elements_by_id find_elements_by_id(self, id_): 通过元素ID定位,含有该属性的所有元素 用法 driver. find_elements_by_id(“id”) 49. find_element_by_name find_element_by_name(self, name): 通过元素Name定位(元素的名称属性text) 用法 driver.find_element_by_name(“name”) 50. find_elements_by_name find_elements_by_name(self, name): 通过元素Name定位(元素的名称属性text),含有该属性的所有元素 用法 driver.find_element_by_name(“name”) 51. find_element_by_link_text find_element_by_link_text(self, link_text): 通过元素可见链接文本定位 用法 driver.find_element_by_link_text(“text”) 52. find_elements_by_link_text find_element_by_link_text(self, link_text): 通过元素可见链接文本定位,含有该属性的所有元素 用法 driver.find_elements_by_link_text(“text”) 53. find_element_by_partial_link_text find_element_by_partial_link_text(self, link_text): 通过元素部分可见链接文本定位 driver. find_element_by_partial_link_text(“text”) 54. find_elements_by_partial_link_text find_elements_by_partial_link_text(self, link_text): 通过元素部分可见链接文本定位,含有该属性的所有元素 driver. find_elements_by_partial_link_text(“text”) 55. find_element_by_tag_name find_element_by_tag_name(self, name): 通过查找html的标签名称定位元素 用法 driver.find_element_by_tag_name(“name”) 56. find_elements_by_tag_name find_elements_by_tag_name(self, name): 通过查找html的标签名称定位所有元素 用法driver.find_elements_by_tag_name(“name”) 57. find_element_by_xpath find_element_by_xpath(self, xpath): 通过Xpath定位元素 用法 find_element_by_xpath(“//*”) 58. find_elements_by_xpath find_elements_by_xpath(self, xpath): This will select all links under this element. :: myelement.find_elements_by_xpath(".//a") this will select all links in the page itself. :: myelement.find_elements_by_xpath("//a") 用法find_elements_by_xpath(“//*”) 59. find_element_by_class_name find_element_by_class_name(self, name): 通过元素class name属性定位元素 用法 driver. find_element_by_class_name(“android.widget.LinearLayout”) 60. find_elements_by_class_name find_elements_by_class_name(self, name): 通过元素class name属性定位所有含有该属性的元素 用法 driver. find_elements_by_class_name(“android.widget.LinearLayout”) 61. find_element_by_css_selector find_element_by_css_selector(self, css_selector): 通过CSS选择器定位元素 62.send_keys send_keys(self, *value): 在元素中模拟输入(开启appium自带的输入法并配置了appium输入法后,可以输入中英文) - value - A string for typing, or setting form fields. For settingfile inputs, this could be a local file path.Use this to send simple key events or to fill out form fields:: form_textfield = driver.find_element_by_name(‘username‘) form_textfield.send_keys("admin") file_input = driver.find_element_by_name(‘profilePic‘) file_input.send_keys("path/to/profilepic.gif") # Generally it‘s better to wrap the file path in one of the methods # in os.path to return the actual path to support cross OS testing. # file_input.send_keys(os.path.abspath("path/to/profilepic.gif")) driver.element.send_keys(“中英”) 63. is_displayed is_displayed(self): 此元素用户是否可见。简单地说就是隐藏元素和被控件挡住无法操作的元素(仅限 Selenium,appium是否实现了类似功能不是太确定)这一项都会返回 False 用法 driver.element.is_displayed() 64. location_once_scrolled_into_view location_once_scrolled_into_view(self): where on the screen an element is so that we can click it. This method should cause the element to be scrolled into view. Returns the top lefthand corner location on the screen, or ``None`` if the element is not visible. 65.size size(self): 获取元素的大小(高和宽) new_size["height"] = size["height"] new_size["width"] = size["width"] 用法 driver.element.size 66. value_of_css_property value_of_css_property(self, property_name): CSS属性 67.location location(self): 获取元素左上角的坐标 用法 driver.element.location ‘‘‘返回element的x坐标, int类型‘‘‘ driver.element.location.get(‘x‘) ‘‘‘返回element的y坐标, int类型‘‘‘ driver.element.location.get(‘y‘) 68.rect rect(self): 元素的大小和位置的字典 69. screenshot_as_base64 screenshot_as_base64(self): 获取当前元素的截图为Base64编码的字符串 img_b64 = element.screenshot_as_base64 70.execute_script execute_script(self, script, *args): 在当前窗口/框架(特指 Html 的 iframe )同步执行 javascript 代码。你可以理解为如果这段代码是睡眠5秒,这五秒内主线程的 javascript 不会执行 - script: The JavaScript to execute. - \*args: Any applicable arguments for your JavaScript. driver.execute_script(‘document.title‘) 71.execute_async_script execute_async_script(self, script, *args): 插入 javascript 代码,只是这个是异步的,也就是如果你的代码是睡眠5秒,那么你只是自己在睡,页面的其他 javascript 代码还是照常执行 - script: The JavaScript to execute. - \*args: Any applicable arguments for your JavaScript. driver.execute_async_script(‘document.title‘) 72.current_url current_url(self): 获取当前页面的网址。 用法 driver.current_url 73. page_source page_source(self): 获取当前页面的源。 driver.page_source 74.close close(self): 关闭当前窗口 driver.close() 75.quit quit(self): 退出脚本运行并关闭每个相关的窗口连接 driver.quit() 76.拉出文件 (Pull File) 从设备中拉出文件 # python driver.pull_file(‘Library/AddressBook/AddressBook.sqlitedb‘) 77.推送文件(Push file) 推送文件到设备中去 # python data = "some data for the file" path = "/data/local/tmp/file.txt" driver.push_file(path, data.encode(‘base64‘)) 78.下载文件夹 driver.pull_folder(path) 79.输入 driver.send_keys() driver.set_text() Android可用 driver.set_value() ios可用 如果使用sendkeys不行,可以尝试下面两种方法,我在测试ios输入密码框是自定义的键盘时,用sendkeys输入不了,appium服务端log提示没找到keyboard,后面尝试setvalue可以输入。 80.截图 driver.get_screenshot_as_file(filename) 81.获取手机屏幕分辨率 driver.get_window_size() x = driver.get_window_size()[‘width‘] y = driver.get_window_size()[‘height‘] 82.设置屏幕分辨率 driver.set_window_size(width,height) 83.获取当前坐标位置 driver.get_window_position() Appium python api 【1】find element driver 的方法 注意:这几个方法只能通过self.driver调用 ? find_element_by_android_uiautomator ? def find_element_by_android_uiautomator(self, uia_string): ? """Finds element by uiautomator in Android. ? ? :Args: ? - uia_string - The element name in the Android UIAutomator library ? 字符串,Uiautomator的代码 ? ? :Usage: ? driver.find_element_by_android_uiautomator(‘.elements()[1].cells()[2]‘) """ ? find_elements_by_android_uiautomator ? def find_elements_by_android_uiautomator(self, uia_string): ? """Finds elements by uiautomator in Android. ? ? :Args: ? - uia_string - The element name in the Android UIAutomator library ? ? :Usage: ? driver.find_elements_by_android_uiautomator(‘.elements()[1].cells()[2]‘) """ ? find_element_by_accessibility_id ? find_element_by_accessibility_id(self, id): ? Finds an element by accessibility id. ? 通过content-desc查找元素 ? :Args: ? - id - a string corresponding to a recursive element search using the ? Id/Name that the native Accessibility options utilize ? ? :Usage: ? driver.find_element_by_accessibility_id() 用法driver.find_element_by_accessibility_id(‘id’) ? find_elements_by_accessibility_id ? def find_elements_by_accessibility_id(self, id): ? """Finds elements by accessibility id. ? 通过content-desc查找元素 ? ? :Args: ? - id - a string corresponding to a recursive element search using the ? Id/Name that the native Accessibility options utilize ? ? :Usage: ? driver.find_elements_by_accessibility_id() """ element的方法 注意:此类方法driver或element均可以调用 element调用时可以用来定位该元素的子元素 ? find_element_by_id ? find_element_by_id(self, id_): ? Finds element within this element‘s children by ID. ? 通过元素的ID定位元素 ? :Args: ? - id_ - ID of child element to locate. 用法 driver. find_element_by_id(“id”) ? find_elements_by_id ? find_elements_by_id(self, id_): ? ? Finds a list of elements within this element‘s children by ID. ? 通过元素ID定位,含有该属性的所有元素 ? :Args: ? - id_ - Id of child element to find. 用法 driver. find_elements_by_id(“id”) ? find_element_by_name ? find_element_by_name(self, name): ? ? Finds element within this element‘s children by name. ? 通过元素Name定位(元素的名称属性text或content-desc) ? :Args: ? - name - name property of the element to find. 用法 driver.find_element_by_name(“name”) ? find_elements_by_name ? find_elements_by_name(self, name): ? ? Finds a list of elements within this element‘s children by name. ? 通过元素Name定位(元素的名称属性text),含有该属性的所有元素 ? :Args: ? - name - name property to search for. 用法 driver.find_element_by_name(“name”) ? find_element_by_link_text ? find_element_by_link_text(self, link_text): ? ? Finds element within this element‘s children by visible link text. ? 通过元素可见链接文本定位 ? :Args: ? - link_text - Link text string to search for. 用法 driver.find_element_by_link_text(“text”) ? find_elements_by_link_text ? find_element_by_link_text(self, link_text): ? ? Finds a list of elements within this element‘s children by visible link text ? 通过元素可见链接文本定位,含有该属性的所有元素 ? :Args: ? - link_text - Link text string to search for. 用法 driver.find_elements_by_link_text(“text”) ? find_element_by_partial_link_text ? find_element_by_partial_link_text(self, link_text): ? ? Finds element within this element‘s children by partially visible link text. ? 通过元素部分可见链接文本定位 ? :Args: ? - link_text - Link text string to search for. driver. find_element_by_partial_link_text(“text”) ? find_elements_by_partial_link_text ? find_elements_by_partial_link_text(self, link_text): ? ? Finds a list of elements within this element‘s children by link text. ? 通过元素部分可见链接文本定位,含有该属性的所有元素 ? :Args: ? - link_text - Link text string to search for. driver. find_elements_by_partial_link_text(“text”) ? find_element_by_tag_name ? find_element_by_tag_name(self, name): ? ? Finds element within this element‘s children by tag name. ? 通过查找html的标签名称定位元素 ? :Args: ? - name - name of html tag (eg: h1, a, span) 用法 driver.find_element_by_tag_name(“name”) ? find_elements_by_tag_name ? find_elements_by_tag_name(self, name): ? ? Finds a list of elements within this element‘s children by tag name. ? 通过查找html的标签名称定位所有元素 ? :Args: ? - name - name of html tag (eg: h1, a, span) 用法driver.find_elements_by_tag_name(“name”) ? find_element_by_xpath ? find_element_by_xpath(self, xpath): ? ? Finds element by xpath. ? 通过Xpath定位元素,详细方法可参阅http://www.w3school.com.cn/xpath/ ? :Args: ? xpath - xpath of element to locate. "//input[@class=‘myelement‘]" ? ? Note: The base path will be relative to this element‘s location. ? ? This will select the first link under this element. ? ? :: ? ? myelement.find_elements_by_xpath(".//a") ? ? However, this will select the first link on the page. ? ? :: ? ? myelement.find_elements_by_xpath("//a") 用法 find_element_by_xpath(“//*”) ? find_elements_by_xpath ? find_elements_by_xpath(self, xpath): ? ? Finds elements within the element by xpath. ? ? :Args: ? - xpath - xpath locator string. ? ? Note: The base path will be relative to this element‘s location. ? ? This will select all links under this element. ? ? :: ? ? myelement.find_elements_by_xpath(".//a") ? ? However, this will select all links in the page itself. ? ? :: ? ? myelement.find_elements_by_xpath("//a") ? 用法find_elements_by_xpath(“//*”) ? find_element_by_class_name ? find_element_by_class_name(self, name): ? ? Finds element within this element‘s children by class name. ? 通过元素class name属性定位元素 ? :Args: ? - name - class name to search for. 用法 driver. find_element_by_class_name(“android.widget.LinearLayout”) ? find_elements_by_class_name ? find_elements_by_class_name(self, name): ? ? Finds a list of elements within this element‘s children by class name. ? 通过元素class name属性定位所有含有该属性的元素 ? :Args: ? - name - class name to search for. 用法 driver. find_elements_by_class_name(“android.widget.LinearLayout”) 【2】 remote/webdriver selenium原生方法,调用方法: self.driver.xxxx() ? page_source: ? def page_source(self) ? Gets the source of the current page. ? 获取当前页面的源。 ? :Usage: driver.page_source ? get_screenshot_as_file ? def get_screenshot_as_file(self, filename): ? """ ? Gets the screenshot of the current window. Returns False if there is ? any IOError, else returns True. Use full paths in your filename. ? 获取 截图 存入指定的路径 ? ? :Args: ? - filename: The full path you wish to save your screenshot to. ? ? :Usage: ? driver.get_screenshot_as_file(‘/Screenshots/foo.png‘) """ ? get_window_size ? def get_window_size(self, windowHandle=‘current‘): ? """ ? Gets the width and height of the current window. ? 获取窗口高度和 ? ? :Usage: ? driver.get_window_size() """ ? orientation ? def orientation(self): ? """ ? Gets the current orientation of the device ? 获取方向 ? ? :Usage: ? orientation = driver.orientation ? """ ? ? def orientation(self, value): ? """ ? Sets the current orientation of the device ? 设置方向 ? ? :Args: ? - value: orientation to set it to. ? ? :Usage: ? driver.orientation = ‘landscape‘ """ ? desired_capabilities ? def desired_capabilities(self): ? """ ? returns the drivers current desired capabilities being used ? 返回 设定的运行参数 """ 【3】appium/webdriver 此类方法的调用方式均为 self.driver.xxxx() 输入操作 点击/触摸操作 scroll scroll(self, origin_el, destination_el): 从元素origin_el滚动至元素destination_el 用法 driver.scroll(el1,el2) ? drag_and_drop ? drag_and_drop(self, origin_el, destination_el): ? ? Drag the origin element to the destination element ? 将元素origin_el拖到目标元素destination_el ? :Args: ? - originEl - the element to drag ? - destinationEl - the element to drag to 用法 driver.drag_and_drop(el1,el2) ? tap ? tap(self, positions, duration=None): ? ? Taps on an particular place with up to five fingers, holding for a certain time ? 模拟手指点击(最多五个手指),可设置按住时间长度(毫秒) ? ? :Args: ? - positions - an array of tuples representing the x/y coordinates of ? the fingers to tap. Length can be up to five. ? - duration - (optional) length of time to tap, in ms ? ? :Usage: ? driver.tap([(100, 20), (100, 60), (100, 100)], 500) 用法 driver.tap([(x,y),(x1,y1)],500) ? swipe ? swipe(self, start_x, start_y, end_x, end_y, duration=None): ? ? Swipe from one point to another point, for an optional duration. ? 从A点滑动至B点,滑动时间为毫秒 ? :Args: ? - start_x - x-coordinate at which to start ? - start_y - y-coordinate at which to start ? - end_x - x-coordinate at which to stop ? - end_y - y-coordinate at which to stop ? - duration - (optional) time to take the swipe, in ms. ? ? :Usage: ? driver.swipe(100, 100, 100, 400) 用法 driver.swipe(x1,y1,x2,y2,500) ? flick ? flick(self, start_x, start_y, end_x, end_y): ? ? Flick from one point to another point. ? 按住A点后快速滑动至B点 ? :Args: ? - start_x - x-coordinate at which to start ? - start_y - y-coordinate at which to start ? - end_x - x-coordinate at which to stop ? - end_y - y-coordinate at which to stop ? ? :Usage: ? driver.flick(100, 100, 100, 400) ? 用法 driver.flick(x1,y1,x2,y2) ? pinch ? pinch(self, element=None, percent=200, steps=50): ? ? Pinch on an element a certain amount ? 在元素上执行模拟双指捏(缩小操作) ? :Args: ? - element - the element to pinch ? - percent - (optional) amount to pinch. Defaults to 200% ? - steps - (optional) number of steps in the pinch action ? ? :Usage: ? driver.pinch(element) ? 用法 driver.pinch(element) ? zoom ? zoom(self, element=None, percent=200, steps=50): ? ? Zooms in on an element a certain amount ? 在元素上执行放大操作,双指放大 ? :Args: ? - element - the element to zoom ? - percent - (optional) amount to zoom. Defaults to 200% ? - steps - (optional) number of steps in the zoom action ? ? :Usage: ? driver.zoom(element) ? 用法 driver.zoom(element) ? open_notifications ? open_notifications(self): ? ? Open notification shade in Android (API Level 18 and above) ? 打系统通知栏(仅支持API 18 以上的安卓系统) 用法 driver.open_notifications() ? shake ? shake(self): ? ? Shake the device. ? 摇一摇手机 用法 driver.shake() 按键 ? press_keycode ? press_keycode(self, keycode, metastate=None): ? ? Sends a keycode to the device. Android only. Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html. ? 发送按键码(安卓仅有),按键码可以上网址中找到 ? ? :Args: ? - keycode - the keycode to be sent to the device ? - metastate - meta information about the keycode being sent 用法 driver.press_ keycode(‘4’) ? long_press_keycode ? long_press_keycode(self, keycode, metastate=None): ? ? Sends a long press of keycode to the device. Android only. Possible keycodes can be ? found in http://developer.android.com/reference/android/view/KeyEvent.html. ? 发送一个长按的按键码(长按某键) ? 详细的按键代码见这里 http://developer.android.com/reference/android/view/KeyEvent.html. ? ? :Args: ? - keycode - the keycode to be sent to the device ? - metastate - meta information about the keycode being sent 用法 driver.long_press_keycode(4) 输入法 ? hide_keyboard ? hide_keyboard(self, key_name=None, key=None, strategy=None): ? ? Hides the software keyboard on the device. In iOS, use `key_name` to press a particular key, or `strategy`. In Android, no parameters are used. ? 隐藏键盘,iOS使用key_name隐藏,安卓不使用参数 ? ? :Args: ? - key_name - key to press ? - strategy - strategy for closing the keyboard (e.g., `tapOutside`) driver.hide_keyboard() ? available_ime_engines ? available_ime_engines(self): ? ? Get the available input methods for an Android device. Package and activity are returned (e.g., [‘com.android.inputmethod.latin/.LatinIME‘]) ? Android only. ? 返回安卓设备可用的输入法 用法print(driver.available_ime_engines) ? is_ime_active ? is_ime_active(self): ? ? Checks whether the device has IME service active. Returns True/False. ? Android only. ? 检查设备是否有输入法服务活动。返回真/假。 ? 安卓 用法 print(driver.is_ime_active()) ? activate_ime_engine ? activate_ime_engine(self, engine): ? ? Activates the given IME engine on the device. ? Android only. ? 激活安卓设备中的指定输入法,设备可用输入法可以从“available_ime_engines”获取 ? :Args: ? - engine - the package and activity of the IME engine to activate (e.g., ? ‘com.android.inputmethod.latin/.LatinIME‘) ? 用法 driver.activate_ime_engine(“com.android.inputmethod.latin/.LatinIME”) ? deactivate_ime_engine ? deactivate_ime_engine(self): ? ? Deactivates the currently active IME engine on the device. ? Android only. ? 关闭安卓设备当前的输入法 用法 driver.deactivate_ime_engine() ? active_ime_engine ? active_ime_engine(self): ? ? Returns the activity and package of the currently active IME engine (e.g., ? ‘com.android.inputmethod.latin/.LatinIME‘). ? Android only. ? 返回当前输入法的包名 用法 driver.active_ime_engine app控制 ? reset ? reset(self): ? ? Resets the current application on the device. ? 重置应用(相当于卸载重装应用) 用法 driver.reset() ? background_app ? background_app(self, seconds): ? ? Puts the application in the background on the device for a certain duration. ? 后台运行app多少秒 ? :Args: ? - seconds - the duration for the application to remain in the background 用法 driver.background_app(5) 置后台5秒后再运行 is_app_installed is_app_installed(self, bundle_id): 检查app是否有安装 返回 True or False 用法 driver.is_app_installed(“com.xxxx”) install_app install_app(self, app_path): 安装app,app_path为安装包路径 用法 driver.install_app(app_path) remove_app remove_app(self, app_id): 删除app 用法 driver.remove_app(“com.xxx.”) launch_app launch_app(self): Start on the device the application specified in the desired capabilities. 根据服务关键字 (desired capabilities) 启动会话 (session) 。请注意这必须在设定 autoLaunch=false 关键字时才能生效。这不是用于启动指定的 app/activities ————你可以使用 start_activity 做到这个效果————这是用来继续进行使用了 autoLaunch=false 关键字时的初始化 (Launch) 流程的。 启动app 用法 driver.launch_app() close_app close_app(self): Stop the running application, specified in the desired capabilities, on the device. 关闭app 用法 driver.close_app() contexts/activity contexts contexts(self): 返回当前会话中的上下文,使用后可以识别H5页面的控件 用法 driver.contexts current_context current_context(self): 返回当前会话的当前上下文 用法driver. current_context context context(self): 返回当前会话的当前上下文。 用法driver. Context current_activity current_activity(self): Retrieves the current activity on the device. 获取当前的activity 用法 print(driver.current_activity()) wait_activity wait_activity(self, activity, timeout, interval=1): 等待指定的activity出现直到超时,interval为扫描间隔1秒 即每隔几秒获取一次当前的activity 返回的True 或 False 用法driver.wait_activity(‘.activity.xxx’,5,2) start_activity start_activity(self, app_package, app_activity, **opts): 在测试过程中打开任意活动。如果活动属于另一个应用程序,该应用程序的启动和活动被打开。 这是一个安卓的方法 用法 driver.start_activity(app_package, app_activity) network network_connection network_connection(self): 返回网络类型 数值 用法 driver.network_connection set_network_connection set_network_connection(self, connectionType): Sets the network connection type. Android only. Possible values: Value (Alias) | Data | Wifi | Airplane Mode ------------------------------------------------- 0 (None) | 0 | 0 | 0 1 (Airplane Mode) | 0 | 0 | 1 2 (Wifi only) | 0 | 1 | 0 4 (Data only) | 1 | 0 | 0 6 (All network on) | 1 | 1 | 0 These are available through the enumeration `appium.webdriver.ConnectionType` 设置网络类型 用法 先加载from appium.webdriver.connectiontype import ConnectionType dr.set_network_connection(ConnectionType.WIFI_ONLY) ConnectionType的类型有 NO_CONNECTION = 0 AIRPLANE_MODE = 1 WIFI_ONLY = 2 DATA_ONLY = 4 ALL_NETWORK_ON = 6 位置服务 toggle_location_services toggle_location_services(self): Toggle the location services on the device. Android only. 打开安卓设备上的位置定位设置 用法 driver.toggle_location_services() set_location set_location(self, latitude, longitude, altitude): Set the location of the device 设置设备的经纬度 :Args: - latitude纬度 - String or numeric value between -90.0 and 90.00 - longitude经度 - String or numeric value between -180.0 and 180.0 - altitude海拔高度- String or numeric value 用法 driver.set_location(纬度,经度,高度) 文件pull/push pull_file def pull_file(self, path): 从设备的指定路径获取文件 用法:driver.pull_file(‘Library/AddressBook/AddressBook.sqlitedb‘) pull_folder def pull_folder(self, path): push_file def push_file(self, path, base64data): 用法: data = "some data for the file" path = "/data/local/tmp/file.txt" driver.push_file(path, data.encode(‘base64‘)) 其他 end_test_coverage def end_test_coverage(self, intent, path): 测试覆盖率相关,目前不能提供完整支持。 set_value def set_value(self, element, value): 设置某元素的值 create_web_element def create_web_element(self, element_id): app_strings def app_strings(self, language=None, string_file=None): 解析被测app的strings.xml 【4】remote/webelement 页面元素的方法,调用方法: element.xxxx() ? tag_name ? tag_name(self): ? ? This element‘s ``tagName`` property. ? 返回元素的tagName属性 ? 经实践返回的是class name 用法 element.tag_name() ? text ? text(self): ? ? The text of the element. ? 返回元素的文本值 ? 用法 element.text 注意:没有括号 ? click ? click(self): ? ? Clicks the element. ? 点击元素 用法 element.click() ? submit ? submit(self): ? ? Submits a form. ? 提交表单 用法 暂无 ? clear ? clear(self): ? ? Clears the text if it‘s a text entry element. ? 清除输入的内容 用法 element.clear() ? get_attribute ? get_attribute(self, name): ? ? Gets the given attribute or property of the element. ? 1、获取 content-desc 的方法为 get_attribute("name") ,而且还不能保证返回的一定是 content-desc (content-desc 为空时会返回 text 属性值) ? 2、get_attribute 方法不是我们在 uiautomatorviewer 看到的所有属性都能获取的(此处的名称均为使用 get_attribute 时使用的属性名称): ? ? 可获取的: ? 字符串类型: ? name(返回 content-desc 或 text) ? text(返回 text) ? className(返回 class,只有 API=>18 才能支持) ? resourceId(返回 resource-id,只有 API=>18 才能支持) ? ? 布尔类型(如果无特殊说明, get_attribute 里面使用的属性名称和 uiautomatorviewer 里面的一致): ? enabled ? checkable ? checked ? clickable ? focusable ? focused ? longClickable(返回 long-clickable) ? scrollable ? selected ? displayed(此元素是否在当前界面存在。调用的是 UIObject 的 exists() 方法,详情请看 http://developer.android.com/reference/android/support/test/uiautomator/UiObject.html#exists()) ? ? Values which are considered truthy, that is equals "true" or "false", ? are returned as booleans. All other non-``None`` values are returned ? as strings. For attributes or properties which do not exist, ``None`` ? is returned. ? ? :Args: ? - name - Name of the attribute/property to retrieve. ? ? Example:: ? ? # Check if the "active" CSS class is applied to an element. is_active = "active" in target_element.get_attribute("class") ? is_selected ? is_selected(self): ? ? Returns whether the element is selected. ? ? Can be used to check if a checkbox or radio button is selected. ? 返回元素是否选择。 ? 可以用来检查一个复选框或单选按钮被选中。 用法 element.is_slected() ? is_enabled ? is_enabled(self): ? ? Returns whether the element is enabled. ? 返回元素是否可用True of False 用法 element.is_enabled() ? send_keys ? send_keys(self, *value): ? ? Simulates typing into the element. ? 在元素中模拟输入(开启appium自带的输入法并配置了appium输入法后,可以输入中英文) ? :Args: ? - value - A string for typing, or setting form fields. For setting ? file inputs, this could be a local file path. ? ? Use this to send simple key events or to fill out form fields:: ? ? form_textfield = driver.find_element_by_name(‘username‘) ? form_textfield.send_keys("admin") ? ? This can also be used to set file inputs. ? ? :: ? ? file_input = driver.find_element_by_name(‘profilePic‘) ? file_input.send_keys("path/to/profilepic.gif") ? # Generally it‘s better to wrap the file path in one of the methods ? # in os.path to return the actual path to support cross OS testing. ? # file_input.send_keys(os.path.abspath("path/to/profilepic.gif")) ? 用法: driver.element.send_keys(“中英”) ? size ? size(self): ? ? The size of the element. ? 获取元素的大小(高和宽) ? ? new_size["height"] = size["height"] ? new_size["width"] = size["width"] ? 用法 driver.element.size ? location_once_scrolled_into_view ? location_once_scrolled_into_view(self): ? ? """THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover ? where on the screen an element is so that we can click it. This method ? should cause the element to be scrolled into view. ? ? Returns the top lefthand corner location on the screen, or ``None`` if ? the element is not visible. ? 不稳定,不推荐使用。 """ ? location ? location(self): ? ? The location of the element in the renderable canvas. ? 获取元素左上角的坐标 ? ? 用法 driver.element.location ? ‘‘‘返回element的x坐标, int类型‘‘‘ ? driver.element.location.get(‘x‘) ? ‘‘‘返回element的y坐标, int类型‘‘‘ driver.element.location.get(‘y‘) ? rect ? rect(self): ? ? A dictionary with the size and location of the element. 元素的大小和位置的字典 1.什么是负载测试?什么是性能测试? 2.性能测试包含了哪些测试(至少举出3种) 3.简述性能测试的步骤 4.简述使用Loadrunner的步骤 5.什么时候可以开始执行性能测试? 6.LoadRunner由哪些部件组成? 7.你使用LoadRunner的哪个部件来录制脚本? 8.LoadRunner的哪个部件可以模拟多用户并发下回放脚本? 9.什么是集合点?设置集合点有什么意义?Loadrunner中设置集合点的函数是哪个? 10.什么是场景?场景的重要性有哪些?如何设置场景? 11.请解释一下如何录制web脚本? 12.为什么要创建参数?如何创建参数? 13.什么是关联?请解释一下自动关联和手动关联的不同。 14.你如何找出哪里需要关联?请给一些你所在项目的实例。 15.你在哪里设置自动关联选项? 16.哪个函数是用来截取虚拟用户脚本中的动态值?(手工管联) 17.你在VUGen中何时选择关闭日志?何时选择标准和扩展日志? 18.你如何调试LoadRunner脚本? 19你在LR中如何编写自定义函数?请给出一些你在以前进行的项目中编写的函数。 20.在运行设置下你能更改那些设置? 21.你在不同的环境下如何设置迭代? 22.你如何在负载测试模式下执行功能测试? 23.什么是逐步递增?你如何来设置? 24.以线程方式运行的虚拟用户有哪些优点? 25.当你需要在出错时停止执行脚本,你怎么做? 26.响应时间和吞吐量之间的关系是什么? 27.说明一下如何在LR中配置系统计数器? 28.你如何识别性能瓶颈? 29.如果web服务器、数据库以及网络都正常,问题会出在哪里? 30.如何发现web服务器的相关问题? 31.如何发现数据库的相关问题? 32.解释所有web录制配置? 33.解释一下覆盖图和关联图的区别? 34.你如何设计负载?标准是什么? 35.Vuser_init中包括什么内容? 36. Vuser_end中包括什么内容? 37.什么是think time?think_time有什么用? 38.标准日志和扩展日志的区别是什么? 39.解释以下函数及他们的不同之处。 Lr_debug_message Lr_output_message Lr_error_message Lrd_stmt Lrd_fetch 40.什么是吞吐量? 41.场景设置有哪几种方法

111

标签:/tmp   获取默认   取消   ppi   orm   ppa   推荐   message   sql   

原文地址:http://www.cnblogs.com/tester-l/p/8075377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!