标准事件结构

相关项: API 测试

本主题介绍 UFT One 中的 API 测试支持的标准事件处理程序。

对于 API 测试支持的大多数活动,这些标准事件处理程序是唯一受支持的事件处理程序。

下图显示了每个事件在单个测试步骤运行中的工作方式:

BeforeExecuteStepEvent

用途: 设置使步骤运行所需的步骤的条件和属性,或处理当前步骤所需的上一个步骤中的输出

可访问属性:

  • 当前活动中的输入属性/参数

  • 当前测试中的用户/测试变量

  • 上一个测试步骤或父级活动中的输出属性

/// <summary>
    	/// Handler for the ConcatenateStringsActivity4 Activity’s BeforeExecuteStepEvent event.
    	/// </summary>
    	/// <param name=\"sender\">The activity object that raised the BeforeExecuteStepEvent event.</param>
    	/// <param name=\"args\">The event arguments passed to the activity.</param>
    	/// Use this.ConcatenateStringsActivity4 to access the ConcatenateStringsActivity4 Activity's context, including input and output properties.
    	public void ConcatenateStringsActivity4_OnBeforeExecuteStepEvent(object sender, STActivityBaseEventArgs args)
    	{
    		ExcelFileImportInputArgs a = new ExcelFileImportInputArgs(@"C:\Users\user\Documents\Unified Functional Testing\API Test Resources\ConcatenateStrings.xlsx", "Sheet1", true); 
    		 GetDataSource("ConcatenateStrings!Sheet1").ImportFromExcelFile(@"C:\Users\user\Documents\Unified Functional Testing\API Test Resources\ConcatenateStrings.xlsx", "Sheet1", true); 
    		ConcatenateStringsActivity4.Prefix = GetDataSource("ConcatenateStrings!Sheet1").GetValue(0, "Prefix").ToString(); 
    		ConcatenateStringsActivity4.Suffix = GetDataSource("ConcatenateStrings!Sheet1").GetValue(0, "Suffix").ToString(); 
    		this.Context.UserLogger.Info (ConcatenateStringsActivity4.Prefix); 
    		this.Context.UserLogger.Info (ConcatenateStringsActivity4.Suffix); 	
    		
    	}

返回页首

AfterExecuteStepEvent

用途: 设置当前步骤的输出属性或处理步骤的输出 (导出、保存等)

可访问属性:

  • 当前活动中的输出属性/参数

  • 当前测试中的用户/测试变量

  • 当前测试步骤中的任何输出

/// <summary>
    	/// Handler for the FileWriteActivity7 Activity’s AfterExecuteStepEvent event.
    	/// </summary>
    	/// <param name=\"sender\">The activity object that raised the AfterExecuteStepEvent event.</param>
    	/// <param name=\"args\">The event arguments passed to the activity.</param>
    	/// Use this.FileWriteActivity7 to access the FileWriteActivity7 Activity's context, including input and output properties.
    	public void FileWriteActivity7_OnAfterExecuteStepEvent(object sender, STActivityBaseEventArgs args)
    	{
		///事件代码如下
    		String WriteToFileContent = this.StServiceCallActivity5.OutputEnvelope.SelectNodes("/*[local-name(.)='Envelope'][1]/*[local-name(.)='Body'][1]/*[local-name(.)='CreateFlightOrder'][1]").ToString(); 
    		this.FileWriteActivity7.Content = WriteToFileContent;

返回页首

CodeCheckpointEvent

用途: 设置当前步骤的检查点属性和值

可访问属性:

  • 当前步骤的输入值和输出值

  • 当前测试中的用户测试/变量

  • 当前测试步骤中的所有输入和输出

 /// <summary>
        /// Handler for the CodeActivity15 Activity?s CodeCheckPointEvent (General execute event for executing code checkpoints) event.
        /// </summary>
        /// <param name="sender">The activity object that raised the CodeCheckPointEvent event.</param>
        /// <param name="args">The event arguments passed to the activity.</param>
        /// Use args to access the CodeActivity15 Activity's context, including any input and output arguments.
        /// <example></example>
        public void CodeActivity15_OnCodeCheckPointEvent(object sender, CheckpointEventArgs args)
        {
            ///事件代码从此处开始
			string attachPath = CodeActivity15.Input.attachmentPath; 
            string attachmentContent = File.ReadAllText(attachPath); 
            string currDate = DateTime.Now.ToString(); 
            
            currDate = currDate.Substring( 0,currDate.IndexOf(":")  ) ; 
            //args.Checkpoint.Assert.Equals( attachmentContent.Contains(" Current Time = "+currDateTime+"   file was attached$") ,true); 
            //bool status= attachmentContent.Contains(" Current Time = "+currDate); 
            bool status = attachmentContent.Contains( CodeActivity16.Output.currentDateTime ); 
            bool status1 = attachmentContent.Contains("file was attached$"); 
            if (status && status1)
            {
              args.Checkpoint.Report( attachmentContent," Current Time = "+currDate+"   file was attached$","contain",  StatusEnum.Succeed ); 
              
            }
            else
            	args.Checkpoint.Report( attachmentContent," Current Time = "+currDate+"   file was attached$","contain", StatusEnum.Fail ); 
        }

返回页首

另请参见: