Top 5 blog articles in 2015

The following articles had the most views from the readers of this blog in 2015.


How To Make Webdriver Scripts Faster

Collection of tips for improving the speed of Selenium WebDriver scripts





Create Selenium HTML Reports With Allure Framework

How-To article about generating HTML reports for Selenium scripts





How Much Java Do I Need To Learn For Selenium

For test automation, you need as much Java knowledge and skills as possible.
The Java skills are never enough.




How Does Selenium Webdriver Work

If you are curious how Selenium WebDriver works and interacts with the browser, this is what you should read.





Use Html Parser Libraries For Test Automation

There are cases when WebDriver is not the best option for automation.
Try checking that no link from a web page is broken with WebDriver.

HTML parsing libraries offer great speed, simple and powerful APIs.




Tried learning test automation by yourself without success?

I can teach you programming and test automation in 10 private lessons.

Learn with your own tutor and on your pace.

Email me at alex@alexsiminiuc.com for details.

The end of the QA manager?

Before going into the article, let me tell you a bit about myself.

I was QA manager between 2006 and 2012.

In 2006, my employer did not have a test team so I volunteered to create it.

Being a QA manager was an amazing opportunity.

It allowed me to learn many things that otherwise would be inaccessible to me.

In 2012,  I decided to work only non-management, hands-on testing jobs.

How is QA management doing these days?





MANY CHANGES HAVE BEEN HAPPENING RECENTLY IN THE MANAGEMENT FIELD

Companies make their management structures flat, with less levels between employees and top management.

Flat structures means less middle managers.

Or no managers in some cases.

See this article about management changes at Zappos (Amazon owned) as an example.




Some management tasks are automated.

Time planning and vacation management are being done through web applications.

The information dissemination to employees is facilitated by email, newsletter and web portals.

Planning, control and evaluation activities are distributed to non-manager employees.

All of these contribute to less activities allocated to managers.





In many cases, managers are seen as not very useful because they only manage.

They dont do anything else than management.

While this is not correct every time, it still leads to the perception that managers are expendable.

So when companies restructure, managers are impacted heavily.




WHAT DOES THIS MEAN FOR QA MANAGERS?

QA managers are managers too.

All changes already mentioned apply to them.

But recent changes in software development pressure even more the QA managers.

Applications are being developed, tested and deployed fast using incremental and iterative processes such as Agile.





AGILE TEAMS INCLUDE TESTERS AND QA ANALYSTS

The QA manager role makes sense when a QA department exists for providing services to development teams.

When using Agile instead of Waterfall-like processes, testers and QA analysts move from the QA team to development teams.

The testing is no longer done after all features are developed.

Code changes need to be tested fast even if application features are incomplete.

The testing is also less scripted and becomes exploratory and session-based.







The testers are no longer coordinated by the QA manager.

The scrum master and development manager take charge.



COMPANIES ARE USING LESS TESTERS OR NO TESTERS AT ALL

Some companies do their development without having testers at all.

Facebook for example.

Or Hootsuite who has 1 manual tester for more then 100 developers.

The developers create the code and unit test it.

They may even do the test automation for the new features.





After the developers finish their development and testing, business users do the integration testing for the product.

Think about it.

Why would a company need testers if the developers do unit testing and test automation and the business users look at the product as well?





LESS QA PROCESS ARE USED AND NEEDED

One of the QA manager's most important responsibilities is to set up and improve processes.

Agile does not put a lot of focus on having the best documentation.

It does not focus too much on processes either.

What is important however is having self-organizing teams of motivated and very capable individuals.




SO WHAT WILL HAPPEN WITH QA MANAGERS?

In companies that continue to use Waterfall development processes, QA managers will still survive, especially the good ones.

In companies that uses Agile or other fast iterative development processes, QA managers will become rare.

The more Agile becomes prominent, the less QA departments will be around.

Less QA departments, less QA managers.



WILL ALL QA MANAGERS BE IMPACTED EQUALLY?

There are 2 types of QA managers.

The first type is the "just-manage" QA manager.

He is highly skilled at management and very capable of managing testers.

But he does not know much about testing and technology.

His technical and development skills are very limited.




The second type of QA manager is very-hands on.

This is the "t-shape" type of QA manager.

He does management part time, is technical and development oriented.

