Class: HooplaSalesforce::WebAgent
- Inherits:
-
Object
- Object
- HooplaSalesforce::WebAgent
- Defined in:
- lib/hoopla_salesforce/web_agent.rb
Constant Summary collapse
- LOGIN_URL =
'https://login.salesforce.com'
- MAX_CLASSES =
10_000
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #get_all_test_links ⇒ Object
-
#initialize(username, password) ⇒ WebAgent
constructor
A new instance of WebAgent.
- #login ⇒ Object
-
#run_tests(test_names, namespace = '') ⇒ Object
Runs the given tests from the Web UI namespace is the package namespace without the __.
- #test_results_dir ⇒ Object
- #test_results_file(test_name) ⇒ Object
- #test_run_url(test, namespace) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ WebAgent
Returns a new instance of WebAgent.
11 12 13 14 15 16 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 11 def initialize(username, password) @username = username @password = password @agent = Mechanize.new login end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
9 10 11 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 9 def agent @agent end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
9 10 11 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 9 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 9 def username @username end |
Instance Method Details
#get_all_test_links ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 37 def get_all_test_links page = agent.get('/01p') if page.search('.next') = page.search('.fewerMore a').first['href'] enough_rows = .sub(/rowsperpage=\d+/, "rowsperpage=#{MAX_CLASSES}") page = agent.get(enough_rows) end page.search('.dataCell[scope="row"] a') end |
#login ⇒ Object
18 19 20 21 22 23 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 18 def login agent.get(LOGIN_URL).form_with(:name => 'login') do |login| login.un = username login.pw = password end.submit end |
#run_tests(test_names, namespace = '') ⇒ Object
Runs the given tests from the Web UI namespace is the package namespace without the __
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 51 def run_tests(test_names, namespace = '') test_links = get_all_test_links tests = test_names.map do |test_name| { :id => test_links.detect{ |a| a.text == test_name }['href'][1..-1], :name => test_name } end mkdir_p test_results_dir tests.each do |test| results_page = agent.get(test_run_url(test, namespace)) results_table = results_page.search('.outer table td').first File.open(test_results_file(test[:name]), 'w') do |f| f.print results_table.inner_html end puts "#{test[:name]} complete, results in #{test_results_file(test[:name])}." end end |
#test_results_dir ⇒ Object
29 30 31 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 29 def test_results_dir "test-results" end |
#test_results_file(test_name) ⇒ Object
33 34 35 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 33 def test_results_file(test_name) "#{test_results_dir}/#{test_name}.html" end |
#test_run_url(test, namespace) ⇒ Object
25 26 27 |
# File 'lib/hoopla_salesforce/web_agent.rb', line 25 def test_run_url(test, namespace) "/setup/build/runApexTest.apexp?class_id=#{test[:id]}&class_name=#{test[:name]}&ns_prefix=#{namespace}" end |