1

I am using java as scripting language in JMeter 3.0 and jmeter-plugins-webdriver-1.4.0.jar. When I run my script which is supposed to open a browser and go to gmail.com, and sign in. I get the following error:

ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: In file: inline evaluation of: ``import org.openqa.selenium; 

import org.openqa.selenium.support.ui;  WDS.sampleRe . . . 

Encountered "WDS" at line 5, column 1.in inline evaluation of: 
import org.openqa.selenium; 

import org.openqa.selenium.support.ui;  

WDS.sampleRe . . . '' at line number 5 

ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: In file: inline evaluation of: 

import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*;  import o . . . '' Encountered "WebElement" at line 9, column 1.
     in inline evaluation of: 

import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*; 

 import o . . .  at line number 9

Here are my 2 scripts :

Open Browser:

import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;


WDS.sampleResult.sampleStart()
WDS.browser.get('http://gmail.com')
// login details
WDS.sampleResult.sampleEnd()

LogIn:

import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;


WDS.sampleResult.sampleStart()


WebElement userIdElement = WDS.browser.findElement(By.id(("username"));
userIdElement.sendKeys('${email}');
WebElement pwdElement = WDS.browser.findElement(By.id("password"));
pwdElement.sendKeys('${pwd}');
WebElement signIn = WDS.browser.findElement(By.id("login"))
signIn.click();
// login details
WDS.sampleResult.sampleEnd()
Shaig Khaligli
  • 4,955
  • 5
  • 22
  • 32

3 Answers3

3

There are multiple problems with your test

  1. Missing semicolons
  2. Unbalanced parentheses
  3. Given Java language you cannot access JMeter Variables like ${email}
  4. Invalid WebElement IDs

Here is example fixed code:

  • Open Browser

    import org.openqa.selenium.*;
    import org.openqa.selenium.support.ui.*;
    
    
    WDS.sampleResult.sampleStart();
    WDS.browser.get("http://gmail.com");
    // login details
    WDS.sampleResult.sampleEnd();
    
  • Login

    import org.apache.jmeter.threads.JMeterContextService;
    import org.apache.jmeter.threads.JMeterVariables;
    
    
    import org.openqa.selenium.*;
    import org.openqa.selenium.support.ui.*;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    
    
    WDS.sampleResult.sampleStart();
    JMeterVariables vars = JMeterContextService.getContext().getVariables();
    
    
    WebElement userIdElement = WDS.browser.findElement(By.id("Email"));
    userIdElement.sendKeys(new String[]{vars.get("email")});
    WebElement nextButton = WDS.browser.findElement(By.id("next"));
    nextButton.click();
    WebElement pwdElement = WDS.browser.findElement(By.id("Passwd"));
    pwdElement.sendKeys(new String[]{vars.get("pwd")});
    WebElement signIn = WDS.browser.findElement(By.id("signIn"));
    signIn.click();
    // login details
    WDS.sampleResult.sampleEnd()
    

Also consider using Explicit Waits as it is quite unlikely your that your browser loads pages immediately and hence you'll get tons of NoSuchElementExceptions

See The WebDriver Sampler: Your Top 10 Questions Answered guide for more information on using the WebDriver Sampler in JMeter tests.

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

I have used this sendKeys method Eg: WDS.browser.findElement(By.id("j_username")).sendKeys(new String[]{vars.get("abcd")});

so, instead of passing abcd, it is passing NULL

0

I used sendKeys method Example:

WDS.browser.findElement(By.id("j_username")).sendKeys( new String[] { "abcd" } );

doing so resolved the passing of NULL.

vimuth
  • 5,064
  • 33
  • 79
  • 116
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 15 '22 at 01:24