【发布时间】:2017-05-10 22:54:03
【问题描述】:
我正在使用多线程在多个 android 设备上运行并行测试。代码在没有多线程的情况下运行良好。我认为有一些与 Appium:TouchAction 相关的同步问题。
这是我的代码:
require 'thread'
require 'appium_lib'
TARGET_APP_ACTIVITY = 'something'
TARGET_APP_PACKAGE = 'mlab.android.speedvideo.pro'
include Appium::Common
def start_app(device_id,port_num)
caps_config={ platformName: 'Android', appActivity: TARGET_APP_ACTIVITY,
deviceName: '', udid: device_id, appPackage: TARGET_APP_PACKAGE,newCommandTimeout: 3600}
appium_lib_config={ port: port_num}
opts={caps:caps_config,appium_lib:appium_lib_config}
orig= Appium::Driver.new(opts)
return orig
end
def test(device1,device2)
cmd1 = "start appium -p 4000 -bp 4001 -U " + device1
cmd2 = "start appium -p 4002 -bp 4003 -U " + device2
system(cmd1)
system(cmd2)
sleep 20
threads = []
threads << Thread.new {
orig = start_app(device1,4000)
dr = orig.start_driver
dr.find_element(id:'something').click
dr.find_element(id:'something').click
dest_elem = dr.find_element(id:'something')
src_elem = dr.find_element(id:'something')
Appium::TouchAction.new.press(element: src_elem).move_to(element:dest_elem).perform
src_elem = dr.find_element(id:'something')
Appium::TouchAction.new.press(element: src_elem).move_to(element:dest_elem).perform
src_elem = dr.find_element(id:'something')
Appium::TouchAction.new.press(element: src_elem).move_to(element:dest_elem).perform
orig.driver_quit
}
threads << Thread.new {
orig = start_app(device2,4002)
dr = orig.start_driver
dr.find_element(id:'something').click
dr.find_element(id:'something').click
dest_elem = dr.find_element(id:'something')
src_elem = dr.find_element(id:'something')
wait {Appium::TouchAction.new.press(element: src_elem).move_to(element:dest_elem).perform}
src_elem = dr.find_element(id:'something')
wait {Appium::TouchAction.new.press(element: src_elem).move_to(element:dest_elem).perform}
src_elem = dr.find_element(id:'something')
wait {Appium::TouchAction.new.press(element: src_elem).move_to(element:dest_elem).perform}
orig.driver_quit
}
threads.each { |t|
t.join
}
end
if __FILE__ == $0
test(ARGV[0],ARGV[1])
end
如果我只保留一个线程,触摸动作可以完美执行。如何同步 Appium::TouchAction 的操作?
【问题讨论】:
标签: android ruby multithreading appium