使用WDS(Web驱动程序采样器)-Javascript和jp@gc - Chrome驱动程序配置在jp@gc - Chrome驱动程序配置中,在选项下输入--remote-allow-origins=*,并在驱动程序下给予chromedriver exe文件的路径,如果是MAC,则不带.exe扩展名 enter image description here
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
var wait = new support_ui.WebDriverWait(WDS.browser, java.time.Duration.ofSeconds(120))
var jmeterVariables = org.apache.jmeter.threads.JMeterContextService.getContext().getVariables();
WDS.sampleResult.sampleStart()
WDS.browser.get(jmeterVariables.get('url'));
var userName = WDS.browser.findElement(pkg.By.xpath("//input[@class='amplify-input amplify-field-group__control' and @name='username']"));
userName.click();
userName.sendKeys([jmeterVariables.get('userName')]);
var password = WDS.browser.findElement(pkg.By.xpath("//input[@class='amplify-input amplify-field-group__control' and @name='password']"));
password.click();
password.sendKeys([jmeterVariables.get('password')]);
var signInbutton = WDS.browser.findElement(pkg.By.xpath("//button[@class='amplify-button amplify-button--primary amplify-field-group__control amplify-authenticator__font']"));
signInbutton.click();
wait.until(conditions.presenceOfElementLocated(pkg.By.cssSelector('.p-menuitem-link.router-link-active.router-link-active-exact')))
var dashboard=WDS.browser.findElement(pkg.By.cssSelector('.p-menuitem-link.router-link-active.router-link-active-exact')).getText()
WDS.log.info("Dashboard text " +dashboard);
var tokenStorageValue = WDS.browser.executeScript('return window.sessionStorage.getItem("auth-mod")')
WDS.log.info("Token storage value is " +tokenStorageValue);
var value = JSON.parse(tokenStorageValue);
jmeterVariables.put('token',value.userToken);
WDS.log.info("User Token Value is " +value.userToken);
WDS.sampleResult.sampleEnd()
2条答案
按热度按时间bwntbbo31#
这是一个简单的correlation问题,只需使用JMeter的HTTP请求采样器从浏览器(或其他应用程序)复制HTTP Requests的OAuth Flow,并使用合适的后处理器从响应中提取动态值,最有可能的是您需要JSON提取器或JSON JMESPath提取器
一些OAuth提供者提供Java客户端SDK,您可以使用JSR223 Sampler进行身份验证,并调用SDK提供的授权函数
ccrfmcuu2#
使用WDS(Web驱动程序采样器)-Javascript和jp@gc - Chrome驱动程序配置在jp@gc - Chrome驱动程序配置中,在选项下输入--remote-allow-origins=*,并在驱动程序下给予chromedriver exe文件的路径,如果是MAC,则不带.exe扩展名
enter image description here