Created
July 3, 2016 20:43
-
-
Save andrew-carroll/3a7b30c15d47e0da1bea59526f643b47 to your computer and use it in GitHub Desktop.
This file contains 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 | |
require 'headless' | |
require 'watir-webdriver' | |
require 'highline/import' | |
module BankAccounts | |
module TDBank | |
class Balance | |
LOGIN_URL = 'onlinebanking.tdbank.com' | |
def initialize | |
Headless.ly { get_balance } | |
end | |
private | |
def get_balance | |
@browser = Watir::Browser.new | |
login | |
verify if needs_verification? | |
Watir::Wait.until { @browser.frame.body.text.include? 'Available Balance' } | |
display_information | |
ensure | |
@browser.close | |
end | |
def prompt(text) | |
ask(text) {|q| q.echo = false} | |
end | |
def display_information | |
table = @browser.frame.tables.last | |
values = table.ths.map(&:text).zip table.tds.map(&:text) | |
puts values.map{|th, td| th.ljust(30) + td.strip} | |
end | |
def login | |
@browser.goto LOGIN_URL | |
form = @browser.frame | |
form.text_field(id: 'txtUser').set prompt("Username: ") | |
form.text_field(id: 'txtPassword').set prompt("Password: ") | |
form.input(name: 'formSubmit').click | |
end | |
def verify | |
question = @browser.frame.td(class: 'question').text | |
security_answer = prompt("Security question: #{question}\n> ") | |
@browser.frame.text_field(id: 'Newanswer').set(security_answer) | |
@browser.frame.input(id: 'Button1').click | |
end | |
def needs_verification? | |
sleep 3 | |
@browser.frame.body.text.include? 'Verification' | |
end | |
end | |
end | |
end | |
BankAccounts::TDBank::Balance.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment