Currently Browsing

JUnit

Changing user agent with webdriver

Not so long ago we had to implement a test case where the user goes to a page with an “unknown” browser.
I had to spend some time to find out the proper configuration and made a small post about it to avoid doing it again.

All you have to do is to change the default user-agent. You can do this by instantiating a new ChromeOptions object and add you user agent as an argument.

Very Short example:

public class SampleTestClass  {

@Test
public void sampleTest(){

ChromeOptions chrome = new ChromeOptions();
chrome.addArguments("user-agent=YOUR_USER_AGENT");

WebDriver driver = new ChromeDriver(chrome);

// you can check your user-agent on this site
driver.get("https://www.whatismybrowser.com/");

driver.quit();
}

}

Reading test data from a CSV file using JUnit

It is recommended that we store the test data separately from the test scripts.
This data can be exported in CSV format. We can read CSV files using Java IO and utility classes.

csvDataPic

In this blog, we will read data from a CSV file and use this data to execute the test script.

Creating a data-driven test with JUnit

We can create data-driven Selenium WebDriver tests using the JUnit parameterization feature. This can be done by using the JUnit parameterized class runner.
In this blog, we will create a simple JUnit test case to test Facebook registration. We will specify the test data within our JUnit test case class. We will use various JUnit annotations to create a data-driven test.

Here is a sample code how to create a data-driven test using JUnit.
Do the following steps:

Open source testing tools

There are tons of applications available for testing, some of them are free(open source), some of them are commercial. This time I have prepared a list of useful and open source testing tools.

Selenium – Web app testing tool – http://seleniumhq.org/

Selenium is a suite of tools such as Selenium IDE, Selenium Remote Control and Selenium Grid used for testing web applications. Selenium IDE is an integrated development environment for Selenium scripts. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. It supports record and playback.

Browserstack integration with junit and webdriver

The purpose of this article is to show how easy is to integrate webdriver with architectures on the cloud, in this case with Browserstack.

For every new tool the first thing to do is to check out and examine the documentation.
The basic steps are very well documented, the examples and the thorough explanations give good impressions. I was able to make a simple test run on their architecture in a couple of minutes.
There is a section with an idea for parallelization, it is worth checking out, as you can get some ideas on improving your testbase. Link to their site is
http://www.browserstack.com/automate/java

Parameterized JUnit tests with Selenium WebDriver

With JUnit 4 we’re able to Parameterize the tests. Parameterized tests allow developers to run the same tests over and over again using different values.

Now we introduce the way to use the parameterized JUnit tests with Selenium WebDriver.

Here is the sample code, which opens the Google search page, searches three different phrases and checks the results.

How to integrate a JUnit4 – Webdriver test into JMeter

JMeter is an open source load testing tool, with many capabilities. One of the many interesting things which can be done is to integrate a webdriver test into a JMeter test suite.

Before start make sure that Java and JMeter properly installed, and the webdriver libraries are downloaded. You can download them from the following links:

The following step is to create a new project in Eclipse with a webdriver test. To keep it simple the test just hits the google.com page, and will check its title.

To create a project:
– Click File -> New- > Java Project

New Java Project

New Java Project

– Enter project name -> click Finish

New Java Project Name

New Java Project Name