Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic chrome webdriver (Selenium) script for JMeter in Groovy
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import static org.openqa.selenium.support.ui.ExpectedConditions.*
import org.openqa.selenium.support.ui.*;
import openqa.selenium.OutputType.*;
// Required to start counting time which will get reported at the end of this code.
WDS.sampleResult.sampleStart();
def service = new ChromeDriverService.Builder().build();
service.start();
DesiredCapabilities capabilities = new DesiredCapabilities();
def driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
driver.get("https://myTestedUrl.com");
Thread.sleep(1000);
// Login
driver.findElementById('username').sendKeys('myusername');
driver.findElementById('password').sendKeys('mypassword');
Thread.sleep(500);
driver.findElementById('submit').click();
Thread.sleep(1500);
// Css selector
driver.findElement(By.cssSelector("button")).click();
Thread.sleep(1550);
// End the test sampler, capturing length of time for the test.
WDS.sampleResult.sampleEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment