Selenium JSR223采样器的WDS.sampleResult.sampleStart()
我正在使用JSR223采样器,我想开始计算url加载后的时间,因此我的代码如下: ** **根据脚本内容自动计算其持续时间,因此如果要测量查找输入所需的时间,必须选择以下选项:Selenium JSR223采样器的WDS.sampleResult.sampleStart(),selenium,selenium-webdriver,jmeter,jmeter-plugins,jsr233,Selenium,Selenium Webdriver,Jmeter,Jmeter Plugins,Jsr233,我正在使用JSR223采样器,我想开始计算url加载后的时间,因此我的代码如下: ** **根据脚本内容自动计算其持续时间,因此如果要测量查找输入所需的时间,必须选择以下选项: 创建另一个JSR223采样器,该采样器将打开所需页面并将WebDriver实例存储到类似的文件中: 第一个JSR223取样器: import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import o
- 第一个JSR223取样器:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.support.ui.WebDriverWait; System.setProperty("webdriver.gecko.driver","/Users/geckodriver"); FirefoxOptions options = new FirefoxOptions().setAcceptInsecureCerts(true); options.addArguments("--headless"); WebDriver driver = new FirefoxDriver(options); def wait = new WebDriverWait(driver, 20); driver.get('https://google.com/'); vars.putObject('driver', driver) vars.putObject('wait', wait)
import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; def driver = vars.getObject('driver') def wait = vars.getObject('wait') wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@name='q']")));
- 第二台JSR223取样器:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.support.ui.WebDriverWait; System.setProperty("webdriver.gecko.driver","/Users/geckodriver"); FirefoxOptions options = new FirefoxOptions().setAcceptInsecureCerts(true); options.addArguments("--headless"); WebDriver driver = new FirefoxDriver(options); def wait = new WebDriverWait(driver, 20); driver.get('https://google.com/'); vars.putObject('driver', driver) vars.putObject('wait', wait)
import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; def driver = vars.getObject('driver') def wait = vars.getObject('wait') wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@name='q']")));
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
System.setProperty("webdriver.gecko.driver","/Users/geckodriver");
FirefoxOptions options = new FirefoxOptions().setAcceptInsecureCerts(true);
options.addArguments("--headless");
WebDriver driver = new FirefoxDriver(options);
def wait = new WebDriverWait(driver, 20);
driver.get('https://google.com/');
def myResult = new org.apache.jmeter.samplers.SampleResult()
myResult.setSampleLabel('Locating element')
myResult.sampleStart()
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@name='q']")));
myResult.setResponseCodeOK()
myResult.setSuccessful(true)
myResult.sampleEnd()
SampleResult.addSubResult(myResult,false)
在这种情况下,您将得到如下结果:
查看以了解有关这些
vars
和SampleResult
速记的更多信息我基本上需要在driver.get()之后开始计算时间。我使用了函数sampleStart()/sampleEnd();最终出现以下错误:2020-10-07 16:08:11096错误o.a.j.p.j.s.JSR223采样器:JSR223脚本JSR223采样器中存在问题,消息:javax.script.ScriptException:groovy.lang.MissingMethodException:没有方法签名:org.codehaus.groovy.JSR223.GroovyScriptEngineImpl.sampleStart()适用于参数类型:()值:[]谢谢,@Dmitri,我相信选项2将更适合我当前的需求,但它再次抛出相同的错误。2020-10-07 18:58:21636信息o.a.j.e.StandardJMeterEngine:所有线程组都已启动2020-10-07 18:58:21636信息o.a.j.t.JMeterThread:线程已启动:FirefoxeBrowser 1-1 2020-10-07 18:58:25427错误o.a.j.s.SampleResult:调用sampleEnd两次java.lang.Throwable:org.apache.jmeter.samplers.samplesult.sampleEnd(samplesult.java:1145)[ApacheJMeter_core.jar:5.3]的org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:82)调用序列无效我复制了上面的脚本并运行了它。我切换到选项2,感谢您的帮助,它解决了我的问题。