Skip to content

Instantly share code, notes, and snippets.

@evanniedojadlo
Created June 22, 2015 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanniedojadlo/431858c33d875ab4beb2 to your computer and use it in GitHub Desktop.
Save evanniedojadlo/431858c33d875ab4beb2 to your computer and use it in GitHub Desktop.
Basic Test which is run against Firefox
#base is used for building out the tests structure
require 'selenium-webdriver'
class Base
def initialize(driver)
@driver = driver
end
def visit(url)
@driver.get url
end
def find_element(locator)
@driver.find_element locator
end
def click(locator)
find_element(locator).click
end
def send_keys(locator, text)
find_element(locator).send_keys text
end
def displayed?(locator)
find_element(locator).displayed?
end
def wait_for(seconds = 15)
Selenium::WebDriver::Wait.new(timeout: seconds).until { yield }
end
#private only to this class
#yield allows us to pass code into this method when we call it in this case yield is replaced with
#the find element locator within displayed?
private
def rescue_exceptions
begin
yield
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
end
end
require_relative 'base'
class DynamicLoading < Base
START_BUTTON = { css: '#start button' }
FINISH_TEXT = { id: 'finish' }
#auto loads the page url
def initialize(driver)
@driver = driver
visit 'http://the-internet.herokuapp.com/dynamic_loading/2'
end
def start
click START_BUTTON
end
def finish_text_present?
wait_for(6) { displayed? FINISH_TEXT }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment