Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'headless'
  3. require 'watir-webdriver'
  4. require 'highline/import'
  5.  
  6. module BankAccounts
  7. module TDBank
  8. class Balance
  9. LOGIN_URL = 'onlinebanking.tdbank.com'
  10. def initialize
  11. Headless.ly { get_balance }
  12. end
  13.  
  14. private
  15.  
  16. def get_balance
  17. @browser = Watir::Browser.new
  18. login
  19. verify if needs_verification?
  20. Watir::Wait.until { @browser.frame.body.text.include? 'Available Balance' }
  21. display_information
  22. ensure
  23. @browser.close
  24. end
  25.  
  26. def prompt(text)
  27. ask(text) {|q| q.echo = false}
  28. end
  29.  
  30. def display_information
  31. table = @browser.frame.tables.last
  32. values = table.ths.map(&:text).zip table.tds.map(&:text)
  33. puts values.map{|th, td| th.ljust(30) + td.strip}
  34. end
  35.  
  36. def login
  37. @browser.goto LOGIN_URL
  38. form = @browser.frame
  39. form.text_field(id: 'txtUser').set prompt("Username: ")
  40. form.text_field(id: 'txtPassword').set prompt("Password: ")
  41. form.input(name: 'formSubmit').click
  42. end
  43.  
  44. def verify
  45. question = @browser.frame.td(class: 'question').text
  46. security_answer = prompt("Security question: #{question}\n> ")
  47. @browser.frame.text_field(id: 'Newanswer').set(security_answer)
  48. @browser.frame.input(id: 'Button1').click
  49. end
  50.  
  51. def needs_verification?
  52. sleep 3
  53. @browser.frame.body.text.include? 'Verification'
  54. end
  55. end
  56. end
  57. end
  58.  
  59. BankAccounts::TDBank::Balance.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement