Editing Java Scripts using Eclipse

Eggplant Performance features an Eclipse plug-in that makes it easier and faster to develop Java virtual user (VU) scripts. Eclipse JDT (Java Development Tools) is a powerful integrated development environment (IDE) for developing Java scripts, with benefits such as:

  • Syntax highlighting
  • Code assist — Eclipse suggests and can auto-complete variable, method, and class names as you type
  • Automatic building
  • Javadoc support — Hover over a variable, method, or class name, and Eclipse shows relevant help documentation in a pop-up window

Learn more about the Eclipse platform and Eclipse JDT.

Download Eclipse

You can download Eclipse from the Eclipse downloads page. There are several versions available. For developing Web Java VU scripts, we require Eclipse Luna, version 4.4 or later.

In the current version, Eggplant Performance Web Java only supports a 32-bit JVM for running scripts. Users should install the latest Eclipse IDE for Java Developers, then make sure it uses the 32-bit JRE.

Note that if a JRE is already installed on your system, it might be a 64-bit version, which is currently not supported. To ensure a 32-bit JRE is used, update your eclipse.ini, which is located in the Eclipse installation directory, by adding the following to the existing list of arguments:

-vm

C:\Program Files (x86)\eggPlant Performance\re\java\jre1.8.0_25\bin

Launching Eclipse from Eggplant Performance Studio

With a project open in Eggplant Performance Studio:

  • On the Build menu, click Start IDE, and then click Start Project IDE.

    OR click the Start IDE button on the toolbar.

Launch a project IDE in Eggplant Performance

If you did not configure an IDE, a message appears asking you to locate an IDE.

No IDE warning dialog in Eggplant Performance

  • Click Yes, and then navigate to the directory where you unzipped Eclipse.
  • Select eclipse.exe, and then click Open.

Studio installs the Eggplant Performance Eclipse plug-in into the /dropins directory of your Eclipse installation, and launches Eclipse.

If you have previous experience using Eclipse, you might be wondering which workspace directory Eclipse will use.  When you launch Eclipse from Studio, Eclipse will use a default workspace, which is located within the Eggplant Performance workspace directory structure.

Note: If there is a Java Development Kit (JDK) or Java Runtime Environment (JRE) that is globally available on Windows (i.e., it is on the PATH environment variable), and it is not of the required version (1.8+), or if it is a 64-bit version, you might see an Unsupported major/minor version error reported by the Eggplant Performance Eclipse plug-in when you launch Eclipse for the first time. To resolve this error, you must ensure that Eclipse is launched using a 1.8 or later version of the JDK/JRE. We recommend using the version that is shipped with Eggplant Performance (by default, located at C:\Program Files (x86)\eggPlant Performance\re\java\jre1.8.0_25\). You can configure Eclipse start up in the eclipse.ini file, as documented on the Eclipse Wiki.

Managing IDE settings

On the Tools menu, click Preferences.

  1. In the Eggplant Performance Studio Preferences, select Compilers and IDEs from the list on the left.
  2. Under Java, specify a direct path to Eclipse, or use the associated browse button to locate the application.
  3. (Optional) Specify a compiler if necessary.

Java IDE Management

Creating Eggplant Performance Projects in Eclipse

The Eggplant Performance Eclipse plug-in enables you to edit Web Java VU scripts using Eclipse. An Eclipse project is created, which links to an Eggplant Performance project in your Eggplant Performance workspace, containing the Web Java VU scripts.

Note: Before you perform this step, you must build the project using Eggplant Performance Studio at least once.
  • On the Build menu, click Build.

    OR on the toolbar click Build.

Build menu options in Eggplant Performance

When you launch Eclipse from Eggplant Performance Studio, an Eclipse project is automatically created for the Eggplant Performance project currently open in Studio. Inside this project you will find the Web Java VU scripts that have been created or generated in Eggplant Performance Studio.

If it doesn't already exist, Eclipse creates a project for the specified Eggplant Performance workspace too. Inside this project you will find code for the custom VUs that exist in the Eggplant Performance workspace.

Project explorer in Eclipse SDK

In the Eggplant Store Demo example workspace, each of the Web Java Virtual User scripts are defined as classes which extend eggPlantStoreDemo_java.MyJavaWebVUScript. In this base class is a method named getVU() which returns an object of type eggPlantStoreDemo_java.MyJavaWebVU. This class defines methods that are useful for interacting with the EggplantStore Demo website, and can be re-used in many scripts, such as findFirstSearchMatch() as used in the Search Virtual User script below. Press F3 while the cursor is in a method name and Eclipse will show the code where that method is defined.

Eclipse store demo example

If you hover over an error or a warning in the code editor, Eclipse suggests options for automatically fixing the error or warning. Click the link and the action will be carried out.

Unused import statement warning in Eclipse

Creating Eclipse Projects Manually

In most cases, Eclipse projects are created automatically when you launch them from Eggplant Performance Studio. However, there is a wizard to create Eclipse projects from a specific Eggplant Performance workspace and Eggplant Performance project, which you can use as described below:

  1. On the File menu, click New, and then click Project.

    OR, if the workbench is visible, on the toolbar click New Project.

    Eclipse new project

  2. In the New Project window, expand Eggplant Performance in the Wizards list, and then click Eggplant Performance Project.
  3. Click Next.

    New Project wizard in Eclipse

  4. Select the Eggplant Performance workspace and Eggplant Performance project from the lists, and then click Finish.

    Eggplant Performance settings in Eclipse

Developing Web Java Virtual User Scripts in Eclipse

Creating Scripts

Important: In the current version of the Eggplant Performance Eclipse plug-in, scripts must be created in Eggplant Performance Studio for them to be included in tests. However, once a script has been created or generated in Eggplant Performance Studio, it should appear in the Eclipse project. If it doesn't appear, right-click the project in the Package Explorer view, and then click Refresh.

Writing Code

Eclipse has content-assist to speed up scripting and reduce typing errors. This means that as you type code, Eclipse suggests variable or method names that you might be trying to use, and you can press Enter for Eclipse to insert the remaining characters automatically. To bring up the content-assist menu when it is not visible, press Ctrl+Space.

eclipse-content-assist

Eclipse also shows javadoc documentation for classes, methods, and variables when using content-assist, and also when the cursor is hovered over a class, method or variable name in the code editor.

Building and Running

By default, Eclipse builds the Eggplant Performance project code automatically whenever a script is modified and saved, by using the build.xml Ant file present in the Eclipse project. This means that you don't have to do anything extra before running a test using Eggplant Performance Test Controller.

To disable automatic building in Eclipse:

  • On the Project menu, click to remove the check mark by Build Automatically.

In this case, the project must be built manually before a test can be run:

  • On the Project menu, click Build Project.

 

This topic was last updated on June 10, 2020, at 03:02:15 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2020 Eggplant