mirror of
https://github.com/appium/appium.git
synced 2026-04-25 12:58:39 -05:00
Update Ruby sample code.
Change from tag_name to class_name for u\_i\_catalog, simple\_test, cucumber tests. Changed to iOS 7.1 in u\_i\_catalog, simple\_test, cucumber tests. Changed `capabilities` to `desired_caps` to avoid some weirdo collisions. Remove Debugging output from Cucumber. Add example of send\_keys as an action chain for u\_i\_catalog.
This commit is contained in:
@@ -19,17 +19,16 @@
|
||||
|
||||
|
||||
Given /^I have entered (\d+) into field (\d+) of the calculator$/ do |value, field|
|
||||
puts "Called: #{value} #{field}"
|
||||
elements = selenium.find_elements(:tag_name, "textField")
|
||||
elements = selenium.find_elements(:class_name, "UIATextField")
|
||||
elements[field.to_i - 1].send_keys value
|
||||
end
|
||||
|
||||
And /^I press button (\d+)$/ do |button_index|
|
||||
button = selenium.find_elements(:tag_name, "button")[button_index.to_i - 1 ]
|
||||
button = selenium.find_elements(:class_name, "UIAButton")[button_index.to_i - 1 ]
|
||||
button.click
|
||||
end
|
||||
|
||||
Then /^the result should be displayed as (\d+)$/ do |expected|
|
||||
result = selenium.find_element(:tag_name, "staticText")
|
||||
result = selenium.find_element(:class_name, "UIAStaticText")
|
||||
result.attribute("value").should eq expected
|
||||
end
|
||||
|
||||
@@ -14,12 +14,12 @@ require 'selenium-webdriver'
|
||||
APP_PATH = '../../../../../apps/TestApp/build/release-iphonesimulator/TestApp.app'
|
||||
|
||||
# What we need as a capability --> iOS device, where our app is, ect.
|
||||
def capabilities
|
||||
def desired_caps
|
||||
{
|
||||
'browserName' => '',
|
||||
'platform' => 'Mac',
|
||||
'device' => 'iPhone Simulator',
|
||||
'version' => '6.0',
|
||||
'version' => '7.1',
|
||||
'app' => absolute_app_path
|
||||
}
|
||||
end
|
||||
@@ -36,7 +36,7 @@ end
|
||||
|
||||
# Set up a driver or, if one exists, return it
|
||||
def selenium
|
||||
@driver ||= Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)
|
||||
@driver ||= Selenium::WebDriver.for(:remote, :desired_capabilities => desired_caps, :url => server_url)
|
||||
end
|
||||
|
||||
After { @driver.quit }
|
||||
|
||||
@@ -40,11 +40,11 @@ def absolute_app_path
|
||||
file
|
||||
end
|
||||
|
||||
capabilities = {
|
||||
desired_caps = {
|
||||
'browserName' => '',
|
||||
'platform' => 'Mac',
|
||||
'device' => 'iPhone Simulator',
|
||||
'version' => '6.0',
|
||||
'version' => '7.1',
|
||||
'app' => absolute_app_path
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ server_url = "http://127.0.0.1:4723/wd/hub"
|
||||
|
||||
describe "Computation" do
|
||||
before :all do
|
||||
@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)
|
||||
@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => desired_caps, :url => server_url)
|
||||
@driver.manage.timeouts.implicit_wait = 10 # seconds
|
||||
end
|
||||
|
||||
@@ -63,37 +63,39 @@ describe "Computation" do
|
||||
it "should add two numbers" do
|
||||
values = [rand(10), rand(10)]
|
||||
expected_sum = values.reduce(&:+)
|
||||
elements = @driver.find_elements(:tag_name, 'textField')
|
||||
elements = @driver.find_elements(:class_name, 'UIATextField')
|
||||
|
||||
elements.each_with_index do |element, index|
|
||||
element.send_keys values[index]
|
||||
end
|
||||
|
||||
button = @driver.find_element(:tag_name, 'button')
|
||||
button = @driver.find_element(:class_name, 'UIAButton')
|
||||
button.click
|
||||
|
||||
actual_sum = @driver.find_elements(:tag_name, 'staticText')[0].text
|
||||
actual_sum = @driver.find_elements(:class_name, 'UIAStaticText')[0].text
|
||||
actual_sum.should eq(expected_sum.to_s)
|
||||
end
|
||||
|
||||
it "should handle alerts" do
|
||||
els = @driver.find_elements(:tag_name, 'button')
|
||||
els = @driver.find_elements(:class_name, 'UIAButton')
|
||||
els[1].click
|
||||
a = @driver.switch_to.alert
|
||||
a.text.should eq("Cool title")
|
||||
a.text.should include("Cool title") # Returns title & text
|
||||
a.accept
|
||||
end
|
||||
|
||||
it "should find alerts" do
|
||||
els = @driver.find_elements(:tag_name, 'button')
|
||||
els = @driver.find_elements(:class_name, 'UIAButton')
|
||||
els[1].click
|
||||
alert = @driver.find_element(:tag_name, 'alert')
|
||||
buttons = alert.find_elements(:tag_name, 'button')
|
||||
buttons[0].text.should eq("Cancel")
|
||||
alert = @driver.find_element(:class_name, 'UIAAlert')
|
||||
buttons = alert.find_elements(:class_name, 'UIATableCell')
|
||||
buttons[0].attribute('label').should eq "Cancel"
|
||||
#.should.equal("Cancel")
|
||||
|
||||
buttons[0].click
|
||||
wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds
|
||||
wait.until {
|
||||
alerts = @driver.find_elements(:tag_name, 'alert')
|
||||
alerts = @driver.find_elements(:class_name, 'UIAAlert')
|
||||
alerts.should be_empty
|
||||
}
|
||||
end
|
||||
@@ -101,7 +103,7 @@ describe "Computation" do
|
||||
it "should get window size" do
|
||||
size = @driver.manage.window.size
|
||||
size.width.should eq(320)
|
||||
size.height.should eq(480)
|
||||
size.height.should eq(568)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -15,12 +15,12 @@ include Selenium::WebDriver::DriverExtensions::HasTouchScreen
|
||||
|
||||
APP_PATH = '../../apps/UICatalog/build/Release-iphonesimulator/UICatalog.app'
|
||||
|
||||
def capabilities
|
||||
def desired_caps
|
||||
{
|
||||
'browserName' => '',
|
||||
'platform' => 'Mac',
|
||||
'device' => 'iPhone Simulator',
|
||||
'version' => '6.0',
|
||||
'version' => '7.1',
|
||||
'app' => absolute_app_path
|
||||
}
|
||||
end
|
||||
@@ -39,7 +39,7 @@ end
|
||||
|
||||
describe "UI Catalog" do
|
||||
before(:all) do
|
||||
@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)
|
||||
@driver = Selenium::WebDriver.for(:remote, :desired_capabilities => desired_caps, :url => server_url)
|
||||
|
||||
end
|
||||
|
||||
@@ -49,26 +49,25 @@ describe "UI Catalog" do
|
||||
|
||||
describe "An Element" do
|
||||
|
||||
subject { @driver.find_elements(:tag_name, "tableView")[0]}
|
||||
subject { @driver.find_elements(:class_name, "UIATableView")[0]}
|
||||
|
||||
it {should_not be nil}
|
||||
|
||||
context "when used as a selection context" do
|
||||
|
||||
it "Can be a selection context" do
|
||||
rows = subject.find_elements(:tag_name, "tableCell")
|
||||
rows = subject.find_elements(:class_name, "UIATableCell")
|
||||
rows.size.should eq 12
|
||||
end
|
||||
|
||||
it "does not return elements it does not contain" do
|
||||
nav_bar = subject.find_elements(:tag_name, "navigationBar")
|
||||
nav_bar = subject.find_elements(:class_name, "UIANavigationBar")
|
||||
nav_bar.length.should be 0
|
||||
end
|
||||
end
|
||||
|
||||
# Not currently working, no text being returned
|
||||
it "returns its text" do
|
||||
rows = subject.find_elements(:tag_name, "tableCell")
|
||||
rows = subject.find_elements(:class_name, "UIATableCell")
|
||||
rows[0].attribute(:name).should eq "Buttons, Various uses of UIButton"
|
||||
end
|
||||
|
||||
@@ -76,7 +75,7 @@ describe "UI Catalog" do
|
||||
|
||||
describe "position" do
|
||||
it "is returned by the driver" do
|
||||
third_row = @driver.find_elements(:tag_name, "tableCell")[2]
|
||||
third_row = @driver.find_elements(:class_name, "UIATableCell")[2]
|
||||
third_row.location.x.should be 0
|
||||
third_row.location.y.should be 152
|
||||
end
|
||||
@@ -96,8 +95,8 @@ describe "UI Catalog" do
|
||||
describe "attributes" do
|
||||
|
||||
before :all do
|
||||
@driver.find_elements(:tag_name, "tableCell")[9].click
|
||||
@switch = @driver.find_element(:tag_name, "switch")
|
||||
@driver.find_elements(:class_name, "UIATableCell")[9].click
|
||||
@switch = @driver.find_element(:class_name, "UIASwitch")
|
||||
end
|
||||
|
||||
# Go back to the menu when you're done
|
||||
@@ -130,8 +129,8 @@ describe "UI Catalog" do
|
||||
describe "text fields" do
|
||||
|
||||
before :all do
|
||||
@driver.find_elements(:tag_name, "tableCell")[2].click
|
||||
@text_field = @driver.find_element(:tag_name, "textField")
|
||||
@driver.find_elements(:class_name, "UIATableCell")[2].click
|
||||
@text_field = @driver.find_element(:class_name, "UIATextField")
|
||||
end
|
||||
|
||||
after :all do
|
||||
@@ -146,7 +145,12 @@ describe "UI Catalog" do
|
||||
@text_field.attribute("value").should eq "discombobulate"
|
||||
end
|
||||
|
||||
it "can accept key presses as an ActionChain"
|
||||
it "can accept key presses as an ActionChain" do
|
||||
@driver.action.send_keys(Selenium::WebDriver::Keys[:backspace])
|
||||
.send_keys('te')
|
||||
.perform
|
||||
@text_field.attribute("value").should eq "discombobulatte"
|
||||
end
|
||||
|
||||
it "can be cleared" do
|
||||
@text_field.clear
|
||||
@@ -156,8 +160,8 @@ describe "UI Catalog" do
|
||||
|
||||
describe "alerts" do
|
||||
before :all do
|
||||
@driver.find_elements(:tag_name, "tableCell")[10].click
|
||||
@elements = @driver.find_elements(:tag_name, "staticText")
|
||||
@driver.find_elements(:class_name, "UIATableCell")[10].click
|
||||
@elements = @driver.find_elements(:class_name, "UIATableCell")
|
||||
end
|
||||
|
||||
after :all do
|
||||
@@ -171,26 +175,20 @@ describe "UI Catalog" do
|
||||
it "can be dismissed"
|
||||
|
||||
it "can be modal & have buttons" do
|
||||
modal = @driver.find_elements(:tag_name, "staticText")
|
||||
modal = @driver.find_elements(:class_name, "UIAStaticText")
|
||||
end
|
||||
end
|
||||
|
||||
describe "scrolling" do
|
||||
|
||||
it "can be done with co-ordinates" do
|
||||
row = @driver.find_elements(:tag_name, "tableCell")[2]
|
||||
initial_location = row.location
|
||||
action = @driver.touch.flick(0, 20)
|
||||
|
||||
action.perform
|
||||
initial_location.should_not eq row.location
|
||||
end
|
||||
# Does not work on iOS 7 yet
|
||||
it "can be done with co-ordinates"
|
||||
end
|
||||
|
||||
describe "sliders" do
|
||||
before :all do
|
||||
@driver.find_elements(:tag_name, "tableCell")[1].click
|
||||
@slider = @driver.find_element(:tag_name, "slider")
|
||||
@driver.find_elements(:class_name, "UIATableCell")[1].click
|
||||
@slider = @driver.find_element(:class_name, "UIASlider")
|
||||
end
|
||||
|
||||
after :all do
|
||||
@@ -222,8 +220,8 @@ describe "UI Catalog" do
|
||||
|
||||
describe "sizes" do
|
||||
it "can be obtained from elements" do
|
||||
table_dimensions = @driver.find_element(:tag_name, "tableView").size
|
||||
row_dimensions = @driver.find_elements(:tag_name, "tableCell")[0].size
|
||||
table_dimensions = @driver.find_element(:class_name, "UIATableView").size
|
||||
row_dimensions = @driver.find_elements(:class_name, "UIATableCell")[0].size
|
||||
|
||||
table_dimensions["width"].should eq row_dimensions["width"]
|
||||
table_dimensions["height"].should_not eq row_dimensions["height"]
|
||||
@@ -233,7 +231,7 @@ describe "UI Catalog" do
|
||||
describe "page source" do
|
||||
before :all do
|
||||
@main_source = @driver.page_source
|
||||
@driver.find_elements(:tag_name, "tableCell")[2].click
|
||||
@driver.find_elements(:class_name, "UIATableCell")[2].click
|
||||
@text_source = @driver.page_source
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
require 'test/unit'
|
||||
require 'selenium-webdriver'
|
||||
|
||||
def capabilities
|
||||
def desired_caps
|
||||
{
|
||||
'browserName' => 'android',
|
||||
'platform' => 'linux',
|
||||
@@ -18,7 +18,7 @@ end
|
||||
|
||||
def init(data={})
|
||||
server_url = 'http://127.0.0.1:4723/wd/hub'
|
||||
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities.merge(data), :url => server_url)
|
||||
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => desired_caps.merge(data), :url => server_url)
|
||||
driver.manage.timeouts.implicit_wait = 20 # seconds
|
||||
driver
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user