简体   繁体   English

如何通过 jenkins - jmeter webdriver 脚本管理网络驱动程序?

[英]How to manage web drivers via jenkins - jmeter webdriver script?

I have to build JMeter script using JSR223 Sample for chrome, I was wondering if there is a way that I can configure path in the script so that I don't need to host drivers in Jenkins.我必须使用 JSR223 Sample for chrome 构建 JMeter 脚本,我想知道是否有一种方法可以在脚本中配置路径,这样我就不需要在 Jenkins 中托管驱动程序。 In Selenium Automation, I used webdriverManger to download new driver every time https://www.toolsqa.com/selenium-webdriver/webdrivermanager/在Selenium Automation中,我每次都使用webdriverManger下载新驱动https://www.toolsqa.com/selenium-webdriver/webdrivermanager/

JSR223 Sampler: JSR223 采样器:

 import org.openqa.selenium.By;
 import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    **System.setProperty("webdriver.gecko.driver","/Users/geckodriver");**
    FirefoxOptions options = new FirefoxOptions().setAcceptInsecureCerts(true);
    WebDriver driver = new FirefoxDriver(options);
    def wait = new WebDriverWait(driver, 20);
    driver.get('https://google.com/');
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@name='q']")));
 

You can do the same in JMeter:你可以在 JMeter 中做同样的事情:

  1. Download WebDriverManager "fat" jar from the releases page and drop it to "lib" folder of your JMeter installation or at any other place inJMeter Classpath发布页面下载 WebDriverManager "fat" jar并将其放到 JMeter 安装的 "lib" 文件夹或JMeter Classpath 中的任何其他位置

  2. Restart JMeter to pick the .jar up重新启动 JMeter 以选择 .jar

  3. Replace your更换你的

    **System.setProperty("webdriver.gecko.driver","/Users/geckodriver");**

    with

     io.github.bonigarcia.wdm.WebDriverManager.firefoxdriver().setup()
  4. Enjoy享受

More information and another trick you can play: How to Reuse Your JMeter Code with JAR Files and Save Time您可以使用更多信息和另一个技巧: 如何使用 JAR 文件重用 JMeter 代码并节省时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM