Standard event structure

Relevant for: API testing only

This topic describes standard event handlers supported for API tests in UFT One.

For most of the activities supported for API tests, these standard event handlers are the only event handlers supported.

The following diagram shows how each event works within the individual test step run:

BeforeExecuteStepEvent

Purpose: Set conditions and properties of the step required to make the step run or to handle output from a previous step required in the current step

Accessible Properties:

  • Input properties/parameters from the current activity

  • User/test variables from the current test

  • Output properties from a previous test step or a parent activity

/// <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\UFT One\API Test Resources\ConcatenateStrings.xlsx", "Sheet1", true);
    		 GetDataSource("ConcatenateStrings!Sheet1").ImportFromExcelFile(@"C:\Users\user\Documents\UFT One\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);	
    		
    	}

Back to top

AfterExecuteStepEvent

Purpose: Set output properties for the current step or handle the output of the step (to export or save)

Accessible Properties:

  • Output properties/parameters from the current activity

  • User/test variables from the current test

  • Any output from the current test step

/// <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)
    	{
		///Event code is here
    		String WriteToFileContent = this.StServiceCallActivity5.OutputEnvelope.SelectNodes("/*[local-name(.)='Envelope'][1]/*[local-name(.)='Body'][1]/*[local-name(.)='CreateFlightOrder'][1]").ToString();
    		this.FileWriteActivity7.Content = WriteToFileContent;

Back to top

CodeCheckpointEvent

Purpose: To set checkpoint properties and values for the current step

Accessible Properties:

  • Input and output values for the current step

  • User test/variables from the current test.

  • All input and output from the current test step

 /// <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)
        {
            ///Event code starts here
			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 );
        }

Back to top

See also: