VMware Cloud Community
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Is There a Way to Detect if the JavaScript is Executing in Aria Automation?

The JavaScript Rhino engine can be used outside the JavaScript runtime environment from Aria Automation. This allows us to create JavaScript source code independently from Aria Automation. However, due to the different environments, it may be necessary to distinguish whether the source code is executed in Aria Automation or not. Does anyone know of a way to detect if the source code is executing in Aria Automation or not. Maybe by querying an environment variable? Or the query of an attribute?

Thanks for hints and tips.
Best regards
Stefan


More interesting information at blog.stschnell.de

Labels (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

The setting of environment variables in the context of Aria Automation is very interesting. When the command printenv is entered in a terminal window, many fewer environment variables are displayed than when the same command is executed in an action.

var command = new Command("printenv");
command.execute(true);
var commandOutput = command.output;
System.log(commandOutput);

When I executed the above code, many environment variables were displayed that were specific to Aria Automation. Here a selection:

/**
 * ABX_SERVICE_PORT
 * ABX_SERVICE_SERVICE_HOST
 * ORCHESTRATION_UI_PORT
 * ORCHESTRATION_UI_SERVICE_HOST
 * TENANT_MANAGEMENT_UI_PORT
 * TENANT_MANAGEMENT_UI_SERCICE_HOST
 * VCO_CONTROLCENTER_SERVICE_PORT
 * VCO_CONTROLCENTER_SERVICE_SERVICE_HOST
 * VCO_SERVICE_PORT
 * VCO_SERVICE_SERVICE_HOST
 */

So I tested the following tiny snippet:

var VcoControlcenterServicePort = java.lang.System.getenv("VCO_CONTROLCENTER_SERVICE_PORT");

if (VcoControlcenterServicePort === null) {
  System.log("VcoControlcenterServicePort not set");
} else {
  System.log(VcoControlcenterServicePort);
}

StefanSchnell_0-1693119288788.png

It delivers in the context of Aria Automation a result, and in the context of a simulation null.

StefanSchnell_1-1693119596252.png

This seems to be a valid approach to differentiate whether a program is executed in the context of Aria Automation or not.

However, the question now would be how stable are these environment variables? I have tried this with the Aria Automation version 8.5.1. Has anyone already experience with this?


More interesting information at blog.stschnell.de

View solution in original post

5 Replies
xian_
Expert
Expert
Jump to solution

What if you check whether System object exists?

StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Hello @xian_,

thank you for your suggestion.

But I use a simulation of the System object in my coding outside of the JavaScript runtime environment from Aria Automation. That's why I had thought of an environment variable, for example.

Best regards
Stefan


More interesting information at blog.stschnell.de

Reply
0 Kudos
xian_
Expert
Expert
Jump to solution

some rarely used methods you do not plan to mock, i.e. Server.getAllPluginInfo() ?

StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Hello @xian_ ,

this is a good idea, thank you for your suggestion.

Best regards
Stefan


More interesting information at blog.stschnell.de

Reply
0 Kudos
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

The setting of environment variables in the context of Aria Automation is very interesting. When the command printenv is entered in a terminal window, many fewer environment variables are displayed than when the same command is executed in an action.

var command = new Command("printenv");
command.execute(true);
var commandOutput = command.output;
System.log(commandOutput);

When I executed the above code, many environment variables were displayed that were specific to Aria Automation. Here a selection:

/**
 * ABX_SERVICE_PORT
 * ABX_SERVICE_SERVICE_HOST
 * ORCHESTRATION_UI_PORT
 * ORCHESTRATION_UI_SERVICE_HOST
 * TENANT_MANAGEMENT_UI_PORT
 * TENANT_MANAGEMENT_UI_SERCICE_HOST
 * VCO_CONTROLCENTER_SERVICE_PORT
 * VCO_CONTROLCENTER_SERVICE_SERVICE_HOST
 * VCO_SERVICE_PORT
 * VCO_SERVICE_SERVICE_HOST
 */

So I tested the following tiny snippet:

var VcoControlcenterServicePort = java.lang.System.getenv("VCO_CONTROLCENTER_SERVICE_PORT");

if (VcoControlcenterServicePort === null) {
  System.log("VcoControlcenterServicePort not set");
} else {
  System.log(VcoControlcenterServicePort);
}

StefanSchnell_0-1693119288788.png

It delivers in the context of Aria Automation a result, and in the context of a simulation null.

StefanSchnell_1-1693119596252.png

This seems to be a valid approach to differentiate whether a program is executed in the context of Aria Automation or not.

However, the question now would be how stable are these environment variables? I have tried this with the Aria Automation version 8.5.1. Has anyone already experience with this?


More interesting information at blog.stschnell.de