Guest User

Untitled

a guest
Mar 3rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. require 'rubygems'
  2. require 'taza'
  3. require 'watir/ie'
  4.  
  5. module Application
  6. include ForwardInitialization
  7.  
  8. class Application < ::Taza::Site
  9. attr_accessor :env, :username, :password, :url, :br
  10. def initialize_browser
  11. # this is where we put specific startup behavior
  12. login('myusername')
  13. end
  14.  
  15. def login(username='default_username', env='default_env')
  16. @username = username.downcase
  17. @env = env.downcase
  18. @password = 'mypassword'
  19. @url = 'myurl.com'
  20.  
  21. puts "Opening browser to #{@url} using the #{@username} user"
  22. # spawn new thread to handle the basic authentication popup using
  23. # supplied credentials
  24.  
  25. a = Thread.new {
  26. puts "spawning new thread to handle basic authentication"
  27. login_title = "Connect to #{@url}"
  28. login_script = File.join(File.dirname(__FILE__), "handlers", 'handle_logon.rb')
  29. system("ruby \"#{login_script}\" \"#{login_title}\" \"#{@username}\" \"#{@password}\"")
  30. }
  31.  
  32. if env == 'other' # some environment that requires dismissing security dialog box
  33. if self.installed_ie_version == '6'
  34. puts "spawning thread to kill IE6 security alert"
  35. security_script = File.join(File.dirname(__FILE__), "handlers", 'handle_security_alert.rb')
  36. b = Thread.new {
  37. system("ruby \"#{login_script}\"")
  38. }
  39. @br = Watir::IE.start_process(@url)
  40. elsif self.installed_ie_version == '7'
  41. @br = Watir::IE.start_process(@url)
  42. @br.link(:id, 'overridelink').click
  43. else
  44. raise "Could not determine IE version"
  45. end
  46. else
  47. @br = Watir::IE.start_process(@url)
  48. end
  49.  
  50. puts "Number of threads running #{Thread.list.size}"
  51. a.join
  52. b.join if (env == 'uat') and (self.installed_ie_version == '6')
  53. puts "end login"
  54. end
  55. end
  56. end
Add Comment
Please, Sign In to add comment