Created
August 19, 2019 14:43
-
-
Save yarres/482c8c8f5fda0a7fe1fbfa3cf59867ae to your computer and use it in GitHub Desktop.
Basic chrome webdriver (Selenium) script for JMeter in Groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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