He has broad skills (test automation, performance testing, web service testing), some of them very specialized.





I believe that many "just-manage" managers will disappear.


Their responsibilities will be taken over by development managers, hands-on QA leads and testers.

Agile does not require many managers, especially ones with no other skills than management.


The "t-shape" managers will survive.

When their QA management is no longer needed, they will join development teams as hands-on QA leads or senior testers.



WILL TESTERS AND QA ANALYSTS BE IMPACTED?

They will.

Having less managers will put more pressure on employees.

They have to do their work with less attention, less mentoring, less feedback.

No one will be around to tell testers what to do and how to do it.






With no managers around, testers should learn self management and become more autonomous.

They should learn to take charge on their goals and problems.

WHAT IS HAPPENING WITH MANAGERS IN OTHER INDUSTRIES?

Lets see what happens in the industry in recent years in Canada:

The number of managers is going down in every industry:

  • Walmart Canada cut 200 head office jobs in 2014.
  • After Tim Hortons merged with Burger King, it axed 40% of its middle managers.
  • When Rogers Communications restructured its business recently, it let go several hundred middle managers
  • It was a similar story at Bell Canada, when the new CEO cut 2500 management jobs.


In 1995, 10.4% of all jobs were in management positions.

In 2015, only 7.8%  are management jobs



NEXT

6 signs that your manual testing career is in danger
How to learn test automation from zero

6 warning signs that your manual testing career is in danger

Do you ever worry about the future of your testing career?

Are you asking yourself sometimes if you are doing the right things?

Do you have a feeling  that you should make changes in your testing job?

If the future of your testing career worries you, there are signs that can tell you if your job is in danger.



1. YOU HAVE DIFFICULTY FINDING A NEW JOB

The first 6 months in a new testing job are exciting.

You learn new things about the company, team, development process, applications to be tested.

But as time goes, the newness of things starts going away.

After a while, you know your job so well that you can do it with your eyes closed.

You decide then that it is time to move on.

So you try to find another job.
And try and try again.




Sometimes you get invited to interviews, other times you dont.

A few months pass since you started to look for a new job and you are still looking.

Not finding fast a new job is a signal that something is not going well with your testing career.

Why cant you find another job?

Maybe because ............



2. SCRIPTED TESTING IS ALL YOU KNOW

Most testers are manual testers.

This is their speciality:
to execute manual functional testing for web sites, mobile apps, windows applications.

Manual testing was very popular until recently because:
  • users demanded high application quality so companies hired manual testers 
  • the SDLC process was a waterfall variation with phases that were more or less distinct and sequential (gather requirements, development, testing, release)
  • developers did not do much testing so testing belonged to manual testers 

Testers created detailed test cases while the developers created the code.

After the development phase ended, the testers executed the test cases and reported their discoveries to the development team.




The present and future of manual testing changed.

Due to the Agile processes, the focus is now to develop features quickly and deploy them frequently. 

Creating requirements, development and testing happen fast and sometimes in parallel.

There is no time for putting together detailed requirements and test cases.

The tester needs to be able to learn fast the new features, create a high level testing checklist, test and report the issues.

And do this fast and continuously.

If your testing is still based on detailed test cases, this is another signal that you may have problems in your future career.

But having only functional testing in your toolbox may still be sufficient for a rewarding testing job.

If you dont have the next problem.



3. YOU ARE NOT DOING EXPLORATORY, CREATIVE TESTING 

Not having time for creating test cases requires that you learn and test fast.

And find important bugs too.

Developers are much more involved in testing now and use unit testing frameworks (like JUNIT) for testing their code.

The unit tests catch many application issues reported in the past by manual testers.

So the manual testers need to do much better testing and find valuable issues not caught by unit testing. 

To test fast, without test cases and find very good bugs requires a different testing approach.

The tester should use exploratory testing instead of scripted testing, be creative, think outside the box, behave as a user.

Use lateral thinking and become proficient with exploratory testing tours.



Being very good at exploratory testing is great if you can find the next job.

But it is often difficult to differentiate yourself from other manual testers, maybe not as good as yourself.

If you don't stand out from other testers, you may not be able to find another job so your testing career will suffer.





But what if your skills are just good at exploratory testing?

This is the third testing career warning: not standing out and not having great exploratory testing skills.

It is difficult to stand out when ....



4. YOU KNOW VERY WELL ONLY ONE TYPE OF TESTING 

I asked many times IT recruiters what type of testers are companies hiring.

The answer was very consistent.

Most companies want testers that can wear multiple hats, are technical, can do test automation, know a programming language.

And they can cook spaghetti and speak italian.

Just kidding.

Why are companies so demanding?

Because the more things a tester knows, the more value he adds to the project.

If the tester can not only test but also provide customer support, participate in code reviews, write test automation scripts, create unit tests, is he more valuable than another tester than just does functional testing?

Much more valuable.






Being a versatile tester is not only more valuable for the company but also for your career.

You can target not only manual testing jobs but also test automation, performance testing, api testing, hybrid testing roles too.

If you focus on one testing type only, your future testing career may be in danger.

But, how can you find the time to learn all these new skills?

And who will provide the training?

And what should you learn?



5. YOU ARE NOT TAKING RESPONSIBILITY FOR YOUR TRAINING 

No one will provide you the training for growing your career except yourself.

You may know this joke:

the person that can solve all your problems is the one that looks at you when you are in front of the mirror.

Few companies offer training programs to testers these days.

And if they do, the courses are for skills that the company needs which may be different from what the tester needs.





So, to keep your career afloat, you need to take responsibility for
  • what you learn
  • how you learn
  • how to find the time for learning



6. YOU ARE KEEPING THE SAME TESTING JOB FOR A LONG TIME 

This is the last warning that your testing career may be in danger.

There are companies out there where you can work for a long time and have a very rewarding experience.

If you can move between projects or departments or even better if you can change job responsibilities often, there is no need to change your job. 

All these changes will keep you improving and learning.





But, if you work on the same product for a few years, do the same testing and within the same team, chances are that you stopped improving yourself a long time ago.

And if there is one thing that shows that your career may not have a future, this is the one:
you are not learning new things every day.

Make Test Automation Scripts Fast Using HTML Parsing Frameworks



If test execution speed is most important, HTML parser libraries like JSOUP should be used when Selenium WebDriver scripts are too slow.

JSOUP is a Java library for working with real-world HTML.

It provides a very convenient API for extracting and manipulating data, using the best of DOM, CSS, and jquery-like methods.


Selenium WebDriver scripts are very slow

The speed of Selenium WebDriver scripts is very slow as it depends on:
  • browser load time; how fast the browser loads depends on how good the computer is
  • site's performance; the performance of the site depends on server hardware, number of concurrent users, site architecture
  • internet connection's performance

Let's take for example a simple script that implements the following test case:
  • open the home page of the http://www.vpl.ca site
  • do a keyword search
  • on the results page, click on the title link for the first result
  • on the details page, check that the book title and book author values exist

All code samples are just that, samples.

No page object classes are being used.

@Test
public void test2() throws InterruptedException {

driver.get("http://www.vpl.ca");


WebElement searchField = wait.until(ExpectedConditions.
visibilityOfElementLocated(By.xpath("//input[@id='globalQuery']")));


searchField.click();
searchField.sendKeys("java");

WebElement searchButton = wait.until(ExpectedConditions.
elementToBeClickable(By.xpath("//input[@class='search_button']")));


searchButton.click();

WebElement resultTitle = wait.until(ExpectedConditions.
elementToBeClickable(By.xpath("(//a[@testid='bib_link'])[1]")));


resultTitle.click();

String bookTitleValue = "", bookAuthorValue = "";;

WebElement bookTitleElement = wait.until(ExpectedConditions.
visibilityOfElementLocated(By.xpath("//h1[@id='item_bib_title']")));

bookTitleValue = bookTitleElement.getText();
assertTrue(bookTitleValue.length() > 0);

//some books do not have author so I need to use a try/catch
try {


WebElement bookAuthorElement = wait.until(ExpectedConditions.
visibilityOfElementLocated(By.xpath("//a[@testid='author_search']")));

bookAuthorValue = bookAuthorElement.getText();
assertTrue(bookAuthorValue.length() > 0);


}
catch(Exception e) { }

}


The test script runs correctly in about 15 seconds.

Let's assume that we want to create a script for another test case that does the same things as the previous one but for all book title links from the results page (10 links).

The script is a bit more complicated as it needs to iterate through all book title links:
  • open the home page of the http://www.vpl.ca site
  • do a keyword search
  • on the results page, do the following for each book title link
    • click on the title link
    • on the details page, check that the book title and book author values exist
    • go back
    • continue with the next link

@Test
public void test1() throws InterruptedException {

driver.get("http://www.vpl.ca");

WebElement searchField = wait.until(ExpectedConditions.
visibilityOfElementLocated(By.xpath("//input[@id='globalQuery']")));


searchField.click();
searchField.sendKeys("java");

WebElement searchButton = wait.until(ExpectedConditions.
elementToBeClickable(By.xpath("//input[@class='search_button']")));


searchButton.click();

for (int i = 1; i <= 10; i++) {

WebElement resultTitle = wait.until(ExpectedConditions.
elementToBeClickable(By.xpath("(//a[@testid='bib_link'])[" + i + "]")));


resultTitle.click();

String bookTitleValue = "", bookAuthorValue = "";

WebElement bookTitleElement = wait.until(ExpectedConditions.
visibilityOfElementLocated(By.xpath("//h1[@id='item_bib_title']")));


bookTitleValue = bookTitleElement.getText();

assertTrue(bookTitleValue.length() > 0);

try {

WebElement bookAuthorElement = wait.until(ExpectedConditions.
visibilityOfElementLocated(By.xpath("//a[@testid='author_search']")));


bookAuthorValue = bookAuthorElement.getText();

assertTrue(bookAuthorValue.length() > 0);


}
catch(Exception e) { }

driver.navigate().back();
}


The script runs successfully but it needs 98 seconds to complete.

Is there another way for making the second script faster?

The first script proves that the site navigation between the home page, result and details pages works well.

If we agree that the navigation is not important for the second script, we can implement it not using the Selenium WebDriver framework but with the JSOUP HTTP parser library.


Implement time consuming automation scripts using the JSOUP library

Let's start cooking :)

We need the soup ingredients first: vegetables, herbs, oil ..............

Just kidding.



We will be cooking a different type of soup: JSOUP.

A few words about JSOUP (from the jsoup official site):

jsoup is a Java library for working with real-world HTML.
It provides a very convenient API for extracting and manipulating data, using the best of DOM, CSS, and jquery-like methods.

jsoup implements the WHATWG HTML5 specification, and parses HTML to the same DOM as modern browsers do.
  1. scrape and parse HTML from a URL, file, or string
  2. find and extract data, using DOM traversal or CSS selectors
  3. manipulate the HTML elements, attributes, and text
  4. clean user-submitted content against a safe white-list, to prevent XSS attacks
  5. output tidy HTML

To user JSOUP, first download the JAR file from http://jsoup.org/ and add it to the project properties.

The second script written with JSOUP looks like this:

@Test public void test1() throws IOException {

Document resultsPage = Jsoup.connect("https://vpl.bibliocommons.com/search?q=java&t=keyword").get();

Elements titles = resultsPage.select("span.title");

for (Element title : titles) {

Element link = title.child(0);

String detailsPageUrl = "https://vpl.bibliocommons.com" + link.attr("href");

Document detailsPage = Jsoup.connect(detailsPageUrl).get();

Elements bookTitle = detailsPage.getElementsByAttributeValue("testid", "text_bibtitle");

if (bookTitle.size() > 0)
assertTrue(bookTitle.get(0).text().length() > 0);

Elements bookAuthor = detailsPage.getElementsByAttributeValue("testid", "author_search");

if (bookAuthor.size() > 0)
assertTrue(bookAuthor.get(0).text().length() > 0); 

}

}

Lets see what each line does:

//establishes a connection to the page;
//uses the get method to get the page content and return a document object
Document resultsPage = Jsoup.connect("https://vpl.bibliocommons.com/search?q=java&t=keyword").get();

//selects all span elements that have the title class from the document object
Elements titles = resultsPage.select("span.title");

//for each span element from the list
for (Element title : titles) {

//gets the first node of the span element; this is the title link
Element link = title.child(0);

//gets the href attribute of the a element
String detailsPageUrl = "https://vpl.bibliocommons.com" + link.attr("href");

//establishes a connection to the details page
//gets the page and returns a document object
Document detailsPage = Jsoup.connect(detailsPageUrl).get();

//finds all elements in the details page that have a testid attribute with the text_bibtitle value
Elements bookTitle = detailsPage.getElementsByAttributeValue("testid", "text_bibtitle");

//get the first found element using get(0) and its text using text()
//assert that the text length is > 0
if (bookTitle.size() > 0)
assertTrue(bookTitle.get(0).text().length() > 0);

//finds all elements in the details page that have a testid attribute with the author_search value
Elements bookAuthor = detailsPage.getElementsByAttributeValue("testid", "author_search");

//get the first found element using get(0) and its text using text()
//assert that the text length is > 0
if (bookAuthor.size() > 0)
assertTrue(bookAuthor.get(0).text().length() > 0); 

The script is simpler than the WebDriver one.

It does not work by interacting with the site through the browser.

It uses http requests instead to get the page data and then it parses or navigates through the page data.

The best part of this script is that it executes in 8 seconds!!!!

Compare this with 98 seconds needed for executing the WebDriver script.




Hope that you liked the soup recipe!

If you have any questions about the recipe, ingredients or the cook, please post them in the comments section.

The cook appreciates your interest in his recipes :)


How To Take Entire Page Screenshots In Selenium WebDriver Scripts

The ashot framework from Yandex can be used for taking screenshots in Selenium WebDriver scripts for
  1. full web pages
  2. web elements
This framework can be found on https://github.com/yandex-qatools/ashot.


Selenium WebDriver TakeScreenshot interface is rather limited


By default, screenshots can be taken in Selenium WebDriver scripts using the TakeScreenshot interface:

import static openqa.selenium.OutputType.*;
 
File screenshotFile = ((Screenshot)driver).getScreenshotAs(file);
String screenshotBase64 = ((Screenshot)driver).getScreenshotAs(base64);

If you need to take entire page screenshots or screenshots of a web element, this is possible but complicated.


Take Entire Page Screenshots With The AShot Framework



Yandex has other frameworks available in addition to Allure.

The ASHOT framework is helpful for taking screenshots.

Lets see some code samples.

The following test script implements a test case for the www.vpl.ca site that
  1. opens the home page of the site
  2. executes a keyword search
  3. clicks on the title of the first result on the results page
  4. checks that the book title is displayed on the details page
  5. checks that the book title's length is greater than 0

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestWithoutScreenshots {

WebDriver driver;

@Before
public void setUp() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
}

@After
public void tearDown() {
driver.quit();
}

@Test
public void testFirstResult() throws InterruptedException
{


//opens the home page of the site
driver.get("http://www.vpl.ca");

//executes a keyword search
WebElement searchField = driver.findElement(By.xpath("//input[@id='globalQuery']"));
searchField.click();
searchField.sendKeys("java");

WebElement searchButton = driver.findElement(By.xpath("//input[@class='search_button']"));
searchButton.click();

Thread.sleep(3000);

//clicks on the title of the first result on the results page
WebElement searchResultLink = driver.findElement(By.xpath("(//a[@testid='bib_link'])[2]"));
searchResultLink.click();

Thread.sleep(3000);

WebElement bookTitleElement = driver.findElement(By.xpath("//h1[@id='item_bib_title']"));
String bookTitleValue = bookTitleElement.getText();

//checks that the book title is displayed on the details page
assertEquals(bookTitleElement.isDisplayed(), true);
//checks that the book title's length is greater than 0 assertTrue(bookTitleValue.length() > 0);

}

}

