ams_layout 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.pryrc +8 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +3 -0
  6. data/Gemfile +12 -0
  7. data/Gemfile.lock +134 -0
  8. data/Guardfile +11 -0
  9. data/LICENSE +22 -0
  10. data/README.md +42 -0
  11. data/Rakefile +116 -0
  12. data/ams_layout.gemspec +32 -0
  13. data/bin/ams_layout +10 -0
  14. data/lib/ams_layout/browser_loader.rb +99 -0
  15. data/lib/ams_layout/cli/config.rb +250 -0
  16. data/lib/ams_layout/cli/generate.rb +145 -0
  17. data/lib/ams_layout/cli.rb +29 -0
  18. data/lib/ams_layout/client.rb +190 -0
  19. data/lib/ams_layout/core_ext/string.rb +30 -0
  20. data/lib/ams_layout/core_ext.rb +11 -0
  21. data/lib/ams_layout/delegate_writer.rb +348 -0
  22. data/lib/ams_layout/pages/login_page.rb +69 -0
  23. data/lib/ams_layout/pages/prequal_detail.rb +26 -0
  24. data/lib/ams_layout/pages.rb +36 -0
  25. data/lib/ams_layout/parser.rb +137 -0
  26. data/lib/ams_layout/version.rb +3 -0
  27. data/lib/ams_layout/writer.rb +124 -0
  28. data/lib/ams_layout.rb +198 -0
  29. data/spec/data/layout-small.yml +25 -0
  30. data/spec/data/layout-small.yml.aliases +22 -0
  31. data/spec/data/layout.yml +652 -0
  32. data/spec/data/layout.yml.aliases +613 -0
  33. data/spec/lib/ams_layout/ams_layout_spec.rb +7 -0
  34. data/spec/lib/ams_layout/cli/config_spec.rb +471 -0
  35. data/spec/lib/ams_layout/cli/generate_spec.rb +188 -0
  36. data/spec/lib/ams_layout/cli_spec.rb +35 -0
  37. data/spec/lib/ams_layout/client_spec.rb +93 -0
  38. data/spec/lib/ams_layout/delegate_writer_spec.rb +80 -0
  39. data/spec/lib/ams_layout/writer_spec.rb +64 -0
  40. data/spec/spec_helper.rb +7 -0
  41. data/spec/spec_helper_spec.rb +27 -0
  42. data/spec/support/asserts.rb +13 -0
  43. data/spec/support/dirs.rb +45 -0
  44. data/spec/support/helpers.rb +46 -0
  45. metadata +231 -0
@@ -0,0 +1,124 @@
1
+ ##############################################################################
2
+ # File:: writer.rb
3
+ # Purpose:: Generate a ruby source file that is a base class containing
4
+ # the fields on the Loan Entry screen.
5
+ #
6
+ # Author:: Jeff McAffee 06/23/2014
7
+ # Copyright:: Copyright (c) 2014, kTech Systems LLC. All rights reserved.
8
+ # Website:: http://ktechsystems.com
9
+ ##############################################################################
10
+
11
+ require 'ams_layout/core_ext'
12
+
13
+ module AmsLayout
14
+ class Writer
15
+
16
+ attr_writer :class_name
17
+ #attr_writer :aliases
18
+
19
+ def source_file_name
20
+ class_name.ams_layout_snakecase + '.rb'
21
+ end
22
+
23
+ def class_name
24
+ @class_name ||= AmsLayout.configuration.layout_class_name
25
+ end
26
+
27
+ def aliases
28
+ @aliases ||= {}
29
+ end
30
+
31
+ def aliases=(data)
32
+ @aliases = Hash(data)
33
+ end
34
+
35
+ def write stream, layout
36
+ stream << header
37
+
38
+ layout.each do |section_label, fields|
39
+ stream << section(section_label)
40
+
41
+ fields.each do |fld|
42
+ stream << field(fld[:label], fld[:id], fld[:type])
43
+ write_aliases stream, fld[:label], fld[:id], fld[:type]
44
+ end # fields
45
+ end # layout
46
+
47
+ stream << footer
48
+ end
49
+
50
+ private
51
+
52
+ def write_aliases stream, label, id, type
53
+ label_aliases = aliases.key?(label) ? aliases[label] : []
54
+ label_aliases.each do |al|
55
+ stream << field_alias(al, id, type)
56
+ end
57
+ end
58
+
59
+ def header
60
+ text =<<TEXT
61
+ #############################################################################
62
+ # #{source_file_name}
63
+ #
64
+ # This file has been generated by AmsLayout.
65
+ # Do not modify this file manually.
66
+ #
67
+ #############################################################################
68
+
69
+ require 'pathname'
70
+ require Pathname(__FILE__).ascend{|d| h=d+'support_helper.rb'; break h if h.file?}
71
+ require 'page-object'
72
+
73
+ class #{class_name}
74
+ include PageObject
75
+
76
+ #
77
+ # Fields (ordered by section as seen on screen)
78
+ #
79
+ TEXT
80
+ end
81
+
82
+ def section label
83
+ text =<<TEXT
84
+
85
+
86
+ # Section: #{label}
87
+ TEXT
88
+ end
89
+
90
+ def field label, id, type
91
+ case type
92
+ when 'text'
93
+ typed_field = 'text_field'
94
+ when 'textarea'
95
+ typed_field = 'text_area'
96
+ when 'select'
97
+ typed_field = 'select_list'
98
+ when 'checkbox'
99
+ typed_field = 'checkbox'
100
+ when 'button'
101
+ typed_field = 'button'
102
+ else
103
+ typed_field = '# unknown_field_type'
104
+ end
105
+
106
+ field_label = label.ams_layout_snakecase
107
+ text =<<TEXT
108
+ #{typed_field}(:#{field_label}, id: '#{id}')
109
+ TEXT
110
+ end
111
+
112
+ def field_alias label, id, type
113
+ text = " #{field(label, id, type)}"
114
+ end
115
+
116
+ def footer
117
+ text =<<TEXT
118
+
119
+ end # #{class_name}
120
+
121
+ TEXT
122
+ end
123
+ end # Writer
124
+ end # AmsLayout
data/lib/ams_layout.rb ADDED
@@ -0,0 +1,198 @@
1
+ ##############################################################################
2
+ # File:: ams_layout.rb
3
+ # Purpose:: Main AmsLayout include
4
+ #
5
+ # Author:: Jeff McAffee 06/21/2014
6
+ # Copyright:: Copyright (c) 2014, kTech Systems LLC. All rights reserved.
7
+ # Website:: http://ktechsystems.com
8
+ ##############################################################################
9
+
10
+ require 'rubygems'
11
+ require 'bundler/setup'
12
+
13
+ module AmsLayout
14
+ CONFIG_FILE_NAME = '.ams_layout'
15
+
16
+ class << self
17
+ attr_accessor :configuration
18
+ attr_accessor :client
19
+ end
20
+
21
+ ##
22
+ # Setup ams_layout configuration
23
+ #
24
+ # Attempts to find and load a configuration file the first time
25
+ # it's requested. If a config file cannot be found on disk, a
26
+ # default configuration object is created.
27
+ #
28
+ # If a block is provided, the configuration object is yielded to the block
29
+ # after the configuration is loaded/created.
30
+ #
31
+
32
+ def self.configure
33
+ if self.configuration.nil?
34
+ unless self.load_configuration
35
+ self.configuration = Configuration.new
36
+ end
37
+ end
38
+ yield(configuration) if block_given?
39
+ end
40
+
41
+ ##
42
+ # Walk up the directory tree from current working dir (pwd) till a file
43
+ # named .ams_layout is found.
44
+ #
45
+ # Returns file path if found, nil if not.
46
+ #
47
+
48
+ def self.find_config_path
49
+ path = Pathname(Pathname.pwd).ascend{|d| h=d+CONFIG_FILE_NAME; break h if h.file?}
50
+ end
51
+
52
+ ##
53
+ # Write configuration to disk
54
+ #
55
+ # Writes to current working dir (pwd) if path is nil
56
+ #
57
+ # Returns path of emitted file
58
+ #
59
+
60
+ def self.save_configuration(path = nil)
61
+ # If no path provided, see if we can find one in the dir tree.
62
+ if path.nil?
63
+ path = find_config_path
64
+ end
65
+
66
+ # Still no path? Use the current working dir.
67
+ if path.nil?
68
+ path = Pathname.pwd + CONFIG_FILE_NAME
69
+ end
70
+
71
+ path = Pathname(path).expand_path
72
+ File.write(path, YAML.dump(configuration))
73
+
74
+ path
75
+ end
76
+
77
+ ##
78
+ # Load the configuration from disk
79
+ #
80
+ # Returns true if config file found and loaded, false otherwise.
81
+ #
82
+
83
+ def self.load_configuration(path = nil)
84
+ # If no path provided, see if we can find one in the dir tree.
85
+ if path.nil?
86
+ path = find_config_path
87
+ end
88
+
89
+ return false if path.nil?
90
+ return false unless path.exist?
91
+
92
+ File.open(path, 'r') do |f|
93
+ self.configuration = YAML.load(f)
94
+ puts "configuration loaded from #{path}" if $debug
95
+ end
96
+
97
+ true
98
+ end
99
+
100
+
101
+ class Configuration
102
+ attr_accessor :default_environment
103
+ attr_accessor :credentials
104
+ attr_accessor :base_urls
105
+ attr_accessor :aliases
106
+ attr_accessor :page_urls
107
+
108
+ # Default generated class names
109
+ attr_accessor :layout_class_name
110
+ attr_accessor :delegate_class_name
111
+
112
+ # Browser user data path (directory)
113
+ attr_accessor :user_data_path
114
+
115
+ # Browser timeout in seconds. Default: 360 (6 mins).
116
+ attr_accessor :browser_timeout
117
+
118
+ def initialize
119
+ reset
120
+ end
121
+
122
+ def reset
123
+ @default_environment = :dev
124
+
125
+ @credentials = { dev: [ ENV['HSBC_DEV_USER'], ENV['HSBC_DEV_PASSWORD'] ],
126
+ dev2: [ ENV['HSBC_DEV2_USER'], ENV['HSBC_DEV2_PASSWORD'] ],
127
+ sit: [ ENV['HSBC_SIT_USER'], ENV['HSBC_SIT_PASSWORD'] ],
128
+ uat: [ ENV['HSBC_UAT_USER'], ENV['HSBC_UAT_PASSWORD'] ] }
129
+
130
+ @base_urls = { dev: "http://207.38.119.211/fap2Dev/Portal",
131
+ dev2: "http://207.38.119.211/fap2Dev2/Portal",
132
+ sit: "http://207.38.119.211/fap2SIT/Portal",
133
+ uat: "http://207.38.119.211/fap2UAT/Portal" }
134
+
135
+ @aliases = {}
136
+
137
+ @page_urls = { 'PrequalDetail' => "/SubmitLoan/PrequalDetail.aspx",
138
+ }
139
+
140
+ @layout_class_name = 'LoanEntryFields'
141
+ @delegate_class_name = 'DelegateLoanEntryFields'
142
+
143
+ @browser_timeout = 360
144
+ @user_data_path = File.absolute_path(File.join(__FILE__, '../../chrome-data'))
145
+ end
146
+
147
+ def base_url
148
+ @base_urls[@default_environment]
149
+ end
150
+
151
+ def url page_class
152
+ suffix = @page_urls[page_class.to_s.split('::').last]
153
+ raise "Unkown page [#{page_class.to_s}]" if suffix.nil?
154
+ base_url + suffix
155
+ end
156
+ end # Configuration
157
+
158
+
159
+ class Runner
160
+ def initialize(argv, client = AmsLayout::Client.new, exit_code = true)
161
+ @argv = argv
162
+ AmsLayout.client = client
163
+ @exit_code = exit_code
164
+ end
165
+
166
+ def execute!
167
+ exit_code = begin
168
+
169
+ # Run the thor app
170
+ AmsLayout::CLI.start(@argv)
171
+
172
+ # Thor::Base#start does not have a return value,
173
+ # assume success if no exception is thrown.
174
+ 0
175
+ rescue StandardError => e
176
+ b = e.backtrace
177
+ b.unshift("#{b.shift}: #{e.message} (#{e.class})")
178
+ puts(b.map { |s| "\tfrom #{s}"}.join("\n"))
179
+ 1
180
+ end
181
+
182
+ # Return the exit code
183
+ exit(exit_code) if @exit_code
184
+ end
185
+ end # Runner
186
+ end # AmsLayout
187
+
188
+ # Call configure to force creation of the configuration object.
189
+ AmsLayout.configure
190
+
191
+ require "ams_layout/version"
192
+ require "ams_layout/browser_loader"
193
+ require 'ams_layout/client'
194
+ require "ams_layout/parser"
195
+ require "ams_layout/writer"
196
+ require "ams_layout/delegate_writer"
197
+ require "ams_layout/cli"
198
+
@@ -0,0 +1,25 @@
1
+ ---
2
+ BORROWER INFO:
3
+ - :label: Borrower Name
4
+ :id: ctl00_ContentPlaceHolder1_txtBorrowerFirstName
5
+ :type: text
6
+ - :label: Borrower SSN
7
+ :id: ctl00_ContentPlaceHolder1_ssnBorrowerSSN
8
+ :type: text
9
+ - :label: Income Type
10
+ :id: ctl00_ContentPlaceHolder1_ddlBorrowerCurrentEmployment
11
+ :type: select
12
+ ESCROW INFO:
13
+ - :label: Has Escrow Account
14
+ :id: ctl00_ContentPlaceHolder1_ddlHasEscrowAccount
15
+ :type: select
16
+ - :label: Pending Escrow Change
17
+ :id: ctl00_ContentPlaceHolder1_chkNoOrLowIncome
18
+ :type: checkbox
19
+ MANAGER BY-PASS EXCEPTIONS:
20
+ - :label: Adverse Action Code(s) (separated w/comma or space)
21
+ :id: ctl00_ContentPlaceHolder1_txtDenialReasonCounterOffer
22
+ :type: text
23
+ - :label: Manual Decline Comments
24
+ :id: ctl00_ContentPlaceHolder1_txtTextArea301
25
+ :type: textarea
@@ -0,0 +1,22 @@
1
+ ---
2
+ Borrower Name:
3
+ - Alias1 Borrower Name
4
+ - Alias2 Borrower Name
5
+ Borrower SSN:
6
+ - Alias1 Borrower SSN
7
+ - Alias2 Borrower SSN
8
+ Income Type:
9
+ - Alias1 Income Type
10
+ - Alias2 Income Type
11
+ Has Escrow Account:
12
+ - Alias1 Has Escrow Account
13
+ - Alias2 Has Escrow Account
14
+ Pending Escrow Change:
15
+ - Alias1 Pending Escrow Change
16
+ - Alias2 Pending Escrow Change
17
+ Adverse Action Code(s) (separated w/comma or space):
18
+ - Alias1 Adverse Action Code(s) (separated w/comma or space)
19
+ - Alias2 Adverse Action Code(s) (separated w/comma or space)
20
+ Manual Decline Comments:
21
+ - Alias1 Manual Decline Comments
22
+ - Alias2 Manual Decline Comments