super-test 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGE.txt +9 -0
  3. data/README.txt +13 -0
  4. data/bin/idb +19 -0
  5. data/bin/ii +113 -0
  6. data/bin/istart_mock +36 -0
  7. data/bin/istop_mock +16 -0
  8. data/bin/kk +181 -0
  9. data/bin/rubyatp +42 -0
  10. data/bin/start_mock +36 -0
  11. data/bin/stop_mock +16 -0
  12. data/bin/xgo +45 -0
  13. data/conf/conf.rb +11 -0
  14. data/conf/db03.yml +31 -0
  15. data/conf/db13.yml +37 -0
  16. data/conf/db19.yml +33 -0
  17. data/conf/online.yml +32 -0
  18. data/conf/super_test.yml +40 -0
  19. data/conf/system.yml +26 -0
  20. data/conf/sz00.yml +31 -0
  21. data/conf/sz06.yml +34 -0
  22. data/conf/wise00.yml +11 -0
  23. data/data/case.house +0 -0
  24. data/data/char.house +0 -0
  25. data/data/images/Bluehills.jpg +0 -0
  26. data/data/images/Sunset.jpg +0 -0
  27. data/data/images/Waterlilies.jpg +0 -0
  28. data/data/images/Winter.jpg +0 -0
  29. data/data/query.house +18595 -0
  30. data/data/user.house +8 -0
  31. data/lib/action/module/check_action.rb +58 -0
  32. data/lib/action/module/cnnt_action.rb +161 -0
  33. data/lib/action/module/datacenter_action.rb +48 -0
  34. data/lib/action/module/http_pack_helper.rb +163 -0
  35. data/lib/action/module/httpserver_action.rb +297 -0
  36. data/lib/action/module/inc.rb +21 -0
  37. data/lib/action/module/mcpack_action.rb +57 -0
  38. data/lib/action/module/sql_action.rb +84 -0
  39. data/lib/action/module/ssh_action.rb +37 -0
  40. data/lib/action/system/user_action.rb +180 -0
  41. data/lib/common/appium_helper.rb +217 -0
  42. data/lib/common/atp_helper.rb +74 -0
  43. data/lib/common/atp_report.rb +344 -0
  44. data/lib/common/data_house.rb +405 -0
  45. data/lib/common/data_model.rb +87 -0
  46. data/lib/common/http/assert_helper.rb +343 -0
  47. data/lib/common/http/fix_hpricot.rb +118 -0
  48. data/lib/common/http/html_helper.rb +362 -0
  49. data/lib/common/http/http_helper.rb +469 -0
  50. data/lib/common/http/multipart.rb +81 -0
  51. data/lib/common/isandbox_helper.rb +195 -0
  52. data/lib/common/json_helper.rb +43 -0
  53. data/lib/common/mock_helper.rb +168 -0
  54. data/lib/common/mtop_helper.rb +141 -0
  55. data/lib/common/myconf_helper.rb +49 -0
  56. data/lib/common/mylog_helper.rb +77 -0
  57. data/lib/common/pairwise.rb +121 -0
  58. data/lib/common/query_house.rb +89 -0
  59. data/lib/common/report_helper.rb +97 -0
  60. data/lib/common/robot_helper.rb +85 -0
  61. data/lib/common/socket/check.rb +325 -0
  62. data/lib/common/socket/conf_modifier.rb +149 -0
  63. data/lib/common/socket/context.rb +55 -0
  64. data/lib/common/socket/data.rb +392 -0
  65. data/lib/common/socket/data_helper.rb +41 -0
  66. data/lib/common/socket/env.rb +317 -0
  67. data/lib/common/socket/inc.rb +24 -0
  68. data/lib/common/socket/log.rb +213 -0
  69. data/lib/common/socket/log4s.rb +58 -0
  70. data/lib/common/socket/log_helper.rb +332 -0
  71. data/lib/common/socket/my_sql.rb +77 -0
  72. data/lib/common/socket/net.rb +74 -0
  73. data/lib/common/socket/network.rb +115 -0
  74. data/lib/common/socket/rlib/conf_modifier.rb +130 -0
  75. data/lib/common/socket/rlib/data_helper.rb +33 -0
  76. data/lib/common/socket/rlib/log_helper.rb +303 -0
  77. data/lib/common/socket/rlib/process_helper.rb +91 -0
  78. data/lib/common/socket/stub.rb +276 -0
  79. data/lib/common/socket/util.rb +266 -0
  80. data/lib/patterns/inc.rb +10 -0
  81. data/lib/patterns/mc_base_pattern.rb +474 -0
  82. data/lib/patterns/some_pattern.rb +145 -0
  83. data/lib/super_test.rb +114 -0
  84. data/log/super_test.log +0 -0
  85. data/log/super_test.log.wf +0 -0
  86. data/test/cover_me.rb +6 -0
  87. data/tool/jenny +0 -0
  88. data/tool/mcsend/mcsend2 +0 -0
  89. data/tool/mcsend/mcsend2_shead +0 -0
  90. data/tool/mcserver/conf/mcserver.conf +77 -0
  91. data/tool/mcserver/conf/mcserverauthip +17 -0
  92. data/tool/mcserver/mcserver +0 -0
  93. data/tool/mcserver/mcserver_trans +0 -0
  94. data/tool/mysql +0 -0
  95. data/tool/net/mcsend/mcsend +0 -0
  96. data/tool/net/mcsend/mcsend_trans +0 -0
  97. data/tool/net/mcsend/nshead.data +7 -0
  98. data/tool/net/mcsend/res_nshead.data +7 -0
  99. data/tool/net/my_client/my_client +0 -0
  100. data/tool/net/tsclient/client.tcl +205 -0
  101. data/tool/others/kk +190 -0
  102. data/tool/others/rubyatp +42 -0
  103. data/tool/others/supertest_install.sh +34 -0
  104. data/tool/trip/idb +0 -0
  105. data/tool/ts-agent/nshead.bft +12 -0
  106. data/tool/ts-agent/server.conf +10 -0
  107. data/tool/ts-agent/server.tcl +376 -0
  108. metadata +275 -0
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '../../conf/')
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '.')
3
+ #!/usr/bin/env ruby
4
+ #coding: utf-8
5
+
6
+ require 'check_action'
7
+ require 'mcpack_action'
8
+ require 'sql_action'
9
+ require 'ssh_action'
10
+ require 'cnnt_action'
11
+ require 'httpserver_action'
12
+
13
+ include CheckActionHelper
14
+ include McpackActionHelper
15
+ include SQLActionHelper
16
+ include SSHActionHelper
17
+ include CNNTActionHelper
18
+ include HttpServerActionHelper
19
+
20
+
21
+
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ module McpackActionHelper
5
+
6
+ # === 功能:
7
+ # 发送mcpack包
8
+ #
9
+ # === 参数解释:
10
+ #
11
+ # - headtype 头类型目前支持: nshead shead
12
+ # - version mcpack的版本号
13
+ # - host 目的模块的ip
14
+ # - port 目的模块的端口
15
+ # - timeout 发送的超时时间
16
+ # - content mcapck包的文本
17
+ # - reserved1 保留字段1
18
+ # - reserved2 保留字段2
19
+ #
20
+ # === Example:
21
+ # mcpack_send "nshead", 1, "10.81.12.148", 9109, 100, 1, 1, "{}"
22
+ #
23
+ # === 检查的方法:
24
+ # assert_head "正则式"
25
+ # assert_body "正则式"
26
+ # mcpack_send "{}"
27
+ def mcpack_send(headtype=HEADTYPE, version=VERSION, host=HOST, port=PORT, timeout=TIMEOUT, reserved1=RESERVED1, reserved2=RESERVED2, content)
28
+ toolspath = TOOL_ROOT+"/mcsend/"
29
+ if(headtype=="nshead")
30
+ cmdtxt="cd #{toolspath}; ./mcsend2 #{version} #{host} #{port} #{timeout} \"#{content}\" #{reserved1}"
31
+ ret=`#{cmdtxt}`
32
+ ary=ret.split "\n"
33
+ Context.set("IOHEAD", ary[0])
34
+ Context.set("IOBODY", ary[1])
35
+ elsif(headtype=="shead")
36
+ cmdtxt="cd #{toolspath}; ./mcsend2_shead #{version} #{host} #{port} #{timeout} \"#{content}\" #{reserved1} #{reserved2}"
37
+ ret=`#{cmdtxt}`
38
+ ary=ret.split "\n"
39
+ Context.set("IOHEAD", ary[0])
40
+ Context.set("IOBODY", ary[1])
41
+ else
42
+ puts "Not support headtype: #{headtype} yet"
43
+ end
44
+ #puts cmdtxt
45
+ $log.debug cmdtxt
46
+ $log.debug Context.get("IOHEAD")
47
+ $log.debug Context.get("IOBODY")
48
+ end
49
+
50
+
51
+ end
52
+
53
+
54
+ if __FILE__ == $0
55
+ end
56
+
57
+
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ module SQLActionHelper
5
+
6
+ # === 功能:
7
+ # 发送sql请求
8
+ #
9
+ # === 参数解释:
10
+ #
11
+ # - host 机器名或ip
12
+ # - port 端口
13
+ # - user 用户名
14
+ # - password 密码
15
+ # - database 数据库名字
16
+ # - sqltxt sql语句
17
+ #
18
+ # === 注意:
19
+ # 需要注意的是在访问之前需要保证使用的用户和密码具有远程访问的权限
20
+ #
21
+ # === Example:
22
+ # sql_send "space", "show tables;"
23
+ #
24
+ # === 检查的方法:
25
+ # assert_body "正则式"
26
+ def sql_send(host=HOST, port=PORT, user=USER, password=PASSWORD, database, sqltxt)
27
+ toolspath = TOOL_ROOT
28
+ cmdtxt="cd #{toolspath}; ./mysql -h #{host} -P#{port} -u#{user} -p#{password} \"#{database}\" -e \"#{sqltxt}\""
29
+ ret=`#{cmdtxt}`
30
+ Context.set("IOBODY", ret)
31
+ puts cmdtxt
32
+ $log.debug cmdtxt
33
+ $log.debug Context.get("IOBODY")
34
+ end
35
+
36
+
37
+
38
+ # === 功能:
39
+ # 发送sql请求
40
+ #
41
+ # === 参数解释:
42
+ #
43
+ # - host 机器名或ip
44
+ # - port 端口
45
+ # - user 用户名
46
+ # - password 密码
47
+ # - database 数据库名字
48
+ # - sqltxt sql语句
49
+ #
50
+ # === 注意:
51
+ # 需要注意的是在访问之前需要保证使用的用户和密码具有远程访问的权限
52
+ #
53
+ # === Example:
54
+ # sql_send_arr "space", "show tables;"
55
+ #
56
+ # === 返回值:
57
+ # 以二维数组格式返回
58
+ def sql_send_arr(host=HOST, port=PORT, user=USER, password=PASSWORD, database, sqltxt)
59
+ toolspath = TOOL_ROOT
60
+ if password.size !=0
61
+ cmdtxt="cd #{toolspath}; ./mysql -h #{host} -P#{port} -u#{user} -p#{password} \"#{database}\" -e \"#{sqltxt}\""
62
+ else
63
+ cmdtxt="cd #{toolspath}; ./mysql -h #{host} -P#{port} -u#{user} \"#{database}\" -e \"#{sqltxt}\""
64
+ end
65
+ #puts cmdtxt
66
+ ret=`#{cmdtxt}`
67
+ arr = []
68
+ i = 0
69
+ ret.each_line do |line|
70
+ arr[i] = line.split
71
+ i = i + 1
72
+ end
73
+ $log.debug cmdtxt
74
+ $log.debug arr
75
+ return arr
76
+ end
77
+
78
+ end
79
+
80
+
81
+ if __FILE__ == $0
82
+ end
83
+
84
+
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '.')
4
+
5
+ require 'net/ssh'
6
+
7
+
8
+ module SSHActionHelper
9
+
10
+ # === 本机或远程执行shell命令
11
+ #
12
+ # === 参数
13
+ # - host 机器
14
+ # - cmdtxt 命令
15
+ #
16
+ # === Example:
17
+ # ssh_cmd "ls"
18
+ def ssh_cmd host=HOST, user=USERNAME, password=PASSWORD, cmdtxt
19
+ if Util.is_localhost? (host) then
20
+ ret = system "#{cmdtxt}"
21
+ else
22
+ ret = Util.exe_ssh_cmd! host, cmdtxt, user, password
23
+ end
24
+ Context.set("IOBODY", ret)
25
+ $log.info "ssh_cmd #{cmdtxt}"
26
+ end
27
+
28
+
29
+
30
+ end
31
+
32
+
33
+
34
+ if __FILE__ == $0
35
+ end
36
+
37
+
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ #
4
+ # Author:: hanyu
5
+ # Date:: 2009.5.7
6
+
7
+ require 'common/myconf_helper'
8
+
9
+ module ActionHelper
10
+ include ConfigHelper
11
+
12
+ # 登录
13
+ #
14
+ # Example:
15
+ # user_A = User.new "ruguo", "passme123", "ruguo"
16
+ # login user_A
17
+ def login(user)
18
+ get "#{ENV['passport']}"
19
+ post "#{ENV['passport']}?login", {
20
+ :username => user.name,
21
+ :password => user.password
22
+ }
23
+ assert_grep "用户登录"
24
+ @user = user
25
+ $log.info "login user[#{user}] success!"
26
+ end
27
+
28
+ # 已废弃,请不要使用
29
+ # 参见 login
30
+ def login_raw(user)
31
+ get "#{ENV['passport']}"
32
+ post "#{ENV['passport']}?login", {
33
+ :username => user.name,
34
+ :password => user.password
35
+ }
36
+ end
37
+
38
+ # 登出
39
+ #
40
+ # Example:
41
+ # login User.new "ruguo", "passme123", "ruguo"
42
+ # logout
43
+ def logout
44
+ raise "must login first" unless login?
45
+ get "#{ENV['passport']}?logout",{},{
46
+ :referer => nil
47
+ }
48
+ assert_ok
49
+ @user = nil
50
+ $log.info "logout user[#{@user}] success!"
51
+ end
52
+
53
+ # 注册
54
+ #
55
+ # 因为注册地防作弊策略比较复杂,故此方法不是直接post数据,
56
+ # 而是先get注册页面,解析出防作弊策略的参数,再发送post请求
57
+ # 并且,由于验证码加解密算法仍未破解,故只能用于线下环境,验证码使用统一的aaaa
58
+ #
59
+ # Example:
60
+ # user_A = User.new "ruguo", "passme123", "ruguo"
61
+ # regist_user user_A
62
+ def regist_user(user)
63
+ # pass的防作弊策略,必须先请求注册页面获取crypt/k_k/k_v三个关键参数
64
+ get "#{ENV['passport']}?reg"
65
+ crypt = find_attr "form[@name='reg'] input[@name='crypt']", "value"
66
+ k_k = find_attr "form[@name='reg'] input[@name^='k']", "name"
67
+ k_v = find_attr "form[@name='reg'] input[@name^='k']", "value"
68
+
69
+ # pass的又一防作弊策略!! 访问这个页面是为了获取 BDUSS 的cookie
70
+ get "#{ENV['passport']}?verifypic"
71
+
72
+ # 配合pass的防作弊策略,必须停留5秒以上才能注册成功
73
+ sleep 5
74
+
75
+ post "#{ENV['passport']}?reg",{
76
+ #post "http://db-testing-space13.db01.baidu.com:4444/?reg",{
77
+ :aid => "",
78
+ :friend => "",
79
+ :tpl => "",
80
+ :tpl_ok => "",
81
+ :need_coin => "",
82
+ :need_pay => "",
83
+ :next_target => "",
84
+ :nick => "",
85
+ :pay_method => "",
86
+ :rand => "",
87
+ :regin => 0,
88
+ :skip_ok => "",
89
+ :uid => "",
90
+ :u => ENV['passport'],
91
+ :username => user.name,
92
+ :loginpass => user.password,
93
+ :verifypass => user.password,
94
+ :sex => user.sex,
95
+ :email => "#{user.name}@baidu.com",
96
+ :regin => 0,
97
+ :return_method => "GET",
98
+ :crypt => crypt,
99
+ k_k => k_v,
100
+ :verifycode => "aaaa"
101
+ }
102
+
103
+ assert_grep "恭喜您已经成功注册"
104
+ $log.info "regist_user user[#{user}] success!"
105
+ end
106
+
107
+ # 激活空间
108
+ #
109
+ # Example:
110
+ #
111
+ # user_A = User.new "ruguo", "passme123", "ruguo"
112
+ # actv_space user_A
113
+ def actv_space()
114
+ raise "must login first" unless login?
115
+ post "#{ENV['hi']}post/actv", {
116
+ :spSpaceName => @user.name+"的空间",
117
+ :spSpaceURL => @user.url
118
+ }
119
+ assert_grep "/sys/guide/portrait"
120
+ $log.info "actv_space user[#{@user}] success!"
121
+
122
+ end
123
+
124
+ # 判断是否登录
125
+ #
126
+ # Example:
127
+ #
128
+ # puts login? #=> false
129
+ # login "ruguo", "passme123"
130
+ # puts login? #=> true
131
+ def login?
132
+ @user != nil
133
+ end
134
+
135
+
136
+ # 上传用户头像
137
+ #
138
+ # === 参数说明:
139
+ # - img_file 用户头像的图片
140
+ #
141
+ # === Example:
142
+ # login User.new "sst_hy_1","passme123","sst_hy_1","ba1368616e6e7975353132311905"
143
+ # upload_portrait("#{$SUPER_ROOT_DATA}/images/Winter.jpg")
144
+ #
145
+ def upload_portrait(img_file)
146
+ raise "must login first" unless login?
147
+ raise "user[#{@user}] must have a portrait" if @user.portrait.nil?
148
+ post "#{ENV['himg']}sys/upload/#{@user.portrait}",{
149
+ :BrowserType =>1,
150
+ :cm =>1,
151
+ :ct =>4,
152
+ :spAlbumName =>"默认相册",
153
+ :spIsBlogPicAdd =>2,
154
+ :B2 =>"上传"
155
+ },{},{:f0 => img_file}
156
+ assert_grep 'parent.uploadstatus("0")'
157
+ $log.info "upload_portrait img_file[#{img_file}] success!"
158
+ end
159
+
160
+
161
+ end
162
+
163
+
164
+
165
+ if __FILE__ == $0
166
+ class MyTest < SystemTest # :nodoc:
167
+ def test_1
168
+ regist User.new "sst_hy_00"
169
+ end
170
+ def qtest_login
171
+ login User.new "ruguo2","aaaa"
172
+ end
173
+
174
+ def qtest_regist
175
+ regist User.new "sp_tt_hy_0"
176
+ end
177
+
178
+
179
+ end
180
+ end
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ #
4
+ # Author:: leiming.lm
5
+ # Date:: 2016.1.31
6
+
7
+ # 封装Appium库的核心模块
8
+ #
9
+ require 'appium_lib'
10
+
11
+ module AppiumHelper
12
+
13
+ # === 功能:
14
+ # 启动appium,初始化appium driver,
15
+ # 在supertest使用appium功能之前,你需要先调用它
16
+ # === 参数解释:
17
+ # - 无
18
+ #
19
+ # === Example:
20
+ # Example #1:
21
+ #
22
+ def start_appium
23
+ init_device
24
+ p 'app path为网路地址,正在下载安装请稍后...' if @caps['caps']['app'] && @caps['caps']['app'].match(/^http/)
25
+ $appium_driver.driver_quit unless $appium_driver.nil?
26
+ $appium_driver = Appium::Driver.new(@caps)
27
+ $appium_driver.start_driver
28
+ Appium.promote_appium_methods self.class
29
+ end
30
+
31
+ # === 功能:
32
+ # 与start_appium对应,您需要在用例退出之前调用stop_appium以完成appium的session清理
33
+ # === 参数解释:
34
+ # - 无
35
+ #
36
+ # === Example:
37
+ # Example #1:
38
+ #
39
+ def stop_appium
40
+ $appium_driver.driver_quit unless $appium_driver.nil?
41
+ end
42
+
43
+ # === 功能:
44
+ # 获取屏幕宽度
45
+ # === 参数解释:
46
+ # - 无
47
+ #
48
+ # === Example:
49
+ # Example #1:
50
+ #
51
+ def window_width
52
+ window_size.width
53
+ end
54
+
55
+ # === 功能:
56
+ # 获取屏幕高度
57
+ # === 参数解释:
58
+ # - 无
59
+ #
60
+ # === Example:
61
+ # Example #1:
62
+ #
63
+ def window_height
64
+ window_size.height
65
+ end
66
+
67
+ # === 功能:
68
+ # 向左滑动操作
69
+ # 坐标(start_x: width-1, start_y: height/2) -> 坐标(end_x: width/4, end_y: height/2)
70
+ # === 参数解释:
71
+ # - duration: 滑动所需时长,可以不加
72
+ #
73
+ # === Example:
74
+ # Example #1:
75
+ #
76
+ def swipe_left(duration = 500)
77
+ actions = Appium::TouchAction.new
78
+ width = window_width
79
+ height = window_height
80
+ swipe start_x: width-1, start_y: height/2, end_x: width/4, end_y: height/2, duration: duration
81
+ actions.perform
82
+ end
83
+
84
+ # === 功能:
85
+ # 向右滑动操作
86
+ # 坐标(start_x: width/4, start_y: height/2) -> 坐标(end_x: width-1, end_y: height/2)
87
+ # === 参数解释:
88
+ # - duration: 滑动所需时长,可以不加
89
+ #
90
+ # === Example:
91
+ # Example #1:
92
+ #
93
+ def swipe_right(duration = 500)
94
+ actions = Appium::TouchAction.new
95
+ width = window_width
96
+ height = window_height
97
+ swipe start_x: width/4, start_y: height/2, end_x: width-1, end_y: height/2, duration: duration
98
+ actions.perform
99
+ end
100
+
101
+ # === 功能:
102
+ # 上滑操作
103
+ # 坐标(start_x: width/2, start_y: height*0.8) -> 坐标(end_x: width/2, end_y: height*0.3)
104
+ # === 参数解释:
105
+ # - duration: 滑动所需时长,可以不加
106
+ #
107
+ # === Example:
108
+ # Example #1:
109
+ #
110
+ def swipe_up(duration = 500)
111
+ actions = Appium::TouchAction.new
112
+ width = window_width
113
+ height = window_height
114
+ swipe start_x: width/2, start_y: height*0.8, end_x: width/2, end_y: height*0.3, duration: duration
115
+ actions.perform
116
+ end
117
+
118
+ # === 功能:
119
+ # 下滑操作
120
+ # 坐标(start_x: width/2, start_y: height*0.3) -> 坐标(end_x: width/2, end_y: height*0.8)
121
+ # === 参数解释:
122
+ # - duration: 滑动所需时长,可以不加
123
+ #
124
+ # === Example:
125
+ # Example #1:
126
+ #
127
+ def swipe_down(duration = 500)
128
+ actions = Appium::TouchAction.new
129
+ width = window_width
130
+ height = window_height
131
+ swipe start_x: width/2, start_y: height*0.3, end_x: width/2, end_y: height*0.8, duration: duration
132
+ actions.perform
133
+ end
134
+
135
+ # === 功能:
136
+ # 长按操作
137
+ # 支持坐标与元素两种方式
138
+ # === 参数解释:
139
+ # - opts:
140
+ #
141
+ # @option element the element to press.
142
+ # @option x [integer] x co-ordinate to press on.
143
+ # @option y [integer] y co-ordinate to press on.
144
+ # @option duration [integer] Number of milliseconds to press.
145
+ #
146
+ # === Example:
147
+ # Example #1:
148
+ # opts = {:element=>find_elements_stable(:id,'com.taobao.trip.usercenter:id/usercenter_orderlist_title')[0], :duration=2000}
149
+ # press opts
150
+ #
151
+ def press(opts={})
152
+ # 默认2000ms,即2s
153
+ opts[:duration] = 2000 unless opts.has_key? :duration
154
+ Appium::TouchAction.new.long_press(opts).perform
155
+ end
156
+
157
+
158
+ # === 功能:
159
+ # 初始化当前设备信息,结果会存储在@desired_caps 这个Hash中
160
+ # === 参数解释:
161
+ # - 无
162
+ #
163
+ # === Example:
164
+ # Example #1:
165
+ #
166
+ def init_device
167
+ @caps = ConfigHelper::CONF["appium_driver"] || Hash.new
168
+
169
+ if @caps['caps']['platformName'].downcase === 'android'
170
+ # res = `adb devices`
171
+ # => "List of devices attached\n9e6d6de3\tdevice\nc8e86f6e\tdevice\n\n"
172
+ system 'adb devices > /dev/null 2>&1'
173
+ device_name = `adb devices`.split(' ')[4]
174
+ fail 'android 设备未连接' if device_name.nil?
175
+ platform_version = `adb -s #{device_name} shell getprop ro.build.version.release`.split(' ')[0]
176
+ @desired_caps = {
177
+ 'platformVersion' => "#{platform_version}",
178
+ 'deviceName' => "#{device_name}"
179
+ }
180
+ else
181
+ # ideviceinfo是一个ios手机基于ideviceinstaller的命令,在安装ifuse的时候回要求用户安装
182
+ # IDEviceinfo会返回当前ios设备的信息
183
+
184
+ # `ideviceinfo`.split("\n").each do |info|
185
+ # $device_name = (info.split(' ')[1] if info.to_s.include?('DeviceName:')) || nil
186
+ # p '------' unless $device_name.nil?
187
+ # $platform_version = (info.split(' ')[1] if info.to_s.include?('ProductVersio')) || nil
188
+ # $udid = (info.split(' ')[1] if info.to_s.include?('UniqueDeviceID')) || nil
189
+ # end
190
+
191
+ for info in `ideviceinfo`.split("\n")
192
+ if info.to_s.include?('DeviceName:')
193
+ @device_name = info.split(' ')[1]
194
+ end
195
+ if info.to_s.include?('ProductVersion')
196
+ @platform_version = info.split(' ')[1]
197
+ end
198
+ if info.to_s.include?('UniqueDeviceID')
199
+ @udid = info.split(' ')[1]
200
+ end
201
+ end
202
+ fail 'ios设备未连接' if (@device_name.nil? || @platform_version.nil? || @udid.nil?)
203
+ @desired_caps = {
204
+ 'platformVersion' => "#{@platform_version}",
205
+ 'deviceName' => "#{@device_name}",
206
+ 'udid' => "#{@udid}"
207
+ }
208
+ end
209
+ @caps['caps'] = @caps['caps'].merge(@desired_caps) unless @desired_caps.nil?
210
+
211
+ end
212
+
213
+ def install path
214
+ p 'app 正在现在安装中,请稍后...' if path.match(/^http/)
215
+ install_app path
216
+ end
217
+ end