在 Python 或 Ruby 中使用 Android UIAutomator



我正在尝试使用python(或可能是ruby(自动化Android应用程序,方法是链接到android SDK中提供的UIAutomator。

现在我正在尝试在这里使用 Python 工具,但我在连接时遇到问题(TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

我试图用 Python 工具执行的操作的代码截取:

    def print_info():
        print('Getting info...')
        d = ui.Device('SERIAL_NUMBER', adb_server_host='192.168.1.20', adb_server_port='5037')
        print(d.info)

我尝试发送命令的方式有问题吗?或者,有没有更好的红宝石/蟒蛇工具来测试安卓设备?

更新 我现在正在使用 Appium 库 Ruby gem 进行测试。启动应用程序,但是点击屏幕等操作会导致此错误

assert_ok': A session is either terminated or not started
(Selenium::WebDriver::Error::NoSuchDriverError)`

这是代码

desired_caps = {
  caps:       {
    appiumVersion:    '1.6.5',
    platformName:     'Android',
    platformVersion:  '4.4',
    browserName:      '',
    deviceName:       'DEVICE_SERIAL',
    app:              'APK',
    appActivity:      'mainactivity',
    appWaitDuration:  '60000', # wait a minute (set to 20000 by default)
    clearSystemFiles: 'true'
  },
  appium_lib: {
    sauce_username:    nil,
    sauce_access_key:  nil
  }
}
$driver = Appium::Driver.new(desired_caps)
$driver.start_driver
sleep(60) # wait a minute for app to fully load, before tring to tap anything
touch_action = Appium::TouchAction.new
touch_action.press(x: 243, y: 288).wait(5).release.perform
touch_action.press(x: 311, y: 165).wait(5).release.perform

这就是我为模拟器做的方法

app_path = File.absolute_path('automateme.apk', 'data')
caps = {
  :platformName => "android",
  :deviceName => "android",
  :app => app_path,
  :noReset => 'true',
  :newCommandTimeout => "30"
}
@driver = Appium::Driver.new(:caps => caps).start_driver

试试这个,让我知道它是否有帮助... :)

有一个很好的移动测试自动化工具 - Appium。 目前我一直在使用红宝石,appium,黄瓜,硒网络驱动程序进行Android自动化。我建议您尝试使用 Appium 工具进行移动自动化。以下是重要链接,

http://www.software-testing-tutorials-automation.com/2015/09/appium-tutorials.html https://community.perfectomobile.com/posts/1103155-ruby-example-for-appium-android http://appium.io/slate/en/tutorial/android.html?ruby#troubleshooting

following is the example to start  
require 'appium_lib'  
desired_caps = {  
     caps:       {   appiumVersion:    '1.6.0',  
      platformName:     'Android',  
      platformVersion:  '4.4.2',    
      browserName:       '',  
     deviceName:       'Samsung Galaxy S4 Emulator',  
     app:              'D:Workspaceandroid-sample-app.apk',         
    name:             'Ruby Appium Sauce example'   
  }       }   
driver = Appium::Driver.new(desired_caps)  
puts driver  
begin  
  driver.start_driver  
  rescue Exception => e   
  puts e     
end
driver.first_textfield.send_key 10 
driver.last_textfield.send_key 20  
driver.first_button.click  
driver.driver_quit   
download "android-sample-app.apk" and put in any path and also set this path 
in desired_caps.

谢谢 卡皮尔·乔特

最新更新