エンドポイント経由で送信されるデータをシミュレートする前に、エンドポイント経由で送信されるデータを学習する必要があります。詳細については、「エンドポイント経由で送信されるデータの学習」を参照してください。
既存の Silk4J スクリプトにサービス仮想化機能を追加するには:
private static Desktop desktop = new Desktop();
private static SvClient sv;
import org.junit.BeforeClass; import com.microfocus.silktest.jtf.sv.SvLabIntegration; import org.microfocus.sv.api.SvClient; import org.microfocus.sv.model.project.Module;
@BeforeClass public static void startSVLabSimulation() { String scenarioName = "PopularProducts"; SvLabIntegration svLabIntegration = desktop.getSvLabIntegration(); String endpoint = svLabIntegration.getServerEndpoint(); sv = SvClient.newInstance(endpoint); Module module = sv.compileModuleFromSources("classpath:/" + scenarioName + "/*"); sv.loadActiveVirtualLab("classpath:/" + scenarioName + "/sv-lab.json", module, true); sv.startActiveVirtualLab(); sv.runSimulation(scenarioName); }
import org.junit.AfterClass;
@AfterClass public static void stopSVLab() { if (sv != null) { sv.close(); } }
import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.microfocus.sv.api.SvClient; import org.microfocus.sv.model.project.Module; import com.borland.silktest.jtf.BrowserBaseState; import com.borland.silktest.jtf.Desktop; import com.borland.silktest.jtf.xbrowser.DomElement; import com.microfocus.silktest.jtf.sv.SvLabIntegration; public class MyTest { private static Desktop desktop = new Desktop(); private static SvClient sv; @BeforeClass public static void startSVLabSimulation() { String scenarioName = "PopularProducts"; SvLabIntegration svLabIntegration = desktop.getSvLabIntegration(); String endpoint = svLabIntegration.getServerEndpoint(); sv = SvClient.newInstance(endpoint); Module module = sv.compileModuleFromSources("classpath:/" + scenarioName + "/*"); sv.loadActiveVirtualLab("classpath:/" + scenarioName + "/sv-lab.json", module, true); sv.startActiveVirtualLab(); sv.runSimulation(scenarioName); } @Before public void baseState() { // Go to web page 'http://advantageonlineshopping.com' BrowserBaseState baseState = new BrowserBaseState(); baseState.execute(desktop); } @Test public void testSimulatedProduct() { DomElement firstPopularItem = desktop.<DomElement> find("//BrowserApplication//BrowserWindow//P[@name='popular_item_16_name']"); Assert.assertEquals("SIMULATED: HP ELITEPAD 1000 G2 TABLET", firstPopularItem.getText()); } @AfterClass public static void stopSVLab() { if (sv != null) { sv.close(); } } }