Can any one show how to extract the local storage value in the jmeter.
var pkg = JavaImporter(org.openqa.selenium, org.openqa.selenium.support.ui);
var jmeterVariables = org.apache.jmeter.threads.JMeterContextService.getContext().getVariables();
WDS.sampleResult.sampleStart();
WDS.sampleResult.getLatency();
WDS.browser.manage().timeouts().pageLoadTimeout(60, java.util.concurrent.TimeUnit.SECONDS);
WDS.log.info("Sample started");
try {
WDS.browser.get(jmeterVariables.get('url'));
var userName = WDS.browser.findElement(pkg.By.xpath("//input[@id='username']"));
userName.sendKeys(jmeterVariables.get('userName'));
var password = WDS.browser.findElement(pkg.By.xpath("//input[@id='password']"));
password.sendKeys(jmeterVariables.get('Password'));
var loginButton = WDS.browser.findElement(pkg.By.xpath("//button[@type='submit' and contains(@class, 'login-button')]"));
loginButton.click();
WDS.browser.get(jmeterVariables.get('url1'));
WDS.log.info("User logged in successfully");
// Wait for the page to load for 30-40 seconds
var wait = new pkg.WebDriverWait(WDS.browser, 40); // Adjust the timeout as needed
var element = wait.until(pkg.ExpectedConditions.visibilityOfElementLocated(pkg.By.xpath("//some/xpath")));
// Perform actions with the element after it's located
// element.click(); // Example action after element is located
// Extract refresh token from local storage
var tokenStorageValue;
allStorage();
var value = JSON.parse(tokenStorageValue);
jmeterVariables.put('refresh_Token', value.secret);
WDS.sampleResult.sampleEnd();
} catch (e) {
WDS.log.error("Error occurred: " + e);
} finally {
// Ensure to quit the browser after execution
WDS.browser.quit();
}
function allStorage() {
for (var key = 0; key <= WDS.browser.executeScript("return window.localStorage.length"); key++) {
var keyName = WDS.browser.executeScript("return window.localStorage.key(" + key + ")");
if (keyName.indexOf('refreshtoken') > 0) {
tokenStorageValue = WDS.browser.executeScript("return window.localStorage.getItem('" + keyName + "')");
break;
}
}
}
Here am facing the issue in the jmeter log as
2024-07-13 01:40:03,098 ERROR c.g.j.p.w.s.WebDriverSampler: Error occurred: TypeError: Can not create new object with constructor org.openqa.selenium.support.ui.WebDriverWait with the passed arguments; they do not match any of its method signatures.
Now While am trying to ask the browser to wait for 40 seconds to extract the user id from the local storage. I see the above error in the log.