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

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.

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:

Gear up for State of Testing 2017

Following in tradition of the past three years with the State of Testing survey, conducted in collaboration with TeaTime with Testers, the countdown starts for the State of Testing Survey 2017!

Last year was very successful with over 1,000 participants worldwide, and with your help we hope this year’s survey will be even bigger by reaching as many testers as we can around the world!

The survey 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.

The survey will go live during January, 2017. If you’d like to be informed when it is live, join this list:

Notify Me When the Survey is Live

You can also see the results of the last year – State of Testing Report 2016

Selenium 3.0 Officially Out Now

Yes. This is one of the major and stable release in the recent times since 2.0 got released around 5 years back.

What’s new we can expect: For users who are using WebDriver API’s this is gonna be just a drop in effortless replacement. But those who are using Selenium Grid may have to go through some minimal configuration changes.

In this version, they have removed the original Selenium Core implementation and replaced it with one backed by WebDriver. For people who are still using Selenium RC should have to undergo some maintenance because of this. This is the right time to migrate the code to WebDriver API’s.

Right from Selenium 3.0, all the major browser vendors are responsible for shipping their own implementation of WebDrivers for their browsers.

Starting with Safari-10, Apple started providing native support for WebDriver API’s. More details here – WebDriver Support in Safari 10

Google already started providing support for WebDriver API’s for Google Chrome using their ChromeDriver.

Even Microsoft when they came up with a new browser “EDGE” for Windows-10, they also came out with support for the WebDriver API’s – Microsoft WebDriver

Mozilla is doing major changes in the internals of Firefox browser to make it more stable and secure. So if you are using Firefox for your testing, you’ll need to use the GeckoDriver, which is an executable similar to the ChromeDriver. But Gecko is still in Alpha and you may have to face lot of issues with your automation w.r.t. Firefox.

The W3C specification for browser automation, based on Open Source WebDriver is still In-Progress and this is gonna reach “recommendation” status.

What you are waiting for? Just go and download the latest from Seleniumhq Downloads

State of Testing 2016

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

State of Testing survey 2016 has been biggest ever, with the participation from over 1,000 professionals from 61 countries!

Following are some of the key takeaways from this report.

Testers report to a number of departments in the organization:
Its interesting to see that percentage of people submitting the testing function reports to Project Management and to the 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.

What do testers do with all their (spare) time?
Mostly we do documentation and managing the test environments.

Testing Documentation – Mind Maps are becoming very popular among the testers compared to high level test plans and other documentation techniques.

Is every second tester a test lead…?
There is a similar number of Test Leads, Managers and Directors, as there are Test Analysts and Test Engineers.
We have just as many leads as we have testers. But where are they leading us to? 🙂

QA:Scrum Master: Also a large number of respondents who are, in addition to working as testers, also fill the role of Scrum Master in their teams.

Skills – More importance to things like Mobile Technologies, Web Technologies, Agile Methodologies and Customer Facing Skills. And the most important skill is Communication Skill, which is even higher this year than ever before!

To Keep up to date – More and more testers are turning to social media in order to keep up to date with their testing knowledge!

Test Team Challenges – Hiring is Extremely Challenging and Training is also Challenging.

What do Managers look for when hiring a tester?

  1. Ability to think outside the box.
  2. Passion ate about testing
  3. Scripting knowledge
  4. Understanding of Agile
  5. Understanding of the relevant technologies
  6. Good writing & communication skills

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.

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.

The report also contains Plenty of good testing gatherings, not only the very large conferences.

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

Angry Testers

I recently came across a question in Quora that “What makes a Tester Angry?”

I just recalled some of my conversations with my colleagues in the last 8 years and picked up some direct statements from them which really made me angry during the initial days of my career.

Of course I am used to it nowadays and I simply smile at them if I don’t have an answer. Just read and have fun.

####################################################

Can you hurry up and finish testing soon? We’re under a very tight deadline.
I didn’t have time to read your bug report. Give me the 5-second version.

You won’t break it.
Oh, that’s not a problem. Let’s leave it.
How much time does it take to test?
Yes its a bug but don’t create issue for it, i will fix it right away
Its not a Bug.
Its not there in our Requirement.
I am not able to reproduce this issue in my machine.
Its not a Bug. Its a upcoming feature.

You need to think outside the box
You can find out for yourself
That’s not a bug, that’s a “nice” to have
Your computer is too slow.
End users won’t do such actions.
This is not in our acceptance criteria.
No user would ever do that.

But It works in production.
You should not test that.
You should not test in that way.
Maybe you can test in this way.
Our developers will give you some proper testing instructions. You just need to follow those.

Why you didn’t found out this defect in the earlier release?
How did you missed that defect?
Maybe I should talk to your QA Lead/Manager about this.
You need to setup your own test environment.
This must be a data issue.
Could you tried this after clearing cache and cookies?
Oh, this is what you are doing?
Have you tried after rebooting your machine?
Performance is not a big deal now. All we need is just a working product.

This is not Blocker/Critical. You have got some work around.
I need the test report in just 3 hours.
Oh, we got only 2 days? I will put one more resource from that project so that it will be completed in just one day.

That’s a part of your Role. That’s why we hired a Senior.
We can close this defect now to release the Product.
Here is your build. Start testing it right away. Enjoy your weekend. [On a Friday evening]

 

####################################################
And the all time favorites are where all the QA hates to the core,
But it works on my machine!

Oh, Wait. I just quoted some statements that made me angry. But still there are couple of statements that will make you to loose your temper the moment you hear.

It’s a complete waste of our testing time.
Do we really need a QA?

Inspired from – Angry Testers