Scenario:
- open main page and click on "Accept All Cookies" (JSR223 Sampler1 in Once Only controller);
- open pages from the set of parametrized urls (JSR223 Sampler2 in another controller).
JSR223 Sampler1 code for main page:
import org.apache.jmeter.samplers.SampleResult; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.WebDriver; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import java.util.concurrent.TimeUnit;
System.setProperty("webdriver.chrome.driver", "vars.get("webdriver_path")");
Map<String, Object> mobileEmulation = new HashMap<>(); mobileEmulation.put("userAgent", "vars.get("userAgent")"); Map<String, Object> chromeOptions = new HashMap<>(); chromeOptions.put("mobileEmulation", mobileEmulation); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("mobileEmulation", mobileEmulation); ChromeDriver driver = new ChromeDriver(options);
driver.get("https://vars.get("main_page")"); WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath"))); driver.findElement(By.xpath("xpath")).click(); log.info(driver.getTitle());
JSR223 Sampler2 code for any page from the set of urls:
driver.get("https://${url}");
Error message: Response message:javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: driver for class
Problem: If I just copy all code from JSR223 Sampler1 to JSR223 Sampler2 and change destination url, urls are opening, but in unproper way - launching each time new browser instance, and I can't have realistic response time (for driver.get("url") only), because result provides time of Sampler work, which includes driver initialization, new browser instance start and it takes several seconds...
Could you please propose any ideas, how is possible to resolve this problem? To get all requests in 1 browser instance and to have realistic response time for all requests in JSR223 Sampler2 for browser.get("url") only? Will appreciate for any help.