How to view documents using Visual Studio

View documents in Visual Studio with an amazing tool

Xpath Axes

A very useful trick for automation

Review: Spire.DataExport for .NET

A great tool for exporting data in .NET

How to install Arch Linux, step by step, for VMware Workstation (Part I)

First part of a installation tutorial for this beloved OS

How to setup a local repository in Ubuntu

The steps to have a local repo in Ubuntu

Tuesday, October 25, 2016

Tools for API REST testing


Sometimes we have to test some feature on the fly, especially if you are supporting more than one team on QA. I already showed how to test APIs with java and Apache libraries, but you my find yourself in a moment when you don't have your code at hand. Then, what to do?
Fortunately, there are some options for this. I´ll check a couple of them.

Postman

Postman is a Chrome and Mac add-in that allows us to work with all kind of API requests. This is a great option for QA, since it has a comprehensive set of options displayed through a nice UI. But let's play a little with a request:

1. Download Postman here.
2. Install it.
3. Open Postman. You should see something like this:

4. For this example, we'll use the pubic API from https://httpbin.org/. So, let's make some GET requests: Paste the following in the main text box: http://httpbin.org/gzip (Returns gzip-encoded data). Make sure that the request is a GET, and then press Send. The result should be displayed in JSON format, like this:


Postman is a comprehensive tool with many options. However, these are the features I liked the most:

History: This is especially useful when you do a lot of requests with different URLs. Sometimes it's hard to keep track of the URLs and configurations, but you can check any past request if you need to in the History:
Request history

Multiple tabs: You can open new tabs, each one with the particular set of options you set. This is useful when you need to copy or compare parameters from different requests, like copying an authentication token.
Multiple tabs

Postman is a great tool, with many advanced options that can help both developers and QAs. However, what if you can't install Postman for some reason? Some organizations have the access to the Chrome store blocked, and contacting IT just for a quick fix might not be always the answer.

Online REST test

There are many pages to do simple requests. These do not have many options or advanced configuration, but they might be helpful to some tests on the run. Examples:

REST test test

You can find this tool at https://resttesttest.com/. To make requests with this tool:

1. Open the page.
2. Select the method. In this case, it's GET.
3. Select the endpoint. We will use the URL we used before (http://httpbin.org/gzip).
4. Press Ajax request.
5. You should see the same response than the one you obtained with Postman.

These tools are not uncommon in internet. For example, you can also use this: https://www.hurl.it/, which will give you most of common options for these tools (Add authentication, header, parameters, etc.):


Monday, October 24, 2016

CSS selectors for automation: how to use them


One of the most common problems we face when automating is that the elements' locators become obsolete as soon as there is a change in the UI we are testing, and most of the time the options for this are clear: Xpath or  CSS Selectors. I´m not comparing them in this article, since there's some controversy around the question. I found an interesting article that compared Xpath and CSS Selectors in terms of performance and other metrics, you might want to check it out. So, there are many reasons to use CSS Selectors. Now, I´ll show some basic tricks with CSS Selectors with a framework with Java and Selenium in mind.

Content

Select by ID
Select by tag
Select by class
Select nth element

Requirements
Prerequisites:

  1. First of all, open Firefox. We will use this page (www.testools.net) for the examples, so open it in a new tab. 
  2. Now, right click on the Testools logo > Inspect Element with Firebug.Inspect logo
  3. Click FirePath.
  4. Click the button at the left of the text box and select CSS. Here we will test our CSS Selectors.CSS text box

Select by ID

First, let's check the HTML structure for the logo:
Logo ID
As you can see, the id for the Logo is Header1_headerimg. In CSS Selectors, IDs are selected using #. So, in this case, we can select the logo with this:

#Header1_headerimg

Open the FirePath tab and paste that string, then press Enter. You should see a match:
Selected logo element

Since IDs should be unique, using them is a safe way to select elements for Selenium. However, not all elements have a unique ID, and asking developers to add them is not always an option.

Select by tag

You can select elements by tag, although this is better used in along with classes. However, tags are selected only with the tag name itself. If you'd want to select all the elements with the tag img, like this:
img tag

You'd only need to write this:

img

And it will match all the elemts with the img tag:
Selection by tag

Select by class

Classes are selected using dots. For example, if we want to select the first post:
Posts inspection
We can do it by typing the class name preceded by a dot:

.wrapfullpost

This will select all the elements with the class wrapfullpost. In this case, 5 elements are selected, since there are 5 posts in the main page:
Select by class

Select nth element

In the example above we had 5 elements selected. But what if we want to select only one of those elements? Let's check another example. Enter the following css:

.menus.menu-secondary.sf-js-enabled.sub-menu

That will select the menu:

Menu selected

If we expand the selected element, we will see that the four menu elements are represented by 'li' nodes. To select the 3rd element, we can use:

.menus.menu-secondary.sf-js-enabled.sub-menu li:nth-of-type(3)

3rd element

Note that, to select the first element you should use nth-of-type(1). Unlike most of other syntax, here you start the count in 1.

This will be enough to get you started using css selectors!

Tuesday, October 4, 2016

API testing: Get requests with Java and Apache libraries


API testing is very common nowadays, and it's easy to see why. One of the uses of APIs is to manipulate an application to create pre steps (among a lot of other things) for scenarios without the need of handling the UI, which is good news for all who struggle with locators that change a lot.

In this article I will show how to use Java to perform basic API actions with the Apache HttpComponents. Let's check it out:

Requirements:
Steps:

1. Open Eclipse and create a new Java Project. Call it 'APITesting'
Project details

2. Right click src > New > Class. Name the new class 'APITesting'. Select 'public static void main(String[] args)' to create the main method snippet. Then click Finish.

Class details

Class created

3. Add the needed libraries. For this, expand the APITesting project and right click JRE System Library > Build Path > Configure Build Path...
4. Click 'Add External JARs'
5. Navigate to httpcomponents-client-4.5.2\lib and select the following libraries:
  • httpClient-4.5.2.jar
  • httpcore-4.4.4.jar
  • commons-logging-1.2.jar
Then press OK.
6. Now that you have all the required libraries, enter the following code into the APITesting.java class. The final result should look like this:


So, basically, you have to perform 3 main actions here:

- Create a httpClient:

HttpClient httpClient = HttpClientBuilder.create().build();

- Create a GET request with proper endpoint and add the header:

HttpGet getRequest = new HttpGet(
"https://jsonplaceholder.typicode.com/posts");
getRequest.addHeader("accept", "application/json");

- Execute the request and store the result in a HttpResponse:

HttpResponse response = httpClient.execute(getRequest);

From there on, you can play with the contents of the response and print it, as I did in this example. Click the Play button in Eclipse to run the code. You should see a json text as response in the console:

Response