Appium ruby客户端介绍

ruby_lib是一个支持Appium服务端的ruby客户端

支持Appium服务端的客户端列表,可在这里查看

Appium_lib是为Appium用ruby写跨平台的测试的客户端,它为用户提供了driver对象和很多有用的方法,来使用Appium

需要

Ruby: 2.2+

更新和安装

更新

gem update --system

安装

gem uninstall -aIx appium_lib
gem install --no-rdoc --no-ri appium_lib

ios端的使用

元素查看工具:

Appium桌面客户端

(ARC)Appium Ruby Console

常用元素定位方法

注:所有查询定位都在当前App显示视图中处理

1、使用button查找按钮

first_button // 查找第一个button
button(value) // 查找第一个包含value的button,返回[UIAButton|XCUIElementTypeButton]对象
buttons(value) // 查找所有包含value的所有buttons,返回[Array<UIAButton|XCUIElementTypeButton>]对象 

eg:
button("登录") // 查找登录按钮

2、使用textfield查找输入框

first_textfield // 查找第一个textfield
textfield(value) // 查找第一个包含value的textfield,返回[TextField]

eg:
textfield("用户名") // 查找

3、使用accessibility_id查找

id(value) // 返回id等于value的元素

eg:
id("登录") // 返回登录按钮
id("登录页面") // 返回登录页面

注意:iOS设置accessibility_id的方法self.view.accessibilityLabel = "登录页面",ios的button和textfield通过设置text就能指定accessibility_id,所以无需设置accessibilityLabel,但view需要手动设置accessibilityLabel

4、通过find查找

find(value) // 返回包含value的元素

eg:
find("登录页面")

更多用法请看这里

常用事件

1、点击事件

// 通过坐标点击
tap(x: 68, y: 171)

// 通过按钮元素点击
button("登录").click

2、手势事件

// 滑动手势
swipe(direction:, element: nil) // direction - Either 'up', 'down', 'left' or 'right'.


eg: 上滑手势
swipe(direction: "up", element: nil)

更多用法请看这里

延时

// wait
wait { find("登录页面") } // 等待登录页面加载完成

// sleep
sleep(2) // 延时2秒

rspec断言

1、相等

expect(actual).to eq(expected)  # passes if actual == expected
expect(actual).to eql(expected) # passes if actual.eql?(expected)
expect(actual).not_to eql(not_expected) # passes if not(actual.eql?(expected))

2、比较

expect(actual).to be >  expected
expect(actual).to be >= expected
expect(actual).to be <= expected
expect(actual).to be <  expected
expect(actual).to be_within(delta).of(expected)

3、类型判断

expect(actual).to be >  expected
expect(actual).to be >= expected
expect(actual).to be <= expected
expect(actual).to be <  expected
expect(actual).to be_within(delta).of(expected)

4、Bool值比较

expect(actual).to be_truthy   # passes if actual is truthy (not nil or false)
expect(actual).to be true     # passes if actual == true
expect(actual).to be_falsy    # passes if actual is falsy (nil or false)
expect(actual).to be false    # passes if actual == false
expect(actual).to be_nil      # passes if actual is nil
expect(actual).to_not be_nil  # passes if actual is not nil

5、错误

expect { ... }.to raise_error
expect { ... }.to raise_error(ErrorClass)
expect { ... }.to raise_error("message")
expect { ... }.to raise_error(ErrorClass, "message")

6、异常

expect { ... }.to throw_symbol
expect { ... }.to throw_symbol(:symbol)
expect { ... }.to throw_symbol(:symbol, 'value')

更多使用,请参考这里

小技巧

可通过methods方法,查看元素所有可用的属性和方法

eg:

并且(/^点击返回$/) do
  puts driver.methods
end

methods:

[:network_connection_type, :network_connection_type=, :location, :location=, :set_location, :touch, :lock, :unlock, :reset, :window_size, :shake, :launch_app, :close_app, :device_locked?, :device_time, :current_context, :open_notifications, :toggle_airplane_mode, :current_activity, :current_package, :get_system_bars, :get_display_density, :is_keyboard_shown, :get_network_connection, :get_performance_data_types, :available_contexts, :set_context, :app_strings, :install_app, :remove_app, :app_installed?, :background_app, :hide_keyboard, :press_keycode, :long_press_keycode, :set_immediate_value, :push_file, :pull_file, :pull_folder, :get_settings, :update_settings, :touch_actions, :multi_touch, :touch_id, :toggle_touch_id_enrollment, :ime_deactivate, :ime_activate, :ime_available_engines, :ime_active_engine, :ime_activated, :find_element, :find_elements, :local_storage, :session_storage, :remote_status, :rotate, :rotation=, :orientation, :session_id, :save_screenshot, :screenshot_as, :file_detector=, :[], :inspect, :first, :close, :all, :action, :quit, :get, :ref, :title, :script, :window_handle, :window_handles, :mouse, :keyboard, :browser, :navigate, :switch_to, :manage, :current_url, :page_source, :execute_script, :execute_async_script, :capabilities, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :to_yaml, :to_yaml_properties, :psych_to_yaml, :cucumber_instance_exec, :to_json, :instance_of?, :public_send, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :kind_of?, :instance_variables, :tap, :method, :public_method, :singleton_method, :awesome_print, :is_a?, :extend, :define_singleton_method, :awesome_inspect, :to_enum, :enum_for, :ai, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :object_id, :display, :send, :gem, :to_s, :nil?, :hash, :class, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untaint, :untrust, :trust, :untrusted?, :frozen?, :!, :==, :!=, :send, :equal?, :instance_eval, :instance_exec, :id, :should, :should_not]

