本教程演示如何创建编码测试用例 (applyForLoan.cs ),以验证 UiBank 应用程序计算的贷款利率是否与您自己的计算结果相符。测试用例引用了编码源文件 (LoanApplication.cs ),其中包含一个类,该类具有用于生成测试数据的“GET”和“SET”方法。
创建一个名为 LoanApplication
的类。
为“贷款申请”表单中的每个字段创建一个公共对象,并为每个字段使用“GET”和“SET”方法。
assignment 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;}
}
创建一个新的编码测试用例 (“文件”组>“新建”>“编码测试用例”),并将其命名为“applyForLoan”。
引用您先前在编码测试用例中创建的编码源文件以生成数据。
assignment private LoanApplication myLoanApplication;
private LoanApplication myLoanApplication;
在编码测试用例 (applyForLoan ) 的公共类内部,但在 Execute 方法外部,创建另一个名为“InitializeTestData”的方法。您可以在此处设置“贷款申请”表单中每个字段的值。
assignment 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;
}
在“排列”部分中,初始化测试用例的测试数据。
assignment InitializeTestData ( ) ;
InitializeTestData();
捕获要在“对象存储库”内的编码测试用例中使用的所有用户界面元素。
访问应用程序中的所有用户界面元素并开始自动化!打开 UiBank 应用程序并选择申请贷款。
assignment 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);
使用先前初始化的测试数据填写“贷款申请”表单。
assignment 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());
在“操作”部分中,添加选择“提交”按钮的操作。
assignment loanApplicationForm. Click ( ObjectRepository. Descriptors. UiBank. LoanApplication. SubmitLoanApplication) ;
loanApplicationForm.Click(ObjectRepository.Descriptors.UiBank.LoanApplication.SubmitLoanApplication);
在“断言”部分中,检索应用程序计算的贷款利率,并验证它是否与您在“初始化测试数据”方法中估计的贷款利率相符。
assignment 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);