android - 应用多线程时,Appium::TouchAction(ruby)中会发生Appium:冲突吗?

标签 android ruby multithreading appium

我正在使用多线程在多个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

如果我只保留一个线程,则触摸 Action 会完美执行。如何同步Appium::TouchAction的操作?

最佳答案

我像把Appium与Java一起使用时生气了,因为以前我没有使用过Ruby:
为您提供引用:(希望有帮助)
http://www.software-testing-tutorials-automation.com/2015/11/pefrorm-multitouch-action-using-appium.html

 // Create object of MultiTouchAction class.
  MultiTouchAction maction = new MultiTouchAction((MobileDriver) driver);

  // Set touch action1 on given X Y Coordinates of screen.
  TouchAction action1 = new TouchAction((MobileDriver) driver).longPress(x1, y1).waitAction(1500);
  // Set touch action2 on given X Y Coordinates of screen.
  TouchAction action2 = new TouchAction((MobileDriver) driver).longPress(x2, y2).waitAction(1500);
  // Set touch action3 on given X Y Coordinates of screen.
  TouchAction action3 = new TouchAction((MobileDriver) driver).longPress(x3, y3).waitAction(1500);
  // Set touch action4 on given X Y Coordinates of screen.
  TouchAction action4 = new TouchAction((MobileDriver) driver).longPress(x4, y4).waitAction(1500);
  // Set touch action5 on given X Y Coordinates of screen.
  TouchAction action5 = new TouchAction((MobileDriver) driver).longPress(x5, y5).waitAction(1500);

  // Generate multi touch action chain using different actions and perform It.
  maction.add(action1).add(action2).add(action3).add(action4).add(action5).perform();

关于android - 应用多线程时,Appium::TouchAction(ruby)中会发生Appium:冲突吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41331850/

相关文章:

android - 如何将一个 android.mk 模块导入 Android 中的另一个 android.mk 模块?

ruby-on-rails - 如何在 Cucumber 中测试不同的环境(例如开发|测试|生产)?

arrays - 如何循环遍历通过终端传递到 Ruby 脚本的 bash 数组变量的元素?

android - 在 Android 插件中通过 AsyncTask 使用 cordova getThreadPool.execute()

android - 在 Android App/Android Studio 中显示 C 代码

java - 对于 Java/Android 使用 'sed"命令更改一行

ruby - 为什么从 cmd 文件调用 gem.bat 在第一次调用后退出?

c++ - 变量中的不同值

java - Java 中有趣的线程行为

java - 如何在java android中对数字进行排序?