Appium里面怎么实现 左右uiautomator滑动屏幕幕

你正在使用的浏览器版本过低,将不能正常浏览和使用知乎。Python脚本在Appium库上对移动应用实现自动化测试
投稿:goldensun
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了使用Python的Appium库对移动应用实现自动化测试的教程,属于Python脚本的一个自动化应用,需要的朋友可以参考下
&采用进行自动化的功能性测试最酷的一点是,你可以使用具有最适合你的测试工具的任何一门语言来写你的测试代码。大家选择最多的一个测试编程语言就是Python。 使用Appium和Python为iOS和Android应用编写测试代码非常容易。
在这篇博文中我们将详细讲解使用Appium下的对一个进行测试所涉及的各个步骤,而对Android应用进行测试所需的步骤与此非常类似。
开始,先自/appium/appiumfork并clone Appium,然后按照安装指南,在你的机器上安装好Appium。
我还需要安装Appium的所有依赖并对样例apps进行编译。在Appium的工作目录下运行下列命令即可完成此任务:
$ ./reset.sh --ios
编译完成后,就可以运行下面的命令启动Appium了:
$ grunt appium
现在,Appium已经运行起来了,然后就切换当前目录到sample-code/examples/python。接着使用pip命令安装所有依赖库(如果不是在虚拟环境virtualenv之下,你就需要使用sudo命令):
$ pip install -r requirements.txt
接下来运行样例测试:
$ nosetests simple.py
既然安装完所需软件并运行了测试代码,大致了解了Appium的工作过程,现在让我们进一步详细看看刚才运行的样例测试代码。该测试先是启动了样例应用,然后在几个输入框中填写了一些内容,最后对运行结果和所期望的结果进行了比对。首先,我们创建了测试类及其setUp方法:
classTestSequenceFunctions(unittest.TestCase):
defsetUp(self):
app=os.path.join(os.path.dirname(__file__),
'../../apps/TestApp/build/Release-iphonesimulator',
'TestApp.app')
app=os.path.abspath(app)
self.driver=webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities={
'browserName':'iOS',
'platform':'Mac',
'version':'6.0',
'app': app
self._values=[]
“desired_capabilities”参数用来指定运行平台(iOS 6.0)以及我们想测试的应用。接下来我们还添加了一个tearDown方法,在每个测试完成后发送了退出命令:
deftearDown(self):
self.driver.quit()
最后,我们定义了用于填写form的辅助方法和主测试方法:
def_populate(self):
# populate text fields with two random number
elems=self.driver.find_elements_by_tag_name('textField')
foreleminelems:
rndNum=randint(0,10)
elem.send_keys(rndNum)
self._values.append(rndNum)
deftest_ui_computation(self):
# populate text fields with values
self._populate()
# trigger computation by using the button
buttons=self.driver.find_elements_by_tag_name("button")
buttons[0].click()
# is sum equal ?
texts=self.driver.find_elements_by_tag_name("staticText")
self.assertEqual(int(texts[0].text),self._values[0]+self._values[1])
就是这样啦!Appium的样例测试代码中还有许多Python的例子。如果你对使用Nose和Python来运行Appium测试有任何问题或看法,烦请告知。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具Appium之java API
我的图书馆
Appium之java API
AppiumDriver& getAppStrings()& 默认系统语言对应的Strings.xml文件内的数据。& driver.getAppStrings(String language)& 查找某一个语言环境对应的字符串文件Strings.xml内数据& sendKeyEvent(int key)& 按下某个键,具体哪个键由key值决定,key值定义在AndroidKeyCode类中& sendKeyEvent(int key, Integer metastate)& 按下某个键的同时按下附加键(Ctrl/Alt/Shift等),具体是哪些键,由key值(AndroidKeyCode类中定义)和metastate(AndroidKeyMetastate类中定义)决定。& currentActivity()& 获取当前activity,比如(.ApiDemos)& isAppInstalled(String bundleId)& 根据bundleId来判断该应用是否已经安装& installApp(String appPath)& 安装app,appPath为应用的本地路径& removeApp(String bundleId)& &&& 卸载app.bundleId在android中代表的是报名,而在ios中有专门的bundleId号。& & closeApp()& 关闭应用,其实就是按home键把应用置于后台& launchApp()& 启动应用& resetApp()& &&& 先closeApp然后在launchAPP& & pushFile(String remotePath, byte[] base64Data)& 将字符数组用64位格式写到远程目录的某个文件中。也可以理解为把本地文件push到设备上。& pullFile(String remotePath)& &&& 将设备上的文件pull到本地硬盘上& & pullFolder(String remotePath)& 将设备上的文件夹pull到本地硬盘上,一般远程文件为/data/local/tmp下的文件。& setNetworkConnection(NetworkConnectionSetting connection)& 设置手机的网络连接状态,可以开关蓝牙、wifi、数据流量。通过NetworkConnectionSetting中的属性来设置各个网络连接的状态。& getNetworkConnection()& openNotifications()& 打开通知栏& runAppInBackground(int seconds)& 与resetApp类似,区别是resetApp关闭后立即启动,而这个方法是关闭后等待seconds秒后再启动。& hideKeyboard()& ios隐藏键盘& hideKeyboard(String strategy, String keyName)& 隐藏键盘,只能用于ios上。& performTouchAction(TouchAction touchAction)& 执行一个touch动作,该touch动作是由TouchAction封装的。& performMultiTouchAction(MultiTouchAction multiAction)& 执行多步touch动作,由MultiTouchAction封装的多步操作。& tap(int fingers, WebElement element, int duration)& 点击element控件中心点按下,duration*5毫秒秒后松开,如此重复fingers次。& tap(int fingers, int x, int y, int duration)& 点击(x,y)点按下,duration*5毫秒后松开,如此重复fingers次。& swipe(int startx, int starty, int endx, int endy, int duration)& 从(startx,starty)滑到(endx,endy),分duration步滑,每一步用时是5毫秒。& pinch(WebElement el)& 2个手指操作控件,从对角线向中心点滑动。& pinch(int x, int y)& 以(x,y)为基准,计算得出(x,y-100),(x,y+100)两个点,然后2个手指按住这两个点同时滑到(x,y)& zoom(WebElement el)& 与pinch(el)的动作刚好相反。两个手指由控件的中心点慢慢向控件的左顶点后右底点滑动。& zoom(int x, int y)& 和pinch(x,y)相反。两个手指从(x,y)点开始向(x,y-100)和(x,y+100)滑动。& getNamedTextField(String name)& 一般用在ios中。根据accessibility id获得控件对象。& &&& endTestCoverage(String intent, String path)& & 结束测试覆盖率的检测。(没用过,不太了解)path为.ec文件的路径。& lockScreen(int seconds)& 锁屏多少秒后解锁(使用的时候提示还没实现该方法)& shake()& 模拟摇晃手机(目前还没实现)& scrollTo(String text)& 滚动到某个text属性为指定的字符串的控件& scrollToExact(String text)& 滚动到某个text属性包含传入的字符串的控件& context(String name)& 设置上下文& getContextHandles()& 可用上下文& getContext()& 当前上下文& rotate(ScreenOrientation orientation)& 设置屏幕横屏或者竖屏& getOrientation()& 获取当前屏幕的方向& findElementByIosUIAutomation(String using)& 利用ios中的uiautomation中的属性来获取控件& findElementsByIosUIAutomation(String using)& 和上面一样,不过获得的是多个控件& findElementByAndroidUIAutomator(String using)& 利用android的uiautoamtor中的属性来获取单个控件。& findElementsByAndroidUIAutomator(String using)& 和上面一样,但是该方法获得是多个控件& findElementByAccessibilityId(String using)& 利用accessibility id来获取单个控件& findElementsByAccessibilityId(String using)& &&& 利用accessibility id来获得多个控件&
TA的最新馆藏2491人阅读
appium(17)
Android(17)
PYTHON(56)
在做appium自动化中,升级appium到1.5.2版本使用swipe方法实现上下左右滑动时候,,遇到之前写的上滑屏幕方法没有见效,而是变成下滑,但是在1.4版本里使用正常,经过调试和查看appium日志,发现1.5版本传入的参数变成偏移量,赶紧改了下,终于又能上滑屏幕了。
swipe(self,start_x,start_y,end_x,end_y,duration=None)
在appium1.5版本以下,swipe的方法中的end_x和end_y是实际要滑动的目的地坐标
但是在1.5版本以上的,end_x和end_y是相对于前面start_x和start_y坐标的偏移量。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:169127次
积分:2511
积分:2511
排名:第14013名
原创:70篇
转载:127篇
评论:22条
(15)(2)(2)(3)(3)(3)(1)(2)(2)(5)(16)(11)(3)(14)(1)(3)(5)(9)(10)(32)(10)(17)(9)(4)(1)(1)(7)(7)Appium 滑动问题 - dengke的个人空间 - 51Testing软件测试网 51Testing软件测试网-中国软件测试人的精神家园
做一个被尊重的测试工程师
Appium 滑动问题
& 19:02:42
/ 个人分类:
//根据方向滑动JavascriptExecutor js = (JavascriptExecutor)HashMap&String, String& scrollObject = new HashMap&String, String&();scrollObject.put("direction", "left");scrollObject.put("element", ((RemoteWebElement) element).getId());js.executeScript("mobile: scroll", scrollObject);//根据坐标滑动&&& public void swipe() {&&& &&& try {&&& &&& &&& Thread.sleep(2000);&&& &&& } catch (Exception e) {&&& &&& &&& e.printStackTrace();&&& &&& }&&& &&& JavascriptExecutor js = (JavascriptExecutor)&&& &&& HashMap&String, Double& swipeObj = new HashMap&String, Double&();&&& &&& swipeObj.put("startX", 420.0);&&& &&& swipeObj.put("startY", 400.00);&&& &&& swipeObj.put("endX", 30.0);&&& &&& swipeObj.put("endY", 400.0);&&& &&& swipeObj.put("duration", 0.4);&&& &&& // 4个滑动页面&&& &&& for (int i = 0; i & 3; i++) {&&& &&& &&& try {&&& &&& &&& &&& js.executeScript("mobile: swipe", swipeObj);&&& &&& &&& } catch (WebDriverException ex) {&&& &&& &&& &&& ex.printStackTrace();&&& &&& &&& }&&& &&& }&&& }相关链接:/html/13/n-863113.html

我要回帖

更多关于 手机屏幕滑动没反应 的文章

 

随机推荐