JMeter WebDriver Sampler不起作用,并且没有头

问题描述

我正在使用jp @ gc-Firefox驱动程序配置插件来命中某些URL并在UI中声明某些元素。 但是我无法启动firefox驱动程序,因为我看不到启用将firefox作为无头浏览器运行的选项。

JP @ GC-WebDriver采样器:

导入org.openqa.selenium.By; 导入org.openqa.selenium.support.ui.ExpectedConditions;导入org.openqa.selenium.support.ui.webdriverwait

def wait =新的webdriverwait(WDS.browser,5000);

WDS.sampleResult.sampleStart(); WDS.browser.get('https://google.com/'); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“ .// input [@ name ='q']”))));; WDS.sampleResult.sampleEnd()

解决方法

如何在jp @ gc中选中Headless框-Firefox Driver Config

enter image description here


请注意,您始终可以通过使用JSR223 Test Elements and Groovy language实现您想要/需要的任何东西来绕过JMeter的任何限制,启动无头Firefox的示例代码将类似于:

System.setProperty('webdriver.gecko.driver','c:/apps/webdriver/geckodriver.exe')
def options = new org.openqa.selenium.firefox.FirefoxOptions()
options.addArguments('--headless')
def driver = new org.openqa.selenium.firefox.FirefoxDriver(options)
driver.get('http://example.com')
log.info('Current page title: ' + driver.getTitle())
driver.quit()

有关JMeter中Groovy脚本的更多信息:Apache Groovy - Why and How You Should Use It