Quantcast
Viewing all articles
Browse latest Browse all 22

BlazeMeter – Work with Selenium Webdriver

It was a long time we wrote about the BlazeMeter and during this time it comes more reliable, easy to use and there are also some new, great tools (Here you can find our latest post about BlazeMeter: Previous post about loadtesting with BlazeMeter).
Maybe the most important feature is that now you can use Selenium Webdriver to describe your test scenario. There are two ways of creating Selenium Webdriver test on BlazeMeter. You can write your own Selenium Webdriver script or you can record it. Unfortunately recording function was not published yet, so we will explain it in one future post (the link will be placed here).

Write your own Selenium Webdriver script

Basically it’s really the same when you are using JMeter with “Webdriver Set” plugin. If you are familiar with JMeter and javascript you won’t have problems using this tool, if you are not, don’t be afraid, it’s really simple. The big benefit is that you don’t need to set all kind of parameters up and to verify the connections between the machines (what you should with JMeter). Everything is just set up for you, and you need just to use it.
The script what you will write in BlazeMeter is based on JMeter’s WebDriver Sampler. BlazeMeter provides you “Labels” as segments of your test scenarios. This is a very good feature especially when you write large tests. We will introduce this with simple test scenario. Let’s say that we want to search for the most popular films and series rating website www.imdb.com and click on login. We can split this little scenario into two labels (Search for imdb, Login to imdb) like this:

Image may be NSFW.
Clik here to view.
Imdb labels

By clicking on the “{ EDIT CODE }” button, you can input your script.

Search for imdb:

 
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)

WDS.sampleResult.sampleStart() 
WDS.browser.get('https://duckduckgo.com/') 
var searchField = WDS.browser.findElement(pkg.By.id('search_form_input_homepage'))
searchField.sendKeys(['imdb'])
var button = WDS.browser.findElement(pkg.By.id('search_button_homepage'))
button.click()
WDS.sampleResult.sampleEnd()

Login to imdb:

var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)

WDS.sampleResult.sampleStart() 
//Click on the first result
var imdb = WDS.browser.findElement(pkg.By.cssSelector("a[href = 'http://www.imdb.com/'].result__a")).click();
//Click on the Login
var login = WDS.browser.findElement(pkg.By.id("nblogin")).click();
WDS.sampleResult.sampleEnd()


Almost every line of our code is related with Webdriver Sampler object called “WDS”. Basically it is the equivalent of Webdriver what we use in Java world. As you can see you have WDS.sampleResult.sampleStart() and WDS.sampleResult.sampleEnd() rows in every label. With those two lines of code you can capture sampler’s time and track it. It not necessary, but you will lose Load time if you skip these two rows. The other lines of code are pretty the same that you would write in any language using Selenium Webdriver.

On the right panel you can specify some parameters to your Load test. Here is the explanation from Blazemeter for each property

Image may be NSFW.
Clik here to view.
Imdb load scenario properties


  • Users: Select the number of users you want. The engines and thread are adjusted automatically according to this number.
  • Engines and Threads: If you don’t want these to be set automatically, you can manually set them by unchecking the ‘Users’ section. Note: Free-tier users don’t have access to engines and are limited to 50 threads.
  • Ramp Up: Select how fast you want the test to ramp up.
  • Iterations: Select the number of iterations in the test. Note: this is automatically set to infinitive
  • Duration: Set the full time duration that you want the test to run
  • Delay: Set the time delay between each page request.
  • Limit RPS: Set the number of requests per second you don’t want to go over.

Related link: BlazeMeter

By clicking on the Save button at right top corner, and then on the play button on the left top corner, you will start your Load test in the cloud. As you can see, it’s really simple and fast to write your script and test your website with various property values.
In near future we will write about the record function of BlazeMeter, which will simplify your code writing work.

Have a good day!


Viewing all articles
Browse latest Browse all 22

Trending Articles