Created
November 2, 2016 01:19
-
-
Save yemartin/893f3edbfcff8e514e7aeb7ee769cabe to your computer and use it in GitHub Desktop.
Quick and dirty use of Capybara against a live site, for automation or smoke tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
OPEN_TIME = "07:45" | |
TARGET_SITE = "http://example.com/" | |
PATIENT_NUMBER = '1111111' | |
require 'time' | |
require 'capybara' | |
require 'selenium-webdriver' | |
Capybara.run_server = false | |
Capybara.default_driver = :selenium | |
Selenium::WebDriver.for :firefox | |
Selenium::WebDriver::Driver.class_eval do | |
# Not sure why I did that ^^; | |
def quit | |
STDOUT.puts "#{self.class}#quit: no-op" | |
end | |
end | |
# Wait for the opening time. | |
Capybara.visit TARGET_SITE | |
sleep_time = Time.parse(OPEN_TIME) - Time.now | |
sleep sleep_time if sleep_time > 0 | |
# Retry a few times in case the server time is skewed | |
# and the site is not open yet. | |
attempts = 10 | |
begin | |
Capybara.visit TARGET_SITE | |
Capybara.click_on 'いますぐ受付' | |
rescue | |
attempts -= 1 | |
if attempts > 0 | |
puts "RETRYING. Attempts left: #{attempts}" | |
retry | |
end | |
raise "UNABLE TO CONNECT, giving up." | |
end | |
# Now perform the main automated task | |
Capybara.click_on '次へ' | |
Capybara.fill_in 'patient_number', with: PATIENT_NUMBER | |
Capybara.click_on '次へ' | |
Capybara.click_on 'はい' | |
Capybara.click_on '次へ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment