IE驱动程序浏览器无法使用JSR223采样器工作-Jmeter

问题描述

我正在使用JSR223 Sampler使用IE浏览器并在UI上运行一些验证。

代码

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.webdriverwait;
import org.apache.jmeter.samplers.SampleResult;
File file = new File("webdriver.ie.driver","C:\Program Files\Internet Explorer\IEDriverServe");
System.setProperty("webdriver.ie.driver",file.getAbsolutePath());

WebDriver driver = new InternetExplorerDriver();

//System.setProperty("webdriver.ie.driver","C:\Users\Downloads\apache-jmeter-5.3\apache-jmeter-5.3\bin\IEDriverServer");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION,true);
WebDriver driver = new InternetExplorerDriver(capabilities)
def wait = new webdriverwait(driver,20);
driver.get('https://google.com/');
WDS.sampleResult.sampleStart();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@name='q']")));
WDS.sampleResult.sampleEnd();

错误: 2020-10-08 11:43:08,472 INFO o.a.j.e.StandardJMeterEngine:所有线程组已启动 2020-10-08 11:43:08,472信息o.a.j.t.JMeterThread:线程启动:IE 1-1 2020-10-08 11:43:08,479错误o.a.j.p.j.s.JSR223Sampler:JSR223脚本iecONfig中的问题,消息:javax.script.ScriptException:org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败: Script23.groovy:8:意外输入:'“ webdriver.ie.driver”,“'@第8行,第44列。 ew File(“ webdriver.ie.driver”,“ C:\ Progra ^

1个错误

javax.script.ScriptException:org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败: Script23.groovy:8:意外输入:'“ webdriver.ie.driver”,“'@第8行,第44列。

解决方法

您的脚本存在多个问题,即:

  1. File file = new File("webdriver.ie.driver","C:\Program Files\Internet Explorer\IEDriverServe");这个构造函数没有意义,请参见File javadoc以获得可能的选项
  2. 您两次声明WebDriver driver,第二次出现脚本失败
  3. 您需要将.exe添加到IEDriverServer

建议的代码更改:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.apache.jmeter.samplers.SampleResult;

System.setProperty("webdriver.ie.driver",'c:/full/path/to/IEDriverServer.exe');

DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION,true);
WebDriver driver = new InternetExplorerDriver(capabilities)
def wait = new WebDriverWait(driver,20);
driver.get('https://google.com/');
WDS.sampleResult.sampleStart();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@name='q']")));
WDS.sampleResult.sampleEnd();

更多信息:Internet Explorer Driver

是否有不将WebDriver SamplerInternetExplorer Driver Config一起使用的特定原因?如果您对Selenium和JMeter不太熟悉,它将更加容易