1. Home
  2. OpKey Help
  3. 5. Working with Business Components
  4. 5.5 Coded Business Component

5.5 Coded Business Component

Overview

The Coded Business Component is an advanced feature of OpKey Web. Coded Business Component i editor provides you with a platform where you can write your own function code of tasks to be performed in test automation. Once, they are written in Java, you can compile Java codes and debug easily. You can execute your Coded Business Component i directly or map them with Test Case and execute them. In addition, Coded Business Component i works as a One Stop Solution for creating Custom Keywords in OpKey as you can write your Custom Keyword specific code in Java, compile it to fix code errors, associate required libraries, import pre-built libraries and execute it. Furthermore, this code can directly be called and used in a Test Case or a Business Component and get Executed.

The need of Coded Business Component

OpKey users sometimes needed a platform where they could write their own code for actions (to be performed during test automation) which could be integrated with other OpKey artifacts. Coded Business Component feature fulfilled all those needs by providing a code editor platform. It allows you to write your own action code in Java, compile it, import pre-built libraries, execute it or map with Test Case. It works as a one-stop platform for writing function codes for the task to be performed, compiling written code, making jar file and using jar file in Custom keyword creation. Now, you will not require Eclipse or any other Java code editor for writing your code, making its jar and using it within your Custom Keywords. You can also import your pre-built libraries at Coded Business Component and compile it. Once, your written code is compiled successfully, you can execute it on your machine by using the corresponding Plugin.

For creating Custom keywords in OpKey, you were required to follow the steps mentioned below:

  1. Write the specific code and save it in .jar file.
  2. Upload the .jar file in OpKey and map it with the associated method.
  3. Create and Add a custom Keyword for it.
  4. Call it in a Test Case or a Business Component (BC).
  5. Execute it.

To skip all the steps above, here arises the need of Coded Business Component. One of the major advantages of Coded Business Component over Custom Keyword is that it can be mapped with a number of Libraries & Test Cases and modified frequently as per the requirement.

Prerequisites of Coded Business Component

In order to work on Coded Business Component, there are few prerequisites that need to configure correctly. If it’s not configured in your system then you should follow below given steps and configure the JAVA_HOME path, as required.

1. JAVA_HOME configuration in Windows 10:

  • Make sure that JDK 8 version is installed in your system. (Coded Business Component supports JDK version 8, so far).
  • Click on Start button, Type This PC, right-click on This PC and click on Properties.
  • Click on Advanced system settings tab.
  • Click on Environment Variables link under User Variables section. Click on New and fill values as given below in the screenshot.
  • Click on OK to save.

2. Java Path configuration in Windows 10:

  • Make sure that you have installed JDK 8 version in your system.
  • Click on Start button, Type This PC, right-click on This PC and click on Properties.
  • Click on Advanced system settings tab.
  • Click on Environment Variables link under System Variables section. Click on New and fill values as given below in the screenshot.
  • Click on OK to save.

Overview:

Coded Business Component is an exceptional feature that allows users to write code in Java for performing a particular task. You can compile and execute your code from here. It eliminates the requirement of a separate code editor, making its jar and then using it for creating a Custom keyword.

Working with Coded Business Component:

After successful login into OpKey Surge, you come to the OpKey Surge dashboard page.

  • Click on the Business Component and navigate to the Coded Business Component tab.

NOTE: Recursions are not allowed in OpKey.

The Coded Business Component window will get opened. It has three major sections:

  1. First Section is the Import Section which allows you to import any required pre-built library.
  2. The second section is for the User-Defined code section which allows you to write user-defined code.
  3. The third section is Private Functions which allows you to create user-defined private functions into it.

You can write the specific java code in the Coded Business Component.

 

Getting Familiar with the Coded BC Buttons:

 

Mapping Associated libraries with Coded BC

Libraries are the Jar files that contain specific Java code for performing an action. These libraries are created by the user for creating Custom Keywords. Now you can import those libraries to the Coded BC, compile them here, execute them, and use them in Custom Keywords, as required. Used associated Libraries can be executed in Run Now and Debug now mode.

Follow below-given steps to associate and use pre-built libraries:

  • Click on the Libraries tab.
  • A window containing Linked and Associated Libraries opens as follows.
  • Select your library file from the list of Linked Libraries and click on the Associate button to add them to the Associated Library list.

Let us see now how to import Package(s) to the Coded BC from the Associated Libraries. You should have to know the Package, Class of the Associated Library/Jar file.

In the below-given screenshot, you can have a look at the Associated Library file code (package and class).

  • Write the Import syntax for importing Package(s) and Class of the associated jar file in the Import Section of the Coded BC as:

import Package_Name.Class_Name

For example: Here, SumPck is the Package name and Division is the Class name in the associated library.

  • Let us write a division code in the User Code section. Here, we will divide 10 by 5 which results output as 2. You need to add an Output Parameter of Integer type which will store the Output of Division.

  • Once, codes are written successfully, Save it.

 

Intellisense in Coded Business Component

While writing Java Code in the Coded BC editor, the Intellisense feature helps the user to view suggested syntax which can be used. Make sure that the Intellisense toggle button is in On state. User can press Ctrl+Spacebar button to trigger the Intellisense and view list of all the suggested syntax to be used.

OpKey Coded BC Compiler window appears. It establishes a connection between the OpKey Server and the client machine.

Now, the behavior of Intellisense has been improved. This new version now supports:

  1. Global Variables
  2. Local variables
  3. Classes name
  4. Input parameters
  5. Output Parameters
  6. The Object, Class, Method, Local variables in Intellisense proposal window are visible with their icons.
  7. The Intellisense proposal window now shows all context of available plugins.
  8. The Classes and Methods of the imported package from the associated jar, are now visible in the Intellisense proposals.

 

Using Coded BC file in Test Case & Coded Business Components:

  • You can map your Coded BC file with the Test Case or Business Component file by selecting its mode to Coded BC.
  • Create a BC or a Test Case. Navigate to the Add Step icon, select your Business Component file(s) to be added.
  • Business Component to be successfully added in the corresponding Test Case or Business Component, to use this Business Component in Coded BC state switch its mode to Coded BC as shown below:

 

  • The Selected Coded BC will get added to the BC.
  • Once the Coded BC gets added into the BC. You can add other desired steps into it.
  • Click Run, to execute the BC.
  • The Execution wizard window will get opened and the BC will get executed.
  • You can also generate the desired reports.

Getting familiar with the Details Tabs of Coded BC:

There are various tabs in the dockable panel of the Coded BC. They are used for performing different tasks.

(1) Information:

Here, you can view detailed information (created by, created on, modified by, and modified on) about the Coded BC.

 

(2) Input Parameter :

Input  Parameter tab under the Details section allows you to add Input Parameters to the Coded BC. Added Input Parameters get reflected in the Non-editable section of Coded BC as shown below.
(3) Output Parameter:

Output tab under Details panel allows you to add Output Parameters to the Coded BC. Added Output Parameters get reflected in the Non-editable section of Coded BC as shown below.

 

(4) UsedBy:

UsedBy tab under the details panel provides information about uses of the Coded BC within a TC or BC.

(5) AuditTrails:

AuditTrails tab under details panel provides detailed information (Task, Field, Old Value, New Value, Time Stamp and By User) about the entire changes made to the Coded BC by the user.

(6) Backup:

The backup tab provides the details about any backup activity is done for the corresponding Business Component. The given details include Name, No, comment, and Actions.

Compiling Java Code:

Once, you have mapped desired associated libraries and written your Java Code, you need to compile it. Code compilation leads to easy identification of existing code errors. You can view the code errors in the Compilation Result tab showing under the dockable panel. You need to follow below-given steps while compiling Java code in Coded BC:
  • Map Associated Libraries to your code.
  • Write your action code, as required.
  • Save the Coded BC file.
  • Click on the Compile button.
  • When you select the required plugin from the dropdown list, your code gets changed as per the selected plugin. After selecting a plugin, you should refresh the page.
  • The compilation process starts which will take a few seconds. Once, it gets completed, you can view the code errors in the console view showing under the Compilation Result tab in the dockable panel.

Executing Coded BC in Run mode:

Once, your java code has been compiled successfully, you can execute your Coded BC file. However, it’s not mandatory to compile your Java Code before execution through Run Now. When you execute your Coded BC file, the code compilation process runs prior to execution.
  • Map Associated Libraries to your code.
  • Write your action code, as required.
  • Select Target Plugin from the list.
  • Save the Coded BC file.
  • Click on the Run button.
  • Fill all required fields in the Local Execution Wizard and click on Next.
  • The execution Process starts successfully.

Here, you can view the Execution Logs.

  • Once, execution process has completed, you can view at the Execution Result.

noteWhile working on Coded Business Component feature on Mac machine, local OpKey Agent will not be required for executing Coded Business Component. You can now execute your Coded BC through Spock Agent. Furthermore, you don’t need to install different plugins as Local Agent is not required.

 

noteNow, Spock Agent in Coded Business Component in OpKey supports Java 11. You can execute your Coded BC (developed with Java 11) on Spock Agent.

OR Tree Implementation in Input Parameters:

Now, the user can view the list of OR tree added in the Input Parameter and use them within the Coded Business Component, as required. You can add a new Input Parameter as OR Object Data Type and provide default OR value from the OR tree.

  • Click on Input Parameter tab, opens as shown below:

  • Click on the Add button to add a new Input Parameter. An Input parameter with an input-parameter-1 name has been added.
  • Navigate to the Data Type dropdown tab. Select ORObject from the dropdown list of Data Types.

  • Navigate to the Default Value tab and click on it.
  • Browse and select your desired object. Your ORObject input parameter has been added successfully to the Coded Business Component.

Was this article helpful to you? Yes No