Tuesday 25 December 2018

New Selenium IDE supports Chrome & more features


       Selenium Integrated Development Environment best known as Selenium IDE, is the simplest and easiest tool in whole Selenium suite to install and get introduce to selenium environment for the beginners. This was initially released as a Firefox add-on that creates tests quickly through record-and-playback functionality. This was even being used by the Selenium advanced users to identify the objects on a page using locator techniques such as xpath, css, id etc. After the recent changes in Firefox browser, Selenium IDE has stopped working for a while now.

But Selenium team has just released new Selenium IDE. 

Let’s discuss the new features of latest Selenium IDE in this post.

    1. Built as Web Extension & Chrome Support:
The latest Selenium IDE is built as a web extension. Because of this, now we have  Selenium IDE support for chrome browser as well. The Sideex open source project was used as a base to build this IDE.
    Installation in chrome:
a.   Open this in your chrome browser and click on “Add to Chrome”


b.   Once you add it, you can seeicon on top of your browser, beside the address bar.
c.   If you click on the icon, Selenium IDE would open up as a popup,

d.   You can start using it, by clicking on “Record a new test in a project” and naming it.
    Installation in firefox:
a.   Open this in your firefox browser and click on “Add to Firefox”
b.   Once you add it, you can see  icon on top of your browser, beside the address bar.
          c. Other steps are same as above.

2. Improved locators:
 Now selenium IDE supports auto populated, improved, multiple fallback locators. Once you record any test, select a step where you want to change the object locator. Then click on the “Target” drop down. You can see multiple options like css, xpaths, name, id etc.

     3. Conditional & Control flows:
The latest Selenium IDE supports Conditional flows by using if, elseif, repeatif commands. With these commands, we can specify the conditions to make our recorded script more intelligent.
                        
IDE also supports control flow using while command. A condition can be specified to execute a specific step repeatedly.

4. In-built implicit wait:
Selenium IDE will now automatically wait for every command, every command will wait for the page to load. Commands which take a locator will wait for the element to appear. This way we no need to use explicit waits.

5. Adding assertion and verifications while recording itself:
Now users can add assertions and verifications in tests by using the context menu on the page. Once the page gets launched from IDE, select the element that needs to add as assertion. Now right click on that element. You can see a context menu, with multiple options.

    
6. Running in CI:
We can execute the selenium IDE scripts in CI now. If you click on 3 dots next to save icon in selenium IDE, you can see an option called “Running in CI”. Clicking on this option takes you to here. This page has very clear explanation on how to execute these .side scripts though CI. We can also use selenium server to run the tests in remote machines.


According to Webdriver creator Simon Stewart, below features are in pipeline for Selenium IDE team.

1. Exporting Selenium IDE Scripts to Programming languages (Java/JUnit/Python/PHP):
    Exporting the .side Scripts to programming languages is not supported yet in the latest IDE. But this will be supported in future starting with Java.

2. Data driven Testing:
    Even the old IDE was not supporting data driven testing. But it is being considered in the latest IDE. We may see this feature as well in future.

Thursday 6 December 2018

Useful tricks and tips for working with POSTMAN


      Postman is a powerful graphical HTTP client helpful when working with APIs. In our day to day work, we use postman for our REST Service tests a lot. In this post I am going to discuss about few tips and tricks while using postman.

1. Variables:
    We can use variables to replace certain fields such as the URL, URL parameters, headers, authorization, request body, and header presets etc. in postman. These variable names are enclosed with double curly braces – like {{variable name}}. Postman uses string substitution to replace the current value of this variable.


There are multiple ways to initialize, retrieve, and define the scope of these variables. Below is the practical usage of this feature.

How I used variables:
    The most annoying problem we face in our everyday usage of postman is, updating the Auth token. As the auth token has limited validity, we have to replace the token every time when it gets expired. This hack helps the users to include this token generation in the run time, so that we don't need to update every time.

    First, we need to add the below script under "Pre-request Script" tab. (The Pre-request Script is a tab where one can write javascript code to hit any endpoint and extract data from a response to use this data in a subsequent request. So, if you include any script in this tab, this will be executed even before making your REST Call. Thus it initializes & loads the variable even before making your actual Call.)


const echoPostRequest = {
  url: 'http://ur.access.token.endpoint',
  method: '<GET or POST>',
  header: 'Content-Type:application/json'
};

var getToken = true;
console.log(pm.sendRequest);

if (getToken === true) {
    pm.sendRequest(echoPostRequest, function (err, res) {
        console.log(err ? err : res.json());
        if (!err) {
            pm.globals.set("token", res.json()["<field name of the response where your token is stored>"]);
        }
    });
}


In the above script, we are storing the token value in the variable called “token”. Now we use this variable in the header as the value of “Authorization” like below (You may be using different key for authorization. Use the same key here).


That's it. Now you can run this collection, whenever you want without worrying about replacing latest token.

2. Dynamic Variables:
     Postman has a few dynamic variables you can use in your requests. We can use them in the request builder as unique IDs, timestamps, or random integers. The syntax will be {{$timestamp}}. Below are those variables and their purposes.

{{$guid}} : Adds a v4 style guid
{{$timestamp}} : Adds the current timestamp
{{$randomInt}} : Adds a random integer between 0 and 1000


3. Data Variables:
   Data variables are available when using a data file with the collection runner. You can import the data as a CSV or JSON file, and then use the values from the data file inside HTTP requests and scripts. Here's an example of Inside pre-request and test scripts. Let's say you have the pm.iterationData.get("username") method inside pre-request and test scripts. The method would let you access the value of the username variable from a data file.


You can get more details on how to use data variables from the below link