Using custom code with a Citrix test

You can write custom Java code to expand the functions of HCL DevOps Test Performance (Test Performance).

Before you begin

Custom code requires knowledge of Java programming and the use of the Test Performance API. See Executing test execution with custom code for more information.

About this task

To use custom code for test synchronization:

Procedure

  1. In the test navigator, select the test element location to insert the custom code.
  2. Click Insert > Custom Code.
    A custom code test element is created in the test.
  3. On the Test Element Details page, click Generate Code to create a Java class based on the Test Performance API.
    You can click View Code to edit an existing class.
  4. In the Java editor, add the import statement for Citrix tests: import com.ibm.rational.test.lt.execution.citrix.customcode.*;
  5. Complete the exec method to specify the function to create.
  6. Save and close the Java class.

Example

The following example is custom code class that can be used as a starting point to evaluate the results of a synchronization point. You can use this template to write a class that performs a synchronization when image synchronization and window-event synchronization are not practical for your test.

import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import org.eclipse.hyades.test.common.event.VerdictEvent;
import com.ibm.rational.test.lt.execution.citrix.customcode.CitrixCustomCodeImpl2;
import com.ibm.rational.test.lt.execution.citrix.customcode.ICitrixCustomCode2;

public String exec(ITestExecutionServices tes, String[] args) {
	ICitrixCustomCode2 thisCode = new CitrixCustomCodeImpl2(tes);

	// to get the last VP status
	int verdict = thisCode.getLastVerificationPointVerdict();
	if (verdict != VerdictEvent.VERDICT_PASS) {
	
		// this example reports a message but must be adapted to your specific needs
		tes.getTestLogManager().reportMessage("last VP status: " + thisCode.verdictEventToString(verdict));

	}
	return null;
}

The following example demonstrates how you can record a screen capture during playback for debugging purposes. The screen capture is recorded in the test log and can be viewed in the Citrix image synchronization view.

import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices; 
import com.ibm.rational.test.lt.execution.citrix.customcode.*;

public String exec(ITestExecutionServices tes, String[] args) { 
	
	ICitrixCustomCode2 thisCode = new CitrixCustomCodeImpl2(tes); 
	
	// To capture and log the full screen: 
	thisCode.logFullScreenCapture(); 
	
	// To capture and log a part of the screen: 
	// thisCode.logPartialScreenCapture(x, y, width, height); 
	
	// To capture and log a part of the screen to a file: 
	// thisCode.savePartialScreenCapture(filename, x, y, width, height); 
	
	return null; 
}

What to do next

After creating a custom code test, you can run the test as usual. If you need to debug the test, you can use the monitoring panel to insert breakpoints or to interact with the Citrix environment during execution.