Search code examples
javascriptjmeterselenium-chromedriverchrome-web-driver

JMeter WebDriver Sampler: working with Firefox but browser does not open when using Chrome


I have been able to successfully run a (javascript) test script using the WebDriver Sampler in JMeter with the Firefox Driver Config. I now want to use the JMeter Chrome Driver Config to run the same test in Chrome.

I know that the Chrome Driver that I have installed on my PC is working as I have successfully used it to run other (non-JMeter) tests. The path to the Chrome Driver is also definitely correct.

My site does not use a proxy so I have selected "No Proxy" under the "Proxy" tab of the Chrome Driver Config.

Problem: When I click "Run" in JMeter with the Firefox Driver Config disabled and the Chrome Driver Config enabled, nothing happens (browser does not open, test quickly ends and nothing is recorded in the "View Results Tree" listener).

I am using version 3.1 of JMeter, version 60.0.3112.101 of Chrome and version 2.31 of ChromeDriver.

My code looks like this in case that helps:

var pkg = JavaImporter(org.openqa.selenium); //WebDriver classes
var pfg = JavaImporter(org.openqa.selenium.Keys); //WebDriver classes
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); 
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);

var username = WDS.args[0];
var password = WDS.args[1];
var docNo = WDS.args[2];

WDS.sampleResult.sampleStart(); 
WDS.sampleResult.getLatency();
WDS.log.info("Sample started");

WDS.browser.get('blah blah blah');

var usernameBox = WDS.browser.findElement(pkg.By.id('TextBoxCustomer')); 
var passwordBox = WDS.browser.findElement(pkg.By.id('PIN')); 
var loginBtn = WDS.browser.findElement(pkg.By.id('btnLogin')); 

usernameBox.click(); //click on User ID textbox
usernameBox.sendKeys([username]); //enter User ID
passwordBox.click(); //click on Password textbox
passwordBox.sendKeys([password]); //enter password
loginBtn.click(); //click Login button
java.lang.Thread.sleep(5000);

//Check that "Home" page has been reached by verifying presence of "News         
Header"
try {
    wait.until(conditions.presenceOfElementLocated(pkg.By.id('ct100_CP1_ctlNewsMessa
    geList_NewsHeader')));
} 
catch (Exception) {
    WDS.sampleResult.sampleEnd();
    WDS.sampleResult.setSuccessful(false);
}

//Navigate to "Invoice PDFs" screen
var accountMnu = WDS.browser.findElement(pkg.By.xpath("//[contains(text(),'Account')]"));
accountMnu.click();
var InvPDFSubMnu = WDS.browser.findElement(pkg.By.xpath("//*
[contains(text(),'Invoice PDFs')]"));
InvPDFSubMnu.click();
java.lang.Thread.sleep(5000);
try {
    wait.until(conditions.presenceOfElementLocated(pkg.By.id('ctl00_CP1_tbDocNo')));
} 
catch (Exception) {
    WDS.sampleResult.sampleEnd();
    WDS.sampleResult.setSuccessful(false);
}

//Enter document number
java.lang.Thread.sleep(5000);
var docNoBox = WDS.browser.findElement(pkg.By.id('ctl00_CP1_tbDocNo')); 
docNoBox.click(); //click on "Doc Bo." textbox
docNoBox.sendKeys([docNo]); //enter Doc No.
java.lang.Thread.sleep(5000);


//Retrieve document with specified document number
var retrieveBtn = WDS.browser.findElement(pkg.By.id('ctl00_CP1_btnRetrieve')); 
retrieveBtn.click();

try {
    wait.until(conditions.presenceOfElementLocated(pkg.By.xpath("//*[contains(text(),'download')]")));
} 
catch (Exception) {
    WDS.sampleResult.sampleEnd();
    WDS.sampleResult.setSuccessful(false);
}
 java.lang.Thread.sleep(5000);

//Click on "download" button
var downloadBtn = WDS.browser.findElement(pkg.By.xpath("//*[contains(text(),'download')]")); 
downloadBtn.click();

WDS.sampleResult.sampleEnd();

Solution

  • It seems that the solution was that in the "Path to Chrome Driver" (under the "Chrome" tab of the "jp@gc - Chrome Driver Config" element) I needed to end the "path" with "\chromedriver.exe".