studio
2024.10
true
UiPath logo, featuring letters U and I in white

Studio 用户指南

上次更新日期 2024年12月19日

向 UiBank 申请贷款

本教程演示如何创建编码测试用例 (applyForLoan.cs),以验证 UiBank 应用程序计算的贷款利率是否与您自己的计算结果相符。测试用例引用了编码源文件 (LoanApplication.cs),其中包含一个类,该类具有用于生成测试数据的“GET”和“SET”方法。
先决条件

创建编码源文件

  1. 创建一个名为 LoanApplication 的类。
  2. 为“贷款申请”表单中的每个字段创建一个公共对象,并为每个字段使用“GET”和“SET”方法。

    稍后,使用预定义值或 API(例如 RandomStringRandomNumber)为对象分配值。

    public class LoanApplication
        {
            public string email {get;set;}
            public int income {get;set;}
            public int loanAmount {get;set;}
            public int loanTerm {get;set;}
            public int age {get;set;}
            public int expectedLoanRate {get;set;}
        }public class LoanApplication
        {
            public string email {get;set;}
            public int income {get;set;}
            public int loanAmount {get;set;}
            public int loanTerm {get;set;}
            public int age {get;set;}
            public int expectedLoanRate {get;set;}
        }
    


创建编码测试用例

  1. 创建一个新的编码测试用例(“文件”组>“新建”>“编码测试用例”),并将其命名为“applyForLoan”。
  2. 引用您先前在编码测试用例中创建的编码源文件以生成数据。
    private LoanApplication myLoanApplication;private LoanApplication myLoanApplication;
  3. 在编码测试用例 (applyForLoan) 的公共类内部,但在 Execute 方法外部,创建另一个名为“InitializeTestData”的方法。您可以在此处设置“贷款申请”表单中每个字段的值。
    public void InitializeTestData()
    {            
                myLoanApplication = new LoanApplication();
                myLoanApplication.age = 42;
                myLoanApplication.email = "john.doe@uipath.com";
                myLoanApplication.income = 30000;
                myLoanApplication.loanAmount = decimal.ToInt32(testing.RandomNumber(20000,30000,0));
                myLoanApplication.loanTerm = 5;
                myLoanApplication.expectedLoanRate = 8;
    }public void InitializeTestData()
    {            
                myLoanApplication = new LoanApplication();
                myLoanApplication.age = 42;
                myLoanApplication.email = "john.doe@uipath.com";
                myLoanApplication.income = 30000;
                myLoanApplication.loanAmount = decimal.ToInt32(testing.RandomNumber(20000,30000,0));
                myLoanApplication.loanTerm = 5;
                myLoanApplication.expectedLoanRate = 8;
    }


  4. 在“排列”部分中,初始化测试用例的测试数据。
    InitializeTestData();InitializeTestData(); 
  5. 捕获要在“对象存储库”内的编码测试用例中使用的所有用户界面元素。


  6. 访问应用程序中的所有用户界面元素并开始自动化!打开 UiBank 应用程序并选择申请贷款。
    var homeScreen = uiAutomation.Open(ObjectRepository.Descriptors.UiBank.HomeScreen);
                    homeScreen.Click(ObjectRepository.Descriptors.UiBank.HomeScreen.Products);
                    homeScreen.Click(ObjectRepository.Descriptors.UiBank.HomeScreen.Loans);
            var applyForLoanScreen = uiAutomation.Attach(ObjectRepository.Descriptors.UiBank.ApplyForLoan);
    				applyForLoanScreen.Click(ObjectRepository.Descriptors.UiBank.ApplyForLoan.ApplyForALoan);var homeScreen = uiAutomation.Open(ObjectRepository.Descriptors.UiBank.HomeScreen);
                    homeScreen.Click(ObjectRepository.Descriptors.UiBank.HomeScreen.Products);
                    homeScreen.Click(ObjectRepository.Descriptors.UiBank.HomeScreen.Loans);
            var applyForLoanScreen = uiAutomation.Attach(ObjectRepository.Descriptors.UiBank.ApplyForLoan);
    				applyForLoanScreen.Click(ObjectRepository.Descriptors.UiBank.ApplyForLoan.ApplyForALoan);
    


  7. 使用先前初始化的测试数据填写“贷款申请”表单。
    var loanApplicationForm = uiAutomation.Open(ObjectRepository.Descriptors.UiBank.LoanApplication);
    
     loanApplicationForm.TypeInto(ObjectRepository.Descriptors.UiBank.LoanApplication.EmailAddress, myLoanApplication.email);
     loanApplicationForm.TypeInto(ObjectRepository.Descriptors.UiBank.LoanApplication.LoanAmountRequested, myLoanApplication.loanAmount.ToString());
     loanApplicationForm.SelectItem(ObjectRepository.Descriptors.UiBank.LoanApplication.LoanTerm, "5");
     Log(loanApplicationForm.ToString());
     loanApplicationForm.TypeInto(ObjectRepository.Descriptors.UiBank.LoanApplication.CurrentYearlyIncome,"30000");
     loanApplicationForm.TypeInto(ObjectRepository.Descriptors.UiBank.LoanApplication.Age, myLoanApplication.age.ToString());var loanApplicationForm = uiAutomation.Open(ObjectRepository.Descriptors.UiBank.LoanApplication);
    
     loanApplicationForm.TypeInto(ObjectRepository.Descriptors.UiBank.LoanApplication.EmailAddress, myLoanApplication.email);
     loanApplicationForm.TypeInto(ObjectRepository.Descriptors.UiBank.LoanApplication.LoanAmountRequested, myLoanApplication.loanAmount.ToString());
     loanApplicationForm.SelectItem(ObjectRepository.Descriptors.UiBank.LoanApplication.LoanTerm, "5");
     Log(loanApplicationForm.ToString());
     loanApplicationForm.TypeInto(ObjectRepository.Descriptors.UiBank.LoanApplication.CurrentYearlyIncome,"30000");
     loanApplicationForm.TypeInto(ObjectRepository.Descriptors.UiBank.LoanApplication.Age, myLoanApplication.age.ToString());
    


  8. 在“操作”部分中,添加选择“提交”按钮的操作。
    loanApplicationForm.Click(ObjectRepository.Descriptors.UiBank.LoanApplication.SubmitLoanApplication);loanApplicationForm.Click(ObjectRepository.Descriptors.UiBank.LoanApplication.SubmitLoanApplication);
  9. 在“断言”部分中,检索应用程序计算的贷款利率,并验证它是否与您在“初始化测试数据”方法中估计的贷款利率相符。
    var loanResultsScreen = uiAutomation.Attach(ObjectRepository.Descriptors.UiBank.LoanResults);
    
     var actualLoanRate = loanResultsScreen.GetText(ObjectRepository.Descriptors.UiBank.LoanResults.LoanRate);
     testing.VerifyExpression(actualLoanRate == myLoanApplication.expectedLoanRate.ToString(),"The expected and actual loan rates are equal.",true, "Verify Expression", true, false);var loanResultsScreen = uiAutomation.Attach(ObjectRepository.Descriptors.UiBank.LoanResults);
    
     var actualLoanRate = loanResultsScreen.GetText(ObjectRepository.Descriptors.UiBank.LoanResults.LoanRate);
     testing.VerifyExpression(actualLoanRate == myLoanApplication.expectedLoanRate.ToString(),"The expected and actual loan rates are equal.",true, "Verify Expression", true, false);
    
    


示例项目

要按照步骤自行操作并试用本教程,请参阅以下示例项目:向 UiBank 申请贷款

  • 创建编码源文件
  • 创建编码测试用例
  • 示例项目

此页面有帮助吗?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath Logo White
信任与安全
© 2005-2024 UiPath。保留所有权利。