Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Now that Jmeter has a webdriver sampler, is there anything that regular selenium can do to test a UI, that Jmeter still can't?

For example, I use Selenium in Java to do things like getting html attributes of an element element.getAttribute("title");

and waiting for conditions up to a maximum time

Wait<WebDriver> customWait = new FluentWait<WebDriver>(driver)
           .withTimeout(15L, TimeUnit.SECONDS)
           .pollingEvery(1, TimeUnit.SECONDS)
           .ignoring(NoSuchElementException.class);

switching between windows, and more.

I've seen some example code for the Webdriver sampler here: http://jmeter-plugins.org/wiki/WebDriverSampler/?utm_source=jpgc&utm_medium=link&utm_campaign=WebDriverSampler

But it doesn't show how to accomplish tasks like the above - only how to send keys and click on elements.I can't find any documentation online regarding how to use the Webdriver sample to accomplish tasks like the above and others.

Is it possible to do these using Jmeter's webdriver sampler?

Besides these examples, what are other things you can do in Selenium, which Jmeter's webdriver sampler can't yet do?

share|improve this question

3 Answers 3

Imagine a jackhammer with a Phillips-head screwdriver welded onto the handle. You could, in theory, use this modified jackhammer for screwing things together, but you probably wouldn't want to.

JMeter is a tool for performance testing. Selenium is a tool for functional testing. I talk about the differences between the two kinds of testing here.

share|improve this answer

Agree with @user246 JMeter is for load testing and recommended to use WebDriver in JMeter paralel with load tests for Ajax applications. But if you run WebDriver sampler in "Once Only Controller" you are fine. Here you can find article about JMeter WebDriver sampler.

share|improve this answer
    
I'm not sure this is relevant to the original question. The article you linked talks about using Selenium with JMeter, not using JMeter instead of Selenium. –  Kate Paulk Sep 24 '13 at 11:43
    
@KatePaulk Pat Meeker, asked "Is it possible to do these using Jmeter's webdriver sampler?" and link is the answer to his question. –  Bob Meliev Sep 25 '13 at 6:04
    
I think everyone would be better served if you extracted the relevant portions of the link (helps to prevent link rot) and then the answer can be evaluated strictly on its content as opposed to outsourcing that content. –  corsiKa 2 days ago

I believe that answers to your questions and more are in the The WebDriver Sampler: Your Top 10 Questions Answered guide.

In particular:

  1. Get data from WebDriver Sampler into JMeter variable:

    You can pass data to JMeter via WDS.sampleResult.setResponseHeaders() method (body and message are being overwritten by the WebDriver Sampler). Once you set the headers you can fetch the data via Regular Expression Extractor. If you need to pass multiple variables headers can be split via \n delimiter like

    If you need to extract multiple values and more headers, you can use the “\n” delimiter. Here’s an example of how this is used correctly:

    WDS.sampleResult.setResponseHeaders('Header_1_Name: Header_1_Value' + '\n' + 'Header_2_Name: Header_2_Value')
    
  2. In order to wait for some element to appear in DOM use the following approach:

    var pkg = JavaImporter(org.openqa.selenium)
    var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
    var conditions = org.openqa.selenium.support.ui.ExpectedConditions
    var wait=new support_ui.WebDriverWait(WDS.browser, 10)
    
    WDS.sampleResult.sampleStart()
    WDS.browser.get('http://example.com')
    wait.until(conditions.presenceOfElementLocated(pkg.By.linkText('More information...')))
    var element=WDS.browser.findElement(pkg.By.linkText("More information..."))
    element.click()
    WDS.sampleResult.sampleEnd()
    
  3. To switch between windows refer to the following code snippet

    WDS.sampleResult.sampleStart()
    WDS.browser.get('http://example.com')
    WDS.browser.executeScript('window.open("http://google.com");')
    var handles = WDS.browser.getWindowHandles()
    var iterator = handles.iterator()
    var counter = 1;
    while (iterator.hasNext())
    {
       var handle = iterator.next()
       WDS.browser.switchTo().window(handle)
       WDS.log.info('Window ' + counter + ' title = ' + WDS.browser.getTitle())
       counter++;
    }
    WDS.sampleResult.sampleEnd()
    

Hope this helps.

share|improve this answer
1  
Answers with only a link are discouraged because if the link moves or vanishes, your answer is no longer useful. Please try to summarize what information can be found at the link –  Yamikuronue Sep 22 at 17:22
    
Corrected the answer according to your comment, thanks. –  Dmitri T Sep 23 at 7:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.