The test script is part of a Maven Project.


Add The ashot Dependency To The POM.XML File

Add the following lines to the pom.xml file:

 <dependency>
<groupId>ru.yandex.qatools.ashot</groupId>
<artifactId>ashot</artifactId>
<version>1.4.12</version>
</dependency>  


Then, change the code so that entire page screenshots are taken for each page:


import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.screentaker.ViewportPastingStrategy;

public class TestWithScreenshots {

WebDriver driver;

@Before
public void setUp() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
}

@After
public void tearDown() {
driver.quit();
}

@Test
public void testFirstResult() throws InterruptedException, IOException
{

driver.get("http://www.vpl.ca");

//take the screenshot of the entire home page and save it to a png file
Screenshot screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver);
ImageIO.write(screenshot.getImage(), "PNG", new File("c:\\temp\\home.png"))
;

WebElement searchField = driver.findElement(By.xpath("//input[@id='globalQuery']"));
searchField.click();
searchField.sendKeys("java");

WebElement searchButton = driver.findElement(By.xpath("//input[@class='search_button']"));
searchButton.click();

Thread.sleep(3000);

//take the screenshot of the entire results page and save it to a png file
screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver);
ImageIO.write(screenshot.getImage(), "PNG", new File("c:\\temp\\results.png"));


WebElement searchResultLink = driver.findElement(By.xpath("(//a[@testid='bib_link'])[2]"));
searchResultLink.click();

Thread.sleep(3000);

//take the screenshot of the entire details page and save it to a png file
screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver);
ImageIO.write(screenshot.getImage(), "PNG", new File("c:\\temp\\details.png"));


WebElement bookTitleElement = driver.findElement(By.xpath("//h1[@id='item_bib_title']"));
String bookTitleValue = bookTitleElement.getText();

assertEquals(bookTitleElement.isDisplayed(), true);
assertTrue(bookTitleValue.length() > 0);

}

}

Lets see how the screenshots look like.

The screenshot for the home page looks good:





The screenshot for the details page looks good as well:



The screenshot for the results page does not look too good:



How can we get a proper screenshot for the results page?


Take Web Element Screenshots 

The framework offers the option of getting screenshots of web elements.

See below the changed code:


import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.screentaker.ViewportPastingStrategy;

public class TestWithScreenshots {

WebDriver driver;

@Before
public void setUp() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
}

@After
public void tearDown() {
driver.quit();
}

@Test
public void testFirstResult() throws InterruptedException, IOException
{

driver.get("http://www.vpl.ca");

//take the screenshot of the entire home page and save it to a png file
Screenshot screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver);
ImageIO.write(screenshot.getImage(), "PNG", new File("c:\\temp\\home.png"));

WebElement searchField = driver.findElement(By.xpath("//input[@id='globalQuery']"));
searchField.click();
searchField.sendKeys("java");

WebElement searchButton = driver.findElement(By.xpath("//input[@class='search_button']"));
searchButton.click();

Thread.sleep(3000);

//take the screenshot of the entire results page and save it to a png file
screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver);
ImageIO.write(screenshot.getImage(), "PNG", new File("c:\\temp\\results.png"));

//take the screenshot of a div element that includes all results page details>br/> screenshot = new AShot().takeScreenshot(driver, driver.findElement(By.xpath("(//div[@id='ct_search'])[1]")));
ImageIO.write(screenshot.getImage(), "PNG", new File("c:\\temp\\div_element.png"));


WebElement searchResultLink = driver.findElement(By.xpath("(//a[@testid='bib_link'])[2]"));
searchResultLink.click();

Thread.sleep(3000);

//take the screenshot of the entire details page and save it to a png file
screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver);
ImageIO.write(screenshot.getImage(), "PNG", new File("c:\\temp\\details.png"));


WebElement bookTitleElement = driver.findElement(By.xpath("//h1[@id='item_bib_title']"));
String bookTitleValue = bookTitleElement.getText();

assertEquals(bookTitleElement.isDisplayed(), true);
assertTrue(bookTitleValue.length() > 0);

}

}


The screenshot of the div element shows the full results page:





NEXT



Use Ranorex When Automating Windows Applications


Use Ranorex when working on test automation for Windows applications.


Ranorex has many qualities that recommend it for test automation:
  • uses C# as programming language
  • supports many application types (windows, mobile and web)
  • has an amazing customer support.
The company that built it does not have other products so they put all their focus and resources into Ranorex.

Everything that follows comes from my test automation experience with Ranorex.

I am not working for Ranorex , nor do I have any business relationship with them.

I am just a fan of the product.



Why not using QTP (UFT) for test automation of windows applications?



Until recently, my answer to this question would be that 

  • QTP uses VB Script as programming language
  • Ranorex uses C#




However, QTP (UFT) has a new module called Lean FT which allows the test automation engineer to use not only VB Script but also Java and C#.

So the language is not a problem.

Actually, UFT offers more languages that Ranorex for test automation.


If not the language, then what recommends Ranorex over QTP?


If you ever had a serious problem with any of the HP QA tools (QTP, QUALITY CENTER, LOAD RUNNER), you know that it takes a long time until HP provides a solution.

You have to go through many customer support levels that are most of the time not helpful.

Eventually, after many weeks (or months; I waited for a Load Runner solution for 6 months once), if you are lucky, you get to speak with someone who is knowledgeable enough to help out.


For Ranorex, since they are a 1 product company, you get help in days.

The Ranorex customer support is made of developers.

All you have to do is to add your problem to the forum.

Someone will pick it up and propose a solution (if available).

If you found a bug in the product, you will be provided with an approximate date of the patch.







Ranorex key functionalities

Record And Play

Like many other commercial test automation tools, Ranorex has a record and play module.

You can use it for recording user scenarios while interacting with your application.

The result of recording is displayed in a matrix where you can make changes:
  1. change the action type
  2. add new action
  3. change the order of actions
  4. remove actions
  5. add delays
  6. change objects
You can also see the C# code generated during recording.

This code can be changed if needed.






Another result of the recording is the object repository.

This is the place where you can see details of the objects used in the user scripts:

  • object type (button, label, radiobutton, textbox, image, etc)
  • object attributes
  • object locator (Ranorex uses XPATH for locators)
  • position of the object in the application object tree


Code Modules

In my opinion, in general, you should not use record and play for test automation.

Instead, create the test scripts slowly using code modules.

Code modules are just files with the CS extension where you can create your classes.

The classes are built using C# and can be of 2 types:

  • run-time classes:  they are used for creating the test scripts
  • normal classes: they are used for implementing the interaction with the application

When creating the classes that implement the interaction with the application, you can use the page object model.

This model says that the test scripts should not include test automation API commands so it is a good idea to use it for 

  • keeping your test scripts short and easy to understand
  • creating your own test automation framework



Spy


The spy is a component that allows exploring the application structure.

You can select any component of the application using the spy and get lots of details about it:
  • xpath expression that matches the component
  • component attributes
  • component value
  • position of the component in the application component tree







Ranorex Studio

The development and execution of the test scripts is being done from the Ranorex Studio.

Ranorex Studio is just an IDE similar with Visual Studio and Eclipse.

It has all functionalities needed when creating code and debugging it:

  • debug components
  • refactoring components
  • build components

The Ranorex API can be used from Visual Studio as well.







Test Cases And Test Suites

Test scripts can be added to test cases.

When this is done, it is possible to add to a test case a 

  • setup script (for setting up the environment needed for the test script) 
  • teardown script (for clearing up the environment)

The test cases allow creating data driven test scripts.

This is done by defining variables in the test scripts and binding them to data tables.

The result of executing the test scripts is displayed in HTML reports that can include any data available in the test scripts.






Learning Materials

You will find on the www.ranorex.com site lots of useful and very detailed materials such as
  1. user guide
  2. free webinars
  3. screencasts
  4. many other
If you are interested in the problems that Ranorex users have, you can check the product's forum.







Is Ranorex a good test automation tool for beginners?

It is a very good tool to use when starting learning test automation.

All information that a beginner needs is available on the Ranorex site, either in the user guide, product guide, screencasts or on the forum.

The user guide and screencasts are very detailed and clear and created for beginners.

The forum provides lots of examples and solutions to many problems.

The record and play tool gets the beginner started right away by providing information about
  1. actions
  2. repository
  3. objects attributes
  4. xpath locators
  5. C# code created for each recording session



When Did I Use Ranorex?

The first time I used Ranorex was in 2013.

My employer at that time had a windows application that used Sharepoint workflows for document management.

This application was crashing randomly all over the place.

I suspected a memory leak being the cause of the random crashes.

So I tried using QTP first.

This did not go well as QTP crashed every time I installed it.

It was probably not compatible either with the hardware of the computer I was using or with the enterprise Windows version.

The next tool I tried was Ranorex.

I knew about it from various QA blogs and online testing magazines.

I recorded a few scripts, customized them and then ran them continuously for a few hours.

This was sufficient for confirming that the memory leak is indeed present as the memory used by the application went up 5 times in 1 hour.

The company purchased the Ranorex license after the memory leak investigation and used it in a few projects.


The second time I used Ranorex was this year.

This time, I was looking into automating user scenarios for a WPF application.

The test automation code was used in this case for 2 purposes:


  • check periodically for memory leaks
  • automate the smoke build process




In conclusion, if you cannot use Selenium WebDriver for test automation, try Ranorex.

You will not be disappointed.