Fix xunit_android sample code

This commit is contained in:
bootstraponline
2014-05-14 23:27:40 -04:00
parent 2a0d809664
commit 82a6a5dbb4
2 changed files with 31 additions and 47 deletions
+26 -42
View File
@@ -1,50 +1,34 @@
# this test show you how to use flick and locate element by parent container
# this test show you how to use scroll and locate element by xpath
# it open the system settings ui, and click the 'About phone' item to find android version
# create by testerhome.com
# author: seveniruby
require 'test/unit'
require 'selenium-webdriver'
def desired_caps
{
'browserName' => 'android',
'platform' => 'linux',
'version' => '4.1',
'app-activity'=> '.Settings',
'app-package'=> 'com.android.settings'
}
end
def init(data={})
server_url = 'http://127.0.0.1:4723/wd/hub'
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => desired_caps.merge(data), :url => server_url)
driver.manage.timeouts.implicit_wait = 20 # seconds
driver
end
require 'appium_lib'
class SettingsTest < Test::Unit::TestCase
def setup
@driver=init
end
def test_settings
#flick the screen until find the Aboud phone item
while @driver.find_elements(:xpath, '//text[@text="About phone"]').count==0
begin
@driver.execute_script 'mobile: flick', :startY=>0.9, :endY=>0.1
rescue
end
end
about=@driver.find_element(:xpath, '//text[@text="About phone"]')
about.click
#parent select, locate the container
version_setting=@driver.find_element(:xpath, '//list/linear[4]/relative')
#child select
version_value=version_setting.find_element(:xpath, '//text[2]')
#check the version, should be 4.1.2 or other version string
assert_not_equal nil, version_value.text=~/[0-9\.]/
end
def teardown
@driver.quit
end
end
def setup
caps = { caps: { platformName: 'Android', appActivity: '.Settings', appPackage: 'com.android.settings' } }
driver = Appium::Driver.new(caps)
Appium.promote_appium_methods self.class
driver.start_driver.manage.timeouts.implicit_wait = 20 # seconds
end
def teardown
driver_quit
end
def test_about_phone_version
scroll_to('About phone').click
android_version = 'Android version'
scroll_to android_version
view = 'android.widget.TextView'
version = xpath(%Q(//#{view}[preceding-sibling::#{view}[@text="#{android_version}"]])).text
valid = !version.match(/\d/).nil?
puts "Version is: #{version}"
assert_equal true, valid
end
end