Use Service Virtualization (on-premises)
UFT Mobile's integration with Service Virtualization (SV) supports testing through UFT Developer or Appium tests. This topic describes how to use Service Virtualization for testing a mobile app with UFT Developer. This section is relevant only for on-premises deployments of UFT Mobile.
Enable SV Simulation
The following steps describe how to use service virtualization with UFT Developer and UFT Mobile:
- Before working with SV, make sure that you have set up UFT Mobile for service virtualization. For details, see Set up Service Virtualization (on-premises)
- Enable SV in the LeanFT config.json file. If needed, configure the SV proxy and outbound proxy address:
- SV proxy address. By default, SV uses the proxy address: localhost: 9000. To configure a different port number, add an inProxyPort number definition in the "sv" section of the config file.
- outProxy address. If your network requires a proxy to access the Internet, add an outProxy string definition in the "sv" section of the config file
Example:
{ "port": 5095, "maxLicensesAllowed": 1, "usageTracking": false, "sv": { "enabled": true, "inProxyPort": 7777, "outProxy": "http://proxy.example.com:8084" } }
Learn the back-end service
Discover the endpoints
- In your IDE, select UFT Developer > Launch a UFT Mobile Device. Select a device that you have enabled for SV (it should have the SV icon
in the right-hand corner) and then click the check mark on the right.
- In your IDE, select UFT Developer >Launch Service Virtualization to open the Service Virtualization window.
- In the DISCOVERY tab, select Mobile in the top-right, and click DISCOVER. Wait for confirmation that the discovery is running.
- On the remote device screen viewer, open the packaged version of your app for testing. The endpoint discovered by SV are displayed in the SV window.
- In the Service Virtualization window, click Stop and view the discovered list of endpoints.
Learn the scenario
- In the LEARNING tab, in the list of endpoints, select the ones you want to simulate.
- Enter a name for the scenario you want to create, click LEARN, and wait for confirmation that the learning is running.
- Go back to the application in the remote device screen viewer, and refresh the app or perform some steps to generate data on the endpoint.
- In the Service Virtualization window, click Stop.
- The learning session generates a set of files for the scenario, saved to the path that you specified.
Run a test with the simulated scenario
Extend your UFT Developer test by including the simulation model generated during the SV learning:
- Add the following import statements to your code:
import org.microfocus.sv.api.SvClient
- Use the
.getSvInfo()
method to retrieve the address of the SV endpoint that is providing the simulation services for the run. Use the SV Lab Client SDK to load the lab using the address of the SV endpoint and scenarios that you recorded, and to run the simulation as follows:
//import SV libraries import org.microfocus.sv.api.SvClient //Create SV client pointing to the endpoint sv = SvClient.newInstance(device.getSvInfo().getEndpoint()); // Load a module to the server to create a lab and start it sv.loadActiveVirtualLab("classpath:/sv-lab.json", sv.compileModuleFromSources("classpath:/<recorded SV scenario files folder>/*"), true); sv.startActiveVirtualLab(); //When the test case starts, start simulation of scenario sv.runSimulation("<Scenario Name"); //Stop simulation and lab sv.stopActiveVirtualLab(); sv.close();
For a runnable demo project, see SV integration on the git repository.
For more details on using Service Virtualization with UFT Developer, see the UFT Developer Help Center.