Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement