JMeter-Safari中的移动设备客户端

时间:2020-09-08 15:41:50

标签: jmeter mobile-safari performance-testing client-side jsr223

我在Win上安装了Safari浏览器,并安装了网络驱动程序,并遵循Safari的JSR223中的代码:

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

错误消息如下:

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

您能帮我找到我所缺少的吗?

1 个答案:

答案 0 :(得分:1)

关于该错误,您似乎在selenium-safari-driver下没有JMeter Classpath,因此需要下载相应的.jar,将其拖放到您的“ lib”文件夹中安装JMeter并重新启动JMeter以选择库。

关于“ Win上的Safari浏览器”节,您绝对确定要执行此操作吗? Windows版本的Safari EOL was in 2012,我认为您不应该投资于8岁浏览器的自动化测试。

展望未来,我认为这句话:

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

应如下所示:

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

如果您需要模拟不同的浏览器进行性能测试,我也看不到JMeter的有效用例-您可以使用User-Agent轻松发送相关的HTTP Header Manager标头并进行加载使用普通的JMeter的HTTP Request采样器,并且如果您只是创建自动化测试-您根本不需要JMeter