attribute:

An unknown server-side error occurred while processing the command. Original error: The attribute 'row' is unknown. Valid attribute names are: (
UID,
accessibilityContainer,
accessible,
enabled,
frame,
label,
name,
rect,
type,
value,
visible,
wdAccessibilityContainer,
wdAccessible,
wdEnabled,
wdFrame,
wdLabel,
wdName,
wdRect,
wdType,
wdUID,
wdValue,
wdVisible
)

Array methods

[:values_at, :delete_at, :delete_if, :reject!, :transpose, :fill, :assoc, :rassoc, :to_h, :uniq, :uniq!, :compact, :include?, :flatten!, :shuffle!, :flatten, :sample, :compact!, :shuffle, :repeated_permutation, :repeated_combination, :combination, :product, :permutation, :bsearch_index, :bsearch, :rotate!, :&, :*, :+, :-, :sort, :count, :find_index, :select, :reject, :collect, :map, :first, :any?, :pack, :reverse_each, :zip, :take, :take_while, :drop, :drop_while, :cycle, :insert, :|, :index, :rindex, :replace, :clear, :<=>, :<<, :==, :[], :[]=, :reverse, :empty?, :eql?, :concat, :reverse!, :shelljoin, :inspect, :delete, :length, :size, :each, :slice, :slice!, :to_ary, :to_a, :to_s, :dig, :hash, :at, :fetch, :frozen?, :last, :push, :pop, :shift, :unshift, :join, :rotate, :each_index, :sort!, :sort_by!, :collect!, :map!, :select!, :keep_if, :to_json, :find, :entries, :sort_by, :grep, :grep_v, :detect, :find_all, :flat_map, :collect_concat, :inject, :reduce, :partition, :group_by, :all?, :one?, :none?, :min, :max, :minmax, :min_by, :max_by, :minmax_by, :member?, :each_with_index, :each_entry, :each_slice, :each_cons, :each_with_object, :chunk, :slice_before, :slice_after, :slice_when, :chunk_while, :lazy, :to_set, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :to_yaml, :to_yaml_properties, :psych_to_yaml, :cucumber_instance_exec, :instance_of?, :public_send, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :kind_of?, :instance_variables, :tap, :method, :public_method, :singleton_method, :awesome_print, :is_a?, :extend, :define_singleton_method, :awesome_inspect, :to_enum, :enum_for, :ai, :===, :=~, :!~, :respond_to?, :freeze, :object_id, :display, :send, :gem, :nil?, :class, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untaint, :untrust, :trust, :untrusted?, :!, :!=, :send, :equal?, :instance_eval, :instance_exec, :id, :should, :should_not]

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,635评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,628评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,971评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,986评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,006评论 6 394
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,784评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,475评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,364评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,860评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,008评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,152评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,829评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,490评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,035评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,156评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,428评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,127评论 2 356

推荐阅读更多精彩内容

  • 如果你受了伤或则生病,那么一群细胞会向内破裂,将有害的毒素喷溅到周围的细胞中,并形成发炎区域,这一过程称为“细胞的...
    Constance1993阅读 263评论 0 0
  • 【导入新课】 课前三分钟播放《滚滚长江东逝水》。 刚才我所播放的歌曲应该是大家耳熟能详的,它是《三国演义》的片头曲...
    雪蓉阅读 383评论 0 1
  • 慈禧,晚清的代言人,集权势于一身,生前极尽奢侈,享尽荣华富贵,死后背上了卖国贼的骂名,遭到成千上万人的唾骂,但其实...
    罗掌柜real阅读 741评论 0 0
  • 在风中冻成木头 让声音变成雕塑 —— 车水马龙 是夜的残念 灯光与星火 吞噬着苦难的灵魂 —— 当尘土升起 是落寞...
    风尘馥馥阅读 296评论 0 0
  • 东君过处柳轻烟,细雨催花次第妍。 祈福龙王司禄职,人间五谷溢丰田。
    惠芝兰心阅读 165评论 0 0