65.9K
CodeProject 正在变化。 阅读更多。
Home

桌面自动化与实时示例

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.20/5 (6投票s)

2016年3月19日

CPOL

2分钟阅读

viewsIcon

31605

理解用户业务流程,分析自动化的好处以及设计解决方案的最佳方法和实践

引言

用户流程自动化/桌面自动化现在越来越受欢迎。Openspan、Blue Prism、IE Spy、Spy ++ 等是开发人员用于自动化开发和测试的流行工具。所有这些工具都基于屏幕抓取技术。

在我们开始任何自动化项目之前,需要进行需求分析活动,这与传统的 SDLC 需求阶段略有不同。

  • 计算完成整个流程所需的总时间
  • 识别计算机化用户流程中涉及的重复步骤
  • 研究我们可以节省多少鼠标点击
  • 进行时间和运动研究,并估算如果进行自动化可以节省的潜在成本
  • 评估流程中涉及的应用程序以及在应用程序之间复制和粘贴数据的活动

典型抵押评估流程的高级自动化设计

假设我们的呼叫中心代理在后台流程中收到 100 个客户潜在客户名单(以 Excel 形式),并在电话中向客户解释抵押贷款计算。

  • 从 Excel 表格中动态选择客户,并在 CRM 应用程序中执行搜索
  • 在抵押贷款潜在客户网站 (CRM 应用程序) 中查找客户详细信息
  • 从潜在客户生成器中选择贷款金额,并将其粘贴到 EMI 计算器中
  • 向客户解释 EMI 详细信息。

自动化流程序列

  1. 在一个班次中启动所需的应用程序一次。
  2. 将 Excel 记录加载到 DataGridView 中。
  3. 选择第一个客户。
  4. 从客户那里获取“利率”和“贷款期限”的输入
  5. 单击“计算 EMI”/“查询 EMI”
  6. 在 DataGrid 单元格按钮中捕获客户姓名
  7. 将客户姓名粘贴到潜在客户生成器并进行搜索
  8. 从潜在客户生成器获取抵押贷款价值
  9. 将贷款期限、抵押贷款价值、利率粘贴到 EMI 计算器中

代码与解决方案案例研究

 

private void LaunchApplications()
        {
            // Launch Mortgage Lead Generation Web Application
            string URL = "http://yourInternalSite.com/lead-generation.aspx";
            
            object o = null;
            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
            
            app = (SHDocVw.WebBrowser)ie;
            app.Visible = true;
            app.Navigate(URL, ref o, ref o, ref o, ref o);
            while (app.Busy)
            {

                htmldoc = (HtmlDocument)app.Document;
            }

            System.Threading.Thread.Sleep(2000);
            //Start EMI Calculator   
            System.Diagnostics.Process.Start(@"D:\Automation\EMI_Calculator.exe");
            
                   

        }

将抵押贷款潜在客户 Excel 列表导入到自动化表单中

 

//
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = @"C:\";
            openFileDialog1.Title = "Browse Text Files";
            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = true;
            openFileDialog1.DefaultExt = "xlsx";
            openFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            openFileDialog1.ReadOnlyChecked = true;
            openFileDialog1.ShowReadOnly = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
            }
            System.Data.OleDb.OleDbConnection MyConnection;
            System.Data.DataSet DtSet;
            System.Data.OleDb.OleDbDataAdapter MyCommand;
            MyConnection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Dell Drivers\custList.xlsx';Extended Properties=Excel 12.0;");
            MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
            MyCommand.TableMappings.Add("Table", "Net-informations.com");
            DtSet = new System.Data.DataSet();
            MyCommand.Fill(DtSet);
            dataGridView1.DataSource = DtSet.Tables[0];
            MyConnection.Close();
        }
    }
//

用户流程中的下一步是单击选定的客户以找出客户的 EMI

//
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0)
            {
               string selstrCustomerName= Convert.ToString(senderGrid[1, e.RowIndex].Value);
                
                // Paste name into the Search Text box of the Lead Generater Web Applicaion
               pasteNameIntoLeadGenerator(selstrCustomerName);
            }
        }//

 

在抵押贷款潜在客户 Web 应用程序中搜索客户,找到客户申请表并获取贷款金额。

 

//Searching the selected Customer Name obtained from Grid and pasting into the Mortgage Prospects
//Application
private void pasteNameIntoLeadGenerator(string selstrCustomerName)
{
     var elems = wb.Document.GetElementByTagName("INPUT");

     foreach(HtmlElement elem in elems){
        if(elem.GetAttribute("name") == "txtCustomerName" && elem.GetAttribute("type") == "text"){
             elem.setAttribute("value", selstrCustomerName)        
      }
    }
   // Allowing the UI to Get updated    
   System.Threading.Thread.Sleep(2000)

  // Perform click of go
    foreach(HtmlElement elem in elems){
        if(elem.GetAttribute("type") == "button"  && elem.GetAttribute("name") == "go"){
        elem.InvokeMember("click");
        }
     }
 // Again Allowing web page  to get refreshed
 System.Threading.Thread.Sleep(2000) 
 //Performing one more scan of HTML Collection
  foreach(HtmlElement elem in elems){     
  if(elem.GetAttribute("name") == "txtLoanAmount" && elem.GetAttribute("type") == "text")
    {   
     string LoanAmount=elem.getAttribute("value")         
    } 
  }

}

最后,自动化会将贷款金额与利息金额、贷款期限粘贴到 EMI 计算器中。

要粘贴值,我们首先需要识别 EMI 计算器屏幕,并使用 Spy ++ 获取控件 ID

 

//Identify window by window title by calling windows API function

[DllImport("user32.dll", EntryPoint="FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

//Send Message to the control by identifying text boxes with control ids

[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, string lParam);
public const uint WM_SETTEXT = 0x000C;

private void InteropSetText(IntPtr iptrHWndDialog, int iControlID, string strTextToSet)
        {
            IntPtr iptrHWndControl = GetDlgItem(iptrHWndDialog, iControlID);
            HandleRef hrefHWndTarget = new HandleRef(null, iptrHWndControl);
            SendMessage(hrefHWndTarget, WM_SETTEXT, IntPtr.Zero, strTextToSet);
        }

 IntPtr handle = FindWindowByCaption(IntPtr.Zero, "EMI Calculator");
      //passing values to the controlstrol ids of EMI Calculator using SPY++
      //0001042A-Hexadecimal value of the control id get from spy++
         int decValueofControl = int.Parse(0001042A, System.Globalization.NumberStyles.HexNumber);
             InteropSetText(handle, decValueofControl,LoanAmount);
              

同样,将贷款期限、利率的值从自动化表单粘贴到 EMI 计算器

在这种情况下,EMI 计算器会计算每月 EMI、应付总利息和总付款。

最后,我们构建战术自动化解决方案,看看它是否减少了代理的鼠标点击次数,从而减少了操作周期并优化了“现状用户流程”
 

关注点

在任何提到的工具中,自动化开发中的基本步骤或原则保持不变

  • 对基于 Web、窗口或控制台的应用程序的控件进行询问或唯一标识
  • 读取和写入控件的值,并在应用程序之间粘贴
  • 执行所需的手动活动(通常由用户执行),并且自动化必须按预期的顺序执行相同的操作。

 

© . All rights reserved.