Permalink
Browse files

implemented convert lead and rspec test

  • Loading branch information...
eslater committed Mar 22, 2012
1 parent 3952d0c commit 78f031150033a79a53df80394f1962cf2398814f
View
@@ -11,7 +11,6 @@
require 'salesforce/model/simple'
-require 'salesforce/core/sf_model'
require 'salesforce/core/sf_view'
require 'salesforce/core/sf_controller'
@@ -4,5 +4,27 @@ class Lead < SFController
@view = Salesforce::LeadView
@model = Salesforce::LeadModel
+ def convert
+ cl_control = ConvertLead.new(@model)
+ cl_control.create
+ end
+
+ class ConvertLead < SFController
+
+ @view = Salesforce::LeadView::ConvertLeadView
+ @model = Salesforce::ConvertLeadModel
+
+ def initialize(l_model)
+ cl_model = ConvertLeadModel.new
+ cl_model.account_name = "Create New Account: " + l_model.company
+ super(cl_model)
+ end
+
+ #TODO: Find out why select list is not working
+ #def populate_account_name; end
+ #def verify_account_name; end
+
+ end
+
end
end
@@ -10,5 +10,18 @@ def defaults
}
end
+
+ end
+
+ ConvertLeadModel = Struct.new(*LeadView::ConvertLeadView.keywords) do
+
+ include Model::Simple
+
+ def defaults
+ {
+ :dont_create_opp => true
+ }
+ end
+
end
end
@@ -27,5 +27,29 @@ def search_params(model)
end
+ #convert lead page
+ class ConvertLeadView < SFView
+
+ keyword(:convert_button) {browser.button(:name,"convert")}
+
+ #fields
+ keyword(:record_owner) {browser.text_field(:name,"owner_id")}
+ keyword(:send_email) {browser.checkbox(:pname,"sem")}
+ keyword(:account_name) {browser.select_list(:name,"accid")}
+ keyword(:opp_name) {browser.text_field(:name,"noopptt")}
+ keyword(:dont_create_opp) {browser.checkbox(:name,"nooppti")}
+ keyword(:converted_status) {browser.select_list(:name,"cstatus")}
+
+
+ class << self
+
+ def create(model)
+ convert_button.click
+ end
+
+ end
+
+ end
+
end
end
@@ -21,6 +21,8 @@ def update hash
hash.each_pair do |key, value|
if key == :searchgroup; next end
if key == :searchstring; next end
+ if key == :waittime; next end
+ if key == :retries; next end
send "#{key}=", value
end
self
@@ -21,7 +21,7 @@ def search(rasta, select_item_if_found = true)
return true if look_in_recent_items(rasta[:searchgroup], rasta[:searchstring])
# Check the search widget
return true if look_in_search_popup(select_item_if_found, rasta)
- log("SF::SEARCH - DID NOT FIND ANYTHING")
+ puts("SF::SEARCH - DID NOT FIND ANYTHING")
false
end
@@ -56,7 +56,7 @@ def look_in_recent_items(searchgrp, searchstr)
# "singular" version of that value. This means we want to look for a match for either
# "Accounts" (the original) or "Account" a singular version we create. From what I
# have seen, the "recent items" list has only singular, but I am not going to change
- # the "look for both" logic yet.
+ # the "look for both" putsic yet.
# Here we use a smart way to turn the "searchgrp" string into a singular form of the
# string. This works for both "Accounts" and "Batches" As mentioned before, we then look
@@ -68,14 +68,14 @@ def look_in_recent_items(searchgrp, searchstr)
# characters ( .|()[]{}+\^$*?) and we need to escape them. Only
# time I saw this was escaping a "blank char" in multi-word string.
searchstring = Regexp.escape(searchstr)
- #log("SF::SEARCH - escaped the search string - result is \"#{searchstring}\" string")
+ #puts("SF::SEARCH - escaped the search string - result is \"#{searchstring}\" string")
# 3) The final addition to the recent items regular expression is to
# look for search string alone, or a search string with some date
# appeneded to the string.
# - "searchgroup: searchstring" or
# - "searchgroup: searchstring\s+##/##/####"
- #log("SF::SEARCH - searching recent with \"(#{searchgroup_orig} OR #{searchgroup_singular}): #{searchstring}($|\s+\d{2}\/\d{2}\/\d{4})\" pattern string")
+ #puts("SF::SEARCH - searching recent with \"(#{searchgroup_orig} OR #{searchgroup_singular}): #{searchstring}($|\s+\d{2}\/\d{2}\/\d{4})\" pattern string")
# locate the sidebar
sidebar_div = Page.browser.div(:class, 'sidebarModule recentItemModule')
@@ -92,28 +92,28 @@ def look_in_recent_items(searchgrp, searchstr)
return true
end
rescue WIN32OLERuntimeError
- log("SF::SEARCH: failed with a WIN32OLERuntimeError")
+ puts("SF::SEARCH: failed with a WIN32OLERuntimeError")
# ignore and try a standard search. Not sure why this happens
# but nextsibling here sometimes gives this error
end
end
false
end
- #TODO: change refs to SFPage to SFPage and add keywords to SFPage
+ #TODO: change refs to SFView to SFView and add keywords to SFView
def chatter_search(select_item, rasta)
begin
url = Page.browser.url
- SFPage.chatter_search_term.focus
- SFPage.chatter_search_term = ''
- SFPage.chatter_search_term = rasta[:searchstring]
- SFPage.chatter_search_button.click_no_wait
+ SFView.chatter_search_term.focus
+ SFView.chatter_search_term = ''
+ SFView.chatter_search_term = rasta[:searchstring]
+ SFView.chatter_search_button.click_no_wait
# This is a little complicated. What happens is that in some environments, when
# running a series of chatter searches (which is common in cleanup routines), Salesforce
# will choke and never load the page that has the search request (browser stuck waiting for site).
- # This causes the scripts to run unreliably, so we've added this wait logic to trap this
+ # This causes the scripts to run unreliably, so we've added this wait putsic to trap this
# scenario and set up for a retry. Since it was hanging on Page.browser.wait
- # we needed a little different logic to trap the broken state while at least waiting
+ # we needed a little different putsic to trap the broken state while at least waiting
# some amount of time for the page to load
Watir::Wait.until(5) {url != Page.browser.url && Page.browser.document.readystate == 'complete'}
Page.browser.wait
@@ -123,15 +123,15 @@ def chatter_search(select_item, rasta)
end
# Scope search option to all data types
- if SFPage.chatter_options_frame.exists?
- SFPage.chatter_option_all.value = true
- SFPage.chatter_option_save.click
+ if SFView.chatter_options_frame.exists?
+ SFView.chatter_option_all.value = true
+ SFView.chatter_option_save.click
end
unless Page.browser.text =~ /(No matches found|No recent records)\./
- searchgroup = SFPage.search_list_section(rasta[:searchgroup])
+ searchgroup = SFView.search_list_section(rasta[:searchgroup])
if searchgroup
- list_link = SFPage.search_list_link(searchgroup, rasta[:searchstring])
+ list_link = SFView.search_list_link(searchgroup, rasta[:searchstring])
if list_link.exists?
list_link.click if select_item
return true
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe "Automating the Lead Conversion" do
+
+ before :all do
+ @model = LeadModel.new
+ @model[:first_name] = "Art"
+ @model[:last_name] = "Vandelay"
+ @model[:company] = "Vandelay Industries"
+
+ @lead = Lead.new(@model)
+
+ Login.new(LoginModel.new).login
+ end
+
+ it "can be created and converted to a contact" do
+ @lead.get
+ @lead.convert
+ end
+
+end

0 comments on commit 78f0311

Please sign in to comment.