Appium 求助:1.多指手势:touchCount 的设置;2.方向:ruby 里如何设置 app 的方向

twh_eastasia · 2014年01月20日 · 最后由 恒温 回复于 2014年01月20日 · 1315 次阅读

运行环境:osx 10.9,appium 0.12.3,真机 ios 7.0.3, cucumber 测试框架

参考例子是 https://github.com/appium/appium/blob/master/docs/gestures.md

1.看到 tap/flick/swipe 方法中都有 touchCount 参数,可以表示使用多个手指,但是自己在实际使用的时候发现并不是我想要的结果。
比如我在 swipe 方法里设置 touchCount=4 ,实际结果好像是 4 个手指都划在了同一点,而不是 4 个不同的点。如果都是指在一个点上,那这参数就没意义了。
不过估计大部分原因应该是我哪里没设置好导致的,求大神解惑。

2.我想要在测试的时候设置 app 的方向,看到例子里没有 ruby 的方法,然后我就自己试着去猜了一下,结果都是报错 “undefined method error”。
所以还想请教下 ruby 里如何设置 app 的方向。

请各位大神不吝赐教啊!

附上 code:

When /^I swipe on the screen$/ do
    selenium.execute_script "mobile: swipe", :startX => 300, :startY => 200, :endX => 100, :endY => 200, :touchCount => 4
end

When /^I set the orentation$/ do
    selenium.setOrientation "PORTRAIT"
    #selenium.orientation = "PORTRAIT"
    #selenium.execute_script "mobile: setOrientation", :orientation => "PORTRAIT"
end
共收到 14 条回复 时间 点赞

贴代码呗,别截图。

@lihuazhang 好的,下次一定直接贴代码

首先 Orientation 应该都支持的,可以在 caps 里面设置。你可以试试看,
第二,确保你的 app 支持 Orientation


def capabilities
  {
    'browserName' => '',
    'platform' => 'Mac',
    'device' => 'iPhone Simulator',
    'version' => '6.0',
    'app' => absolute_app_path,
     'deviceOrientation'=> 'LANDSCAPE'
  }
end

#2 楼 @twh_eastasia 你要实时改的话, setOrientation 方法应该可以啊

@lihuazhang hi
刚刚我又去试了一下 setOrientation 方法,还是又报错,试之前我确认了两点:

  1. 测试的 app 支持 landscape 和 portrait(我装完 app,在真机上打开自动旋转试过,两个方向都可以) 2.capabilities 里包含了 ruby deviceOrientation' => 'LANDSCAPE'

然后再去跑测试,结果:
undefined method `setOrientation' for # (NoMethodError)

#5 楼 @twh_eastasia 看了下,应该是 rubybinding 的 webdriver 还没做这些方法。

#6 楼 @lihuazhang 嗯,那就是 ruby 暂不支持设置 app 方向了,谢谢;
不过还有第一个问题没搞明白,是否也可以点拨一下?

#7 楼 @twh_eastasia 可以曲线救国,

selenium.execute_script("target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT);");

直接传 UIAutomation 的脚本过去。

第一个问题,我没试过。等别人来回答吧。

@twh_eastasia

When /^I set the orentation$/ do
    selenium.rotation = "PORTRAIT"
end

可以试试看这个么?

#8 楼 @lihuazhang 嗯,好的,试试看

#9 楼 @lihuazhang
刚刚你说的两种方法都实验了下:

第一种直接传 UIAutomation 的脚本的方法仍然不起作用
第二种设置在运行时也会报错,但是在错误信息里有提示,报错为
expected [:landscape, :portrait], got "PORTRAIT" (ArgumentError)
于是稍微改动了下第二种方法,

selenium.rotation = :portrait

然后就真的改变方向了!😃

#11 楼 @twh_eastasia 顶,我看了源码,好像是传 symbol 的。ruby 好像是实现了。但是 开放出来的 api

在 bridge.rb 里面

def setScreenOrientation(orientation)
         execute :setScreenOrientation, {}, :orientation => orientation
       end

       def getScreenOrientation
         execute :getScreenOrientation
       end

这两个方法,感觉没用。

rotation 方法是在 rotatable.rb 里面的

def rotation=(orientation)
     unless ORIENTATIONS.include?(orientation)
       raise ArgumentError, "expected #{ORIENTATIONS.inspect}, got #{orientation.inspect}"
     end

     bridge.setScreenOrientation(orientation.to_s.upcase)
   end
   alias_method :rotate, :rotation=

#12 楼 @lihuazhang
看下 ORIENTATIONS 这个常量是啥,应该就知道 orientation 是啥格式了

#13 楼 @twh_eastasia 我看了下,因为 remote.rb 把 Bridge 下面的代码都 private 了。 只有 rotatable.rb 才暴露了出来。

require 'uri'

require 'selenium/webdriver/remote/capabilities'
require 'selenium/webdriver/remote/bridge'
require 'selenium/webdriver/remote/server_error'
require 'selenium/webdriver/remote/response'
require 'selenium/webdriver/remote/commands'
require 'selenium/webdriver/remote/http/common'
require 'selenium/webdriver/remote/http/default'

module Selenium
  module WebDriver

    # @api private
    module Remote

    end
  end
end




需要 登录 后方可回复, 如果你还没有账号请点击这里 注册