SELENIUM TO REST-ASSURED ADAPTER

Its been a long time and I am back after a very tight work schedule.

Earlier I have written an article about dealing with scenarios which involve both UI as well as API testing using Selenium and SoapUI.

Since that time, Rest Assured has been evolved as a most commonly used API Test Automation Framework and also it goes well with Java.

Last week I came across a Selenium Conference talk where I got to know about an interesting library called Selenium to Rest Assured Adapter.

This will simplify some of our automation tests, which needs automation at both UI and API levels.

In my previous posts, Selenium Webdriver – Get SessionID from a Web Application and SoapUI Get SessionID we have explored how to extract a session information from Selenium and passing it into our API Automated tests using SoapUI.

Now we are gonna explore the same using Rest Assured using the Selenium-To-RestAssured library.

For this, we need to download the latest jar file from Download Selenium-To-RestAssured Jar file and you have to add it to your classpath in your IDE – Eclipse or IntelliJ Idea.

If you are using Maven to manage the dependencies in your project, you can add the following to your pom.xml

<dependency>
    <groupId>uk.co.mwtestconsultancy</groupId>
    <artifactId>selenium-to-restassured</artifactId>
    <version>0.1</version>
    <scope>system</scope>
</dependency>

In selenium, to get a cookie from AUT, we use,

driver.manage().getCookieNamed("COOKIE NAME");

To use the cookie in rest assured tests, simply we have to create an instance for the CookieAdapter class and using the convertToRestAssured method like below. Then we can use the cookie in our RestAssured API Tests.

org.openqa.selenium.Cookie cookieToConvert = driver.manage().getCookieNamed("COOKIE NAME");
CookieAdapter cookieAdapter = new CookieAdapter();
io.restassured.http.Cookie adaptedCookie = cookieAdapter.convertToRestAssured(seleniumCookie);

given()
  .cookie(convertedCookie)
  .get("http://my-url");

The above snippet is extremely useful if we are automating API testing with an application that has a complex login process. We can log into the application via the browser using selenium, grab the necessary logged in Cookies from the browser, close the browser down, and then use the Cookies in our API Tests.

This Selenium-To-RestAssured is a dual way adapter and it converts cookie from RestAssured into a selenium cookie as well.

This can be used when you made an HTTP login request and you have to extract the response Cookie and store them in the browser.

Once we have the converted cookie we can add them to our browser like below.

io.restassured.http.Cookie cookieToConvert = response.getDetailedCookie("COOKIE NAME")
CookieAdapter cookieAdapter = new CookieAdapter();
org.openqa.selenium.Cookie convertedCookie = cookieAdapter.convertToSelenium(cookieToConvert);
driver.manage().addCookie(convertedCookie);
driver.navigate().refresh(); // We refresh the page so it reads the newly added cookies

This library is an open source and you can dig deeper into the source code here – Selenium-To-RestAssured-Github

Thanks to Mark Winteringham for this innovative creation.

Advertisements

State of Testing – 2018

For the 5th time, Practitest and TeaTime with Testers launch the State of testing survey. The State of Testing 2018 seeks to identify the existing characteristics, practices, and challenges facing the testing community in hopes to shed light and provoke a fruitful discussion towards improvement.

Each year the amount of participants has increased, and the final reports become even more valuable as a culminated reflection of testing trends, challenges, and characteristics.

The final report is translated into several languages and shared globally, further expanding the reach and impact this report has on all of us in the QA world.

You can help the test community by sharing your thoughts and view on the testing profession. Fill in the survey. Of course you’ll get the report for free, so you can learn how others look at the world.

The state for testing report of last year is available: State of Testing 2017.

Headless CHROME With Selenium Web Driver

Till Google Chrome 59, headless execution has been achieved using third party tools like PhantomJS or HTMLUnitDriver.

Earlier if you want to achieve headless test execution in Chrome, you had to use Xvfb (short for X virtual framebuffer). This is an in-memory display server for Linux which enables you to run graphical applications without a display.

But Google has released updates to chrome to achieve an inbuilt Headless test execution without using Xvfb or any other third party tools using a real browser – Chrome. This is available on Mac and Linux Os from Chrome 59. If you are using Windows, you need up update your Chrome version to 60 or above to achieve headless execution.

How to do Headless Test Execution: Its simple. All you have to do is add a chrome options argument before initializing your driver.


ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
WebDriver driver = new ChromeDriver(options);
driver.get("http://seleniumhq.org");

Check for broken links on your website using Postman

If you are using Postman for your API Testing, then you can also you the same to automatically crawl all the pages on our website and check every link for a healthy HTTP status code.

This can be achieved using 2 simple API requests in Postman.

First lets create a new Collection and an Environment in Postman, where you can specify

  • root_url
  • start_url

Specify the values for the root_url and start_url.

root_url as https://linkeshkannavelu.com/

start_url as https://linkeshkannavelu.com/category/software-testing/selenium/

Create a simple request with Get method and enter url as {{start_url}} and in the Tests tab enter the following code.

// set environment variables to default values
postman.setEnvironmentVariable('links', '[]');
postman.setEnvironmentVariable('url', postman.getEnvironmentVariable('start_url'));
postman.setEnvironmentVariable('index', -1);

 

Initialize

Create a second request – Get method and enter URL as {{url}} and in the Tests tab enter the following code.


// Tests and custom scripts can be written in JavaScript.

// get environment variables
var start_url = postman.getEnvironmentVariable('start_url');
var root_url = postman.getEnvironmentVariable('root_url');
var links = JSON.parse(postman.getEnvironmentVariable('links'));
var url = postman.getEnvironmentVariable('url');
var index = parseInt(postman.getEnvironmentVariable('index'));

// increment index counter to access links in array to check
index = index + 1;

// test if link works
if (responseCode.code &gt; 400) {
 console.log("This link is broken: ", url);
 tests["Link works"] = false;
} else {
 tests["Link works"] = true;
}

// if the current url includes the start_url, then this is an internal link and we should crawl it for more links
if (url.includes(start_url)) {

 // load the response body as HTML using cheerio, get the &lt;a&gt; tags
 var $ = cheerio.load(responseBody);

 $('a').each(function (index) {

 var link = $(this).attr('href');

 // add links to the links array if not already in there
 // if you have additional links you would like to exclude, for example, ads, you can add this criteria as well
 if (!links.includes(link)) {
 links.push(link);
 }
 });
}

// if we've gone through all the links, return early
if (links.length - 1 === index) {
 console.log('no more links to check');
 return;
}

// if link is a relative one, prepend with root_url
url = links[index]
if (! /^https?:\/\//.test(url)) {
 url = root_url + url;
}

// update environment variable values
postman.setEnvironmentVariable("links", JSON.stringify(links));
postman.setEnvironmentVariable("url", url);
postman.setEnvironmentVariable("index", index);

// continue calling the same request until all links are checked
postman.setNextRequest('Check URL');

Now Open “Runner” Select the Collection, Select the Environment and Click on Start Run Button.

Run

You can see Postman in action crawling all the links until there are no more links to check.

You can also simply download the Postman Collection and import it into your Postman.

Online Test Conf

SPRING ONLINE TEST CONF: The 100% online conference all about testing is happening on June 13-14, 2017.

This is an initiative to bring all the advantages of attending professional QA related conferences: personal learning, networking etc. without the shortcomings of scheduling, expenses and travel.

Attendance at OnlineTestConf is free and meant for anyone who sees themselves involved in testing and the testing community.

Why an Online Conference?

Not everyone can take time off their work, or pay the costs of physical conferences, and as much as we would like to our employers don’t always want to send us to learn new things and to improve our skills based on the knowledge of our peers.

Today we have the means (technologically and logistically) of organizing an event of this sort and share it with the community.  Something we could not really do even a couple of years ago.

The first conference was held in November 2016, was an amazing success. The feedback from that conference that drove them to make this a recurring event.

This upcoming OnlineTestConference will tackle hot topics such us: Agile team success, IoT, Mobile Testing, Testing AI and more, with a great line up of speakers such as: Alan Page, Paul Grizzaffi, Matt Heusser and Eran Kinsbruner to name a few.

Sign Up for this Conference and Save your seat

State of Testing 2017

 

Recently I have posted the State of Testing Survey 2017 survey conducted by PractiTest and now the survey results are out.

State of Testing survey 2017 has been biggest ever, with the participation from over 1600 professionals from 60 countries! We have 600+ more participants for this survey compared to the last year. This tells us a lot about the value this project is providing to the worldwide QA Community.

Following are some of the key takeaways from this report.

Respondents Demographics:
Indian Software Professionals contributed a lot for this survey. 23% of the participants are from India, and QA Professionals from Europe and Russia contributed to 34%. Most of them have the word “TEST” attached to their professional titles.

Where to Start?
If you or someone you know is starting his/her testing career, it is better to look for work in a smaller company or a startup firm, instead of looking for work in a bigger corporate organization.

Testing salaries around the world:
There is a jump in salaries compared to last year in a number of areas around the world, with the USA, Canada enjoying the largest gains in reported salary. On the other hand India, as a geographical area, showed similar salaries to previous years.

Testers report to a number of departments in the organization:
Again like last year, Its interesting to see that percentage of people from the Testing Function is reporting more to the Project Management and Development Manager than to the VP or Director of Quality.

Testers Approach towards Testing:
Almost all the testers prefers Exploratory / Session based testing than any other testing approaches. People also started trying out Mob Testing as one of the test approach. Mob testing is a group testing activity utilizing one computer and voices out the tacit knowledge in the group of individuals on shared tasks.

Additional Task for Testers:
Mostly we do documentation, managing test environments and requirement gathering. So when looking for tasks that will help you to boost your testing career, try focusing on helping the documentation gets created correctly and also on more technical tasks such as managing environments and taking part of the deployment and integration operations.

Source of Knowledge for Testers to learn:
Mostly QA People prefers Testing Books, Peer Mentoring and Online Communities and forums to keep themselves up-to date.

Skills – More importance to things like Automation, Scripting and Web Technologies and Security Testing. The most important skill is Communication Skill, which is even higher this year than ever before!

To Keep up to date – More people attending more interesting conferences than last year.

Adoption of New Tools: More than half of the testers introduce new tools into their practices.

Automation:
Overall the percentages of respondents using automation remains the same than as last year with 85% of the respondents.

What do Managers look for when hiring a tester?

  1. Problem Solving/Curiosity/Creativity
  2. Ability to think outside the box
  1. Technical knowledge
  1. Understanding of Agile
  1. Communication and listening Skills.
  2. Ability to adopt changes quickly.

 

Job Stability – The stabilization trend we started to see last year is only increasing, and so
people are less concerned in general about their job stability.

Predictions to the Future:
We see that most people want to stay in the testing arena within the next 5 years, although an important number of respondents want to work as Test Managers or Test Consultants.

The report also contains Plenty of good testing gatherings and open answers to Our ideal testing world in the future

To Read the full Report : Download State of Testing 2017 Report

Take part of the 2017 State of Testing Survey

The Largest Worldwide Testing Survey is back!

Following in tradition of the past three years on this QA Intelligence Blog and in collaboration with Tea Time with Testers, we are happy to announce the launch of the 2017 State of Testing Survey!

The survey is open throughout January, 2017 and you can take it right now – 
It only takes 10 min. or less to fill out  (we timed it) but will make a [testing] world of difference.

The State of Testing seeks to identify the existing characteristics, practices and challenges facing the testing community in hopes to shed light and provoke a fruitful discussion towards  improvement.

Last year was very successful with thousands of participants worldwide and the final report was translated into several languages and shared globally.
See the results from last year’s State of Testing Survey 2016.

With your help this year’s survey will be even bigger by reaching as many testers as possible around the world!

ANSWER SURVEY NOW

Other than taking the survey yourself, you are also invited to Share, Tweet, Post, Blog and brag about it with your professional network: