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

327 views Asked by At

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. In Selenium Automation, I used webdriverManger to download new driver every time https://www.toolsqa.com/selenium-webdriver/webdrivermanager/

JSR223 Sampler:

 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']")));
 
1

There are 1 answers

1
Dmitri T On

You can do the same in 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 in JMeter Classpath

  2. Restart JMeter to pick the .jar up

  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