Skip to content

Instantly share code, notes, and snippets.

@hdemon
Last active August 29, 2015 14:06
Show Gist options
  • Save hdemon/6cef7ab56ce3d9ad4bf9 to your computer and use it in GitHub Desktop.
Save hdemon/6cef7ab56ce3d9ad4bf9 to your computer and use it in GitHub Desktop.
require "json"
require "selenium-webdriver"
require "rspec"
require 'appium_lib'
include RSpec::Expectations
def desired_caps
{
caps: {
platformName: 'iOS',
deviceName: 'iPhone Simulator',
browserName: 'Safari',
versionNumber: '7.1',
# app: APP_PATH
},
appium_lib: {
sauce_username: nil, # don't run on sauce
sauce_access_key: nil,
wait: 30,
},
# appium_port: 4724,
}
end
describe "Test" do
before(:all) do
@driver = Appium::Driver.new(desired_caps).start_driver
Appium.promote_appium_methods RSpec::Core::ExampleGroup
end
before(:each) do
# @driver = Selenium::WebDriver.for(:remote, :url => "http://0.0.0.0")
# @driver = Selenium::Appium.new(desired_caps)
# @driver = Selenium::WebDriver.for :phantomjs
@base_url = "http://blog.reallysimplethoughts.com/"
@accept_next_alert = true
# @driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end
after(:each) do
@driver.quit
@verification_errors.should == []
end
it "test_" do
@driver.get(@base_url + "/2014/01/05/manually-adding-and-updating-element-locators-the-easy-way/")
@driver.find_element(:link, "Really Simple Thoughts of a Perpetual Learner").click
end
def element_present?(how, what)
@r.find_element(how, what)
true
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
def alert_present?()
@r.switch_to.alert
true
rescue Selenium::WebDriver::Error::NoAlertPresentError
false
end
def verify(&blk)
yield
rescue ExpectationNotMetError => ex
@verification_errors << ex
end
def close_alert_and_get_its_text(how, what)
alert = @r.switch_to().alert()
alert_text = alert.text
if (@accept_next_alert) then
alert.accept()
else
alert.dismiss()
end
alert_text
ensure
@accept_next_alert = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment