Tuesday, October 25, 2016

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:

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.

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:

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

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.

First, let's check the HTML structure for the logo:
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:

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.

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:

Tuesday, October 4, 2016

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:

Apache HttpComponents. You can download it at: https://hc.apache.org/downloads.cgi. After you download it, extract the compressed file. Take note of the location of the path to the folder httpcomponents-client-4.5.2\lib, as you will need the contents of that folder for this example.

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: