mirror of
https://github.com/appium/appium.git
synced 2026-05-03 17:00:32 -05:00
Fix xunit_android sample code
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user