0

I have Safari browser on Win with installed webdriver on it and following code in JSR223 for Safari:

import org.openqa.selenium.safari.SafariOptions;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("userAgent", "vars.get("userAgent")");
Map<String, Object> safariOptions = new HashMap<>();
safariOptions.put("mobileEmulation", mobileEmulation);

SafariOptions safari = new SafariOptions();
options.setExperimentalOption("mobileEmulation", mobileEmulation);

SafariDriver driver = new SafariDriver(options);

driver.get("url");

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath")));
driver.findElement(By.xpath("xpath")).click();
  
vars.putObject("driver", driver);

Error messages are folllowing:

Response code:500
Response message:javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script19.groovy: 2: unable to resolve class org.openqa.selenium.safari.SafariOptions
 @ line 2, column 1.
   import org.openqa.selenium.safari.SafariOptions;
   ^

Script19.groovy: 3: unable to resolve class org.openqa.selenium.safari.SafariDriver
 @ line 3, column 1.
   import org.openqa.selenium.safari.SafariDriver;
   ^

2 errors

Could you please help me to find, what I'm missing?

Nadezhda T
  • 262
  • 8
  • 24

1 Answers1

1

With regards to the error you're getting it seems that you don't have selenium-safari-driver under JMeter Classpath so you need to download the appropriate .jar, drop it to "lib" folder of your JMeter installation and restart JMeter to pick the library up.

With regards to your "Safari browser on Win" stanza, are you absolutely sure this is something you really want to be doing? Windows version of Safari EOL was in 2012 and I don't think you should be investing into automated testing of 8-years-old browser.

Going forward I think this line:

mobileEmulation.put("userAgent", "vars.get("userAgent")");

should look like:

mobileEmulation.put("userAgent", vars.get("userAgent"));

I also fail to see a valid use case for JMeter there, if you need to simulate different browsers doing a performance test - you can easily send the relevant User-Agent header using HTTP Header Manager and conduct the load using normal JMeter's HTTP Request Samplers and if you're just creating automated tests - you don't need JMeter at all

Dmitri T
  • 159,985
  • 5
  • 83
  • 133