IE driver browser not working using JSR223 sampler - jmeter

111 views Asked by At

I am using JSR223 Sampler to use IE browser and run some validation on UI.

code:

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();

error : 2020-10-08 11:43:08,472 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started 2020-10-08 11:43:08,472 INFO o.a.j.t.JMeterThread: Thread started: IE 1-1 2020-10-08 11:43:08,479 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script iecONFIG, message: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script23.groovy: 8: Unexpected input: '"webdriver.ie.driver","' @ line 8, column 44. ew File("webdriver.ie.driver","C:\Progra ^

1 error

javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script23.groovy: 8: Unexpected input: '"webdriver.ie.driver","' @ line 8, column 44.

1

There are 1 answers

0
Dmitri T On

There are multiple problems with your script, i.e.:

  1. File file = new File("webdriver.ie.driver","C:\Program Files\Internet Explorer\IEDriverServe"); this constructor doesn't make sense, see File javadoc for possible options
  2. You declare WebDriver driver twice, on 2nd occurrence your script will fail
  3. You need to add .exe to IEDriverServer

Suggested code change:

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();

More information: Internet Explorer Driver

Is there any specific reason for not using WebDriver Sampler with InternetExplorer Driver Config? It will be way more easy given you're not too familiar with Selenium and JMeter