【问题标题】:JMeter - client-side for mobile in SafariJMeter - Safari 中的移动客户端
【发布时间】:2020-09-08 15:41:50
【问题描述】:

我在 Win 上有 Safari 浏览器,上面安装了 webdriver,并遵循 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);

错误消息如下:

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

你能帮我找出我缺少的东西吗?

【问题讨论】:

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


    【解决方案1】:

    关于您收到的错误,您似乎在JMeter Classpath 下没有selenium-safari-driver,因此您需要下载适当的 .jar,将其放入 JMeter 安装的“lib”文件夹并重新启动JMeter 来取库。

    关于“Win 上的 Safari 浏览器”一节,您绝对确定这是您真正想做的事情吗? Safari EOL was in 2012 的 Windows 版本,我认为您不应该投资于 8 年前浏览器的自动化测试。

    展望未来,我认为这条线:

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

    应该看起来像:

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

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

    【讨论】:

    • 谢谢你,德米特里 T!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多