Service Virtualization - SV Lab

Supported in LeanFT versions 14.52 and later (in 14.52, as a tech preview)

LeanFT integrates with Service Virtualization (SV), enabling you to test your web applications in various scenarios, even if the services it uses are not ready, or you need to test conditions that are currently unavailable.

The LeanFT installation includes an on-premises installation of the Service Virtualization Lab.

After enabling the integration, you can use SV when designing web tests or running them.

LeanFT 14.53 or later: If Mobile Center - Service Virtualization Lab integration is set up, you can use Service Virtualization when running LeanFT tests on mobile devices as well.

Note: This topic is aimed at people familiar with service virtualization and the use of SV Lab. If you are new to SV and would like to learn more, we recommend that you visit the Service Virtualization Help Center.

System requirements

To use the SV integration in LeanFT, you must have Java 1.8 installed.

Back to top

Enable Service Virtualization in LeanFT

Add or edit the sv definition in the LeanFT config.json file. See the bold text added below.

{
   ...
    ...
    ...
    "port": 5095,
    "maxLicensesAllowed": 1,
    "usageTracking": false,
    "sv":{
           "enabled": true
}

}

Back to top

Configure the SV Lab license server URL

Supported in LeanFT versions 14.53 and later

Configure the URL of an SV license server to enable simulating scenarios on more than 3 endpoints at a time.

Do one of the following: 

  • In the file <LeanFT installation>\sv\conf\svlab.properties, add or edit the SVLicenseServerUrl property to define the SV license server address and port.

    SVLicenseServerUrl=<host>:<port>
  • Define the SV license server address and port in the SVLicenseServerUrl Java System property.

Back to top

Configure SV's communication ports

The SV integration is based on the following flow:

When you open an application in your browser, the browser first connects to the SV Lab server, which, in turn, connects to the web application. This enabled SV to simulate services that the application requires.

Perform the configuration steps below to enable the SV communication flow

  • SV proxy address. The proxy for browsers to use when using SV.

    By default, SV uses the proxy address: localhost:9000.

    To configure a different port number, add an inProxyPort number definition in the "sv" section that you added to the config file.

  • outProxy address. If your network requires a proxy to access the Internet, you must configure the proxy address for SV to use when accessing your application.

    Add an outProxy string definition in the "sv" section that you added to the config file.

    Example:

        "sv":{
               "enabled": true,
    	    "inProxyPort": 7777,
    	    "outProxy": "http://proxy.example.com:8084"
             }
    
  • Configure your browser to use the SV proxy address.

    To enable SV to intervene when you open an application in your browser, you must configure the browser to use the SV proxy address localhost:9000, or localhost:<configured inProxyPort number>.

    To use SV when designing LeanFT tests in your IDE, you must configure your browser proxy manually.

    To use SV when running a LeanFT test, you can do this programmatically, as described further below.

    Tip:  

    • After setting this proxy, if you use your browser when SV is not running, the browser will not be able to reach any URLs.

    • Keep in mind that Internet Explorer proxy definitions affect other programs on your computer as well. Some steps you may need to take to mitigate this:

      Select Bypass proxy server for local addresses in the browser's proxy server definitions.

      Add LeanFT's concurrent license server address to the list of addresses that should not use the proxy.

      Change your eclipse proxy definitions to use the Manual Active Provider option instead of the Native one.

Config file location

Windows

%localappdata%\LeanFT\config\. If this folder does not exist, create it.

Linux ~/.leanft/config
Mac ~/Library/Application Support/LeanFT/config

Note: If this is your first time editing the configuration file, the config folder will be empty. You need to copy the file from:<LeanFT installation>/lwe/lightweight-engine/config

Back to top

Use SV when designing LeanFT tests in your IDE

Start SV from the LeanFT Eclipse or IntelliJ IDEA plug-in and do the following: 

  • Discover all of the endpoints that your application communicates with.
  • Learn the details of the scenarios you want to simulate.
  • Simulate the relevant scenarios.

To use SV during LeanFT test design

  1. Prerequisites:

  2. In Eclipse or IntelliJ IDEA, select LeanFT  > Launch Service Virtualization.

    The Service Virtualization window opens.

  3. Discover the endpoints your application uses.

    1. In the DISCOVER tab, click DISCOVER and wait for confirmation that the discovery is running.
    2. In a browser window, navigate to your web application and perform some steps on it, so SV can discover the endpoints the application uses.

      Tip: If you change the config file at this point, you need to restart the LeanFT runtime engine and re-open Service Virtualization.

    3. In the Service Virtualization window, click Stop and view the discovered list of endpoints.

    4. You can manually add additional endpoints that you know the application uses but were not discovered during the set of steps you ran on the application.
  4. Learn which data is transmitted through the endpoints.

    1. In the LEARN tab, in the list of endpoints, select the ones you want to simulate.

    2. Enter a name for the scenario you want to create, click LEARN, and wait for confirmation that the learning is running.

      By default, the scenario files are saved in %localappdata%\LeanFT\sv-scenarios\ (on Windows).

      You can change this location by adding a scenariosFolder string definition in the "sv" section that you added to the config file.

    3. Clear your browser's cache to make sure it does not use local data for the next application session.

    4. Reload the application, and perform some steps to generate data on the endpoint.

    5. In the Service Virtualization window, click Stop.

    6. In the scenario path displayed in the LEARNING tab, open the .js file that contains the scenario data.

      Each scenario may contain multiple simulation files for multiple endpoints. Use the files named <endpoint name>Model.js

      You can change data in this file, specifying the data SV should use when simulating the relevant endpoint.

  5. Simulate a scenario the application uses.

    You can run the following steps a few times, with different data in the simulation file each time, and test that the application behaves accordingly.

    1. In the SIMULATION tab, select the scenario that you want to simulate, click SIMULATE, and wait for confirmation that the simulation is running.

      The Server Endpoint Address indicates the address of the SV Lab server that is providing the simulation services for this run.

      Note: You can create and store multiple scenarios. However, when running a simulation session, you can use only one scenario at a time.

    2. Clear your browser's cache to make sure it does not use local data for the next application session.

    3. Reload the application, and perform some steps that require the simulated scenario.

    4. Click Stop when you want to stop the simulation. For example, if you want to let the real endpoint handle the communication.

Note: When you close your IDE, Service Virtualization processes sometimes remain running on your computer. We recommend that you verify that all SV processes stopped and manually stop any remaining ones.

Back to top

Use SV Lab when running LeanFT tests

To use service virtualization in LeanFT Java tests, do the following:

  1. Include the SV Lab Client SDK .jar file provided with the LeanFT installation, from the <LeanFT install>\SDK\Java\sv folder:

    LeanFT 14.52: Include the file named sv-lab-client-5.0.1.jar

    LeanFT 14.53 and later: Include the file named sv-lab-client-all-5.1.0.jar

  2. Add the following import statements to your code: 

    import org.microfocus.sv.api.SvClient;
    import org.microfocus.sv.model.project.Module;
    
  3. Use the getSvInfo method to retrieve the address of the SV endpoint that is providing the simulation services for this run.

    For web testing in a Desktop environment, retrieve the SV web proxy address as well, and configure your web browser to use it.

    Perform the following steps: 

    Desktop environment Mobile device
    1. Use the LeanFT Java SDK method Desktop.getSvInfo to retrieve the SV web proxy address and the address of the SV endpoint that is providing the simulation services for this run.

    2. Configure your web browser to use the SV web proxy, in one of the following ways:

      • Configure the browser manually as described above.

      • Configure the browser automatically in your test steps, providing the proxy information in your BrowserFactory.launch statement. For details, see the example below or the Java SDK.

    Running parallel tests

    When you run multiple tests in parallel, multiple SV Lab servers run in parallel. Each test communicates with one server, using the endpoint address retrieved by getSvInfo.

    In this case, do not define the inProxyPort in the config.json file. LeanFT allocates an available port for the SV web proxy and returns it in getSvInfo. Use this proxy in BrowserFactory.launch step.

    LeanFT 14.53 and later:

    1. Make sure Service Virtualization is set up and enabled on your device in Mobile Center. For details, see Mobile Center Help.

    2. Use the LeanFT Java SDK method Device.getSvInfo to retrieve the SV endpoint in Mobile Center that is providing the simulation services for this run.

      Note: Device.getSvInfo always returns NULL for the SV web proxy address. LeanFT does not need this information, as Mobile Center manages the communication between the Mobile web browser and SV.

  4. Use the SV Lab Client SDK to start and stop simulation during your test run, using the address of the SV endpoint and scenarios that you prepared in advance.

    • For details on how to customize simulations, see the Service Virtualization Help Center.
    • For details on the SV Lab Client SDK, see the API documentation available in <LeanFT install>\SDK\Java\sv\sv-lab-client-<version number>-javadoc.jar. (Unzip the file and open index.html)

Back to top

Examples - LeanFT tests with Service Virtualization

The following examples show a LeanFT test written in Java, which use Service Virtualization.

You can see the imported packages, the call to Desktop.getSvInfo() or Device.getSvInfo(), and the subsequent calls to the SV Lab Client methods: newInstance(inf.getEndpoint()), loadActiveVirtualLab, startActiveVirtualLab, runSimulation, stopSimulation, and stopActiveVirtualLab.

In the Desktop example, you can also see the BrowserFactory.launch method, which specifies the SV web proxy address for the browser to use.

Back to top

14.53 or later: Using LeanFT-SV tests created in LeanFT 14.52

LeanFT 14.53 uses a newer version of the SV Lab. Therefore, to run LeanFT tests with SV that were created in LeanFT14.52, you need to perform the following steps:

  • Replace the sv-lab-client-5.0.1.jar file included in your project with sv-lab-client-all-5.1.0.jar, located in <LeanFT install>\SDK\Java\sv.

  • In calls to the method SvClient.loadActiveVirtualLab, add the new required boolean argument forceDeploy. This argument defines whether to undeploy an existing lab with the same ID if such exists.

    Use 'true' to preserve the behavior that you had in LeanFT 14.52.

Back to top

See also: