Latest Updates. News. Insights. Ideas.

web automation Archives - Sahi Pro

Fetching multiple elements? _collect APIs to your rescue.

Posted by | Sahi, technical, tutorials, web automation | No Comments

There are multiple cases in automation where you would like to fetch multiple elements. In such cases, you can use any of the three APIs – _collect, _collectAttributes and _collectElementsInfo.
Let us see each API in detail.

This API returns an array of element stubs of all elements of type apiType matching the identifier within relations.

_collect($apiType, $identifier[, $relations ...])

$apiType string type of elements to collect. Eg. "_link", "_button", "/text/" etc.
$identifier string|int Sahi Identifier. Can also be just an index.
$relations … relations optional Relations like _in, _near etc.

The next API to check out is _collectAttributes
This returns an array of element attributes of all elements of type apiType matching the identifier within relations.

_collectAttributes($apiType, $identifier, $attribute[, $relations ...])

$apiType string type of elements to collect. Eg. "_link", "_button", "/text/" etc.
$identifier string|int Sahi Identifier. Can also be just an index.
$attribute attribute|function attribute or function.
$relations … relations optional Relations like _in, _near etc.This can fetch

This API can fetch

  • a simple attribute from multiple elements
  • one of the few simple attributes from multiple elements
  • some synthesized/processed values from multiple elements by executing
    • an inline function for each element
    • a defined function for each element
    • nested functions

The third API to note is _collectElementsInfo
This API returns array of Accessor Info object of all elements of type apiType within relations.

_collectElementsInfo($apiType[, $relations ...])

$apiType string Type of elements to collect. Can be regular expression. Eg. "_link", "_button", "/text/" etc.
$relations … relations optional Relations like _in, _near etc.

To know more about Fetch APIs, please refer this link:

Feel free to write your questions to support [at] sahipro [dot] com

Test Talks: Automation Awesomeness: Test Automation Using Sahi with Narayan Raman

Posted by | Agile, marketing, People, Speakers, talks, web automation | No Comments

Our CEO Mr. Narayan Raman was featured on Joe Colantonio’s Test Talks. Listen to the Test Talk to discover why Sahi Pro might be the right choice and the parameters to consider while choosing a test automation tool, apart from other insights on Sahi Pro and Sahi Open Source.

135: Test Automation Using Sahi with Narayan Raman

Quotes & Insights from this Test Talk

  • Created Sahi After Attempt at Agile Needed something more lightweight and easier to use. Developers and browsers were moving too fast
  • Very tester-focused, an effort to make it easier for a nyone to automate applications. Many testers are not programmers, and Sahi helps them understand the basics. Most testing code is procedural; you take steps and you verify results. Sahi helps to keep it simple! Organize functions into the right files Make sure you’re calling the right parameters
  • This tool is good for both testers and developers. Developers write the application as it should function; the automation team and the tester team should be able to work with a working application, and be able to automate it; they should no thave anything extra done for that automation. If the tool requires more, there’s going to be pushback from developers. The end tester should know about only the actions he performs on the
  • Example: “Recording a sequence for playback is considered a tricky task on most web applications,” but this was fairly successful. Helped testers to quickly automate the app and script it took tester through 30% or 40% of initial automation phase. After that, you should be refactoring the code into functions and have reusable libraries
  • Sahi’s Recorder, and being able to work more closely with the browser, helped make the testing process faster. Record and Playback records image in Javascript. There’s also a Java Recorder
    Sahi vs Selenium (both came out around the same time)
    * Premises
    – “ Selenium was built on the premise that the developer himself would also write every test for everything that he builds; he has full control over the application that he’s testing.”
    – In Sahi, the end tester does not need to know too much about the app. If there is something he needs to automate, he does not need to go back to the developer all the time.
    – Operations
    – Selenium uses XPath, CSS Selectors, Waits, etc
    – Sahi handles a lot of complexity internally
    – enters Javascript into web page
    – Hooks into XMLHTTPRequestObject, and wait until AJAX activity
    has subsided on the page before proceeding to execute a step
    – Eliminates need for implicit or explicit waits
    – “Any element of interest to automation will always have something by
    which it can be identified, even if it doesn’t have an ID…Depending on the
    kind of element, we have a sequence of attributes by which we try to
    identify that element… the code automatically iterates to the frame and
    finds the element.”
    – “XPath is a strict no-no in Sahi.”
    – Does not rely on structure of HTML page to ID elements
    – Makes elements more stable
    – Sahi is similar to Selenium IDE, but it will work on any browser
    – Recorder will carry over between browsers, as well
    – Finds most useful attribute value during recording phase, and stores that one only
    – Eventually, triggers will come from a continuous integration system
  • Sahi Pro ( )
    – Adds enterprise features to Sahi
    – Better for bigger organizations with larger suites
    – Helps test automation team focus on the automation itself
    – Distribution across multiple machines
    – Test suite executed across all machines
    – Pull reports and generate one consolidated report
    – Can be stored in a database
    – Puts system reports in database
    – Reports are more varied and configurable
    – Historic overview available for test suite
    – Can analyze trends and patterns
    – Log reports
    – Screenshots
  • When choosing tools or trying to automate, think what is important for the business, and not what is important for a resume review. What adds the most business value is what is going to take you higher in your organization, and also is going to help the business that you’re actually employed with.

Feel free to request a demo and check out if your automation challenges can be solved using Sahi Pro.

Five Questions Series: Sahi’s Relational APIs

Posted by | features, web automation, xpath | One Comment

In the fourth post on the Five Questions Series, we have Sahi Relational APIs today.
Previous posts in this series: Sahi Controller, Sahi Logs and Sahi Excel Framework.

What is Sahi Relational API
Some times, elements are not uniquely identifiable by themselves. Identifying them in relation to either some element near them or by the element in which they are contained helps. Sahi Relational APIs help you solve that problem. The Relational APIs can be used even on applications with dynamic ids to easily locate one element with respect to another.

Please list the different APIs (markers) under DOM and Positional Relational APIs
There are 2 kinds of relation APIs: DOM Relation APIs and Positional Relation APIs. DOM relation markers like _near, _in specify that the element should be searched near or within another element. Position relations like under, rightOf, leftOf etc. relate one element to another via their position. The list is as follows:
DOM Relation APIs:
_near, _in, _startLookInside, _stopLookInside
Positional Relation APIs:
_rightOf, _leftOf, _leftOrRightOf, _under, _above, _aboveOrUnder
Parent APIs:
_parentNode, _parentCell, _parentRow, _parentTable

How to identify elements using relational APIs?
Identify the main element or the element which is easily identifiable. Then, anchor it and identify the (hard to identify) element in relation to the main element.
Let us take an example to highlight this. In the sample application, we have three books Core Java, Ruby for Rails and Python Cookbook. We also have a text field against each of them.

Relational APIs: Sample Application

Relational APIs: Sample Application

Suppose, we want to identify the text field against the Ruby for Rails. Notice the accessor of the element when no relational API is used. It reads _textbox(“q[1]”).

Relational APIs: Element Accessor without Relational API

Relational APIs: Element Accessor without Relational API

First, identify the main element. In this case, it is the label?-?Ruby for Rails.

Relational APIs: Identify Ruby for Rails

Relational APIs: Identify Ruby for Rails

Anchor the main element by clicking on the Anchor icon.

Relational APIs: Anchor the main element

Relational APIs: Anchor the main element

Identify the secondary element now. Observe the accessor field.

Relational APIs: Identify the second element in relation to the first element

Relational APIs: Identify the second element in relation to the first element

It reads: _textbox(“q”, _near(_cell(“Ruby for Rails”))).

What is the advantage of using _rightOf/_leftOf compared to _near
Using _near where the element to be found may or may not exist can give you unexpected results. For example, in the table below

Relational APIs: Sample Table with missing elements

Relational APIs: Sample Table with missing elements

Let us say we are looking to check if a delete link exists against all users.

_assertExists(_link(“delete”, _near(_cell(“User Two”)))) may be expected to fail, but it passes.
_link(“delete”, _near(_cell(“User Two”))) actually points to the above highlighted link.

This is because, _near is a DOM relation API and finds an element within 7 ancestors (parent nodes) of the given anchor. In our case this link was found within 2 ancestors of the cell in the next row.

The correct way of asserting this would be
_assertExists(_link(“delete”, _rightOf(_cell(“User Two”)))).
_rightOf forces location only along the same line.

Does Sahi Flex Library (SFL) support the Relational APIs?
Sahi Flex Library (SFL) supports near, inside, leftOf, rightOf and under APIs. The usage of these APIs is a little different from the Sahi relation APIs.
The relation APIs are called as member functions.
_f(“mxC”).datagriditemrenderer(“/”).rightOf(_f(“mxComponents”).datagriditemrenderer(“Mary Jones”))

They can be chained to use multiple relations.

Any other questions in your mind?
Feel free to comment or ask your question(s) and we will get back to you.

MetricStream achieves quick ROI using Sahi Pro Web Test Automation Tool

Posted by | Case study, marketing, web automation | No Comments


MetricStream, a Leader in 2016 Gartner’s Magic Quadrant for Operational Risk Management Solutions and Forrester Wave on Governance, Risk, And Compliance (GRC) Platforms, is achieving quick ROI using Sahi Pro Web Test Automation Tool.

MetricStream’s GRC products are web-based applications built on technologies like Java, Ext JS, Ajax. They are using Sahi Pro to test their products in agile methodology and continuous integration. Sahi Pro Web Test Automation tool is being used for Frontend UI and Functional Validation.

MetricStream achieved several benefits by using Sahi Pro, and the most significant one was a reduction in overall regression test time and achieving an average savings of 70% to 80% on man hours of manual testing. Amongst other benefits, an important one was the ability of Sahi Pro to integrate with Jenkins and SVN to test builds in Continuous Integration.

Read More

Interview with Sahi Pro – The Tester’s Web Automation Tool

Posted by | Sahi, web automation | No Comments

I am Ajay Balamurugadas and I welcome you to our weekly show where we interview one of the promising leaders of the industry. It gives me immense pleasure to introduce today’s guest. He has been a consistent performer in web automation and built a strong hold in a very competitive market. When everyone built the automation frameworks, he focused on what is important – automating the checks. His unique philosophy of helping the tester makes his tagline – “The Tester’s Web Automation Tool” the Sahi (correct) tagline for him.

Without further ado, let us welcome –
Sahi Pro: The Tester’s Web Automation Tool

Ajay(A): Hello, Sahi Pro. Welcome to the show. We are very excited that you are here today to interact with us and share your expertise. You are one of the few automation tools who is tester-friendly and gets the job done in a simple manner. Tell us about yourself and your journey.
Sahi Pro(SP): Thank you, Ajay. It is my pleasure. I started as an open source product and then due to customer commitments, I started to focus on my Pro version and fulfill customer expectations. I noticed excellent testers struggling to automate due to complex automation tools. So, I evolved to enable subject matter experts and testers to get into automation easily.

A: Yes, that is indeed strange. When everyone around you focuses on building a robust framework and turning testers to coders, you have taken a different route altogether…
S: I will not say that we have a taken a different route for the sake of being different. My thought process is continuously evolving based on the testing industry and trends. I quickly realized that most of the end users were expected to be technical programmers or automation engineers. They were expected to build a framework from scratch, get the developers write code to align with the element identification mechanism and after all this, focus on automating the checks.

I found it quite disturbing. The purpose of web automation is to automate the checks, give the testing team the confidence that the regression bugs they expected to find are not present. The tool should free up the tester’s time. Testers should explore the application and find more critical bugs. I don’t expect my users to be technically super-strong. I take care of everything to help the tester, right from identifying the elements, suggesting accessor alternatives, providing relational APIs, excellent logging and reporting, calling Java functions and libraries from my script, automatic screenshots on failure and believe it or not, I automatically wait for page loads and AJAX activities to end!!!

A: Whoa! That’s quite a big list of key differentiators! Tell us about your element identification mechanism.
S: I use my own wrappers around the Javascript DOM to identify elements. My APIs use various DOM attributes of an element to identify them. Instead of relying on a single attribute, I look for the element’s value, name, id, css class or index etc. So, I work well even if multiple elements have the same attribute value. If I am unsure about a particular element’s identification, I rely on my trusted advisor – the Relational APIs to identify one element with respect to another.

A: Many testers want to learn automation and give up as soon as they face problems in learning a particular language. What is you suggestion to them?
S: Yes, that is a common story. People are spending time learning the language more than automating the tests. I am not against anyone learning a language but let us remember why we started this discussion. A tool should enable people to automate and not set restrictions on the way. I am an extension of JavaScript and have a pretty good recorder which can create scripts for further usage. If you have never used any tool for automation, try me!!! If you already burnt your hands spending a lot of time learning a language with little success, let us pair together and see if I can help achieve your goals.

A: Are you only for newbies or can experienced folks take advantage of your prowess?
S: As I have already highlighted, my recorded scripts can be used as a good starting point for further scripting. My JavaScript is executed in a Rhino JavaScript Interpreter, running inside my proxy. As Rhino is a JavaScript runtime running inside a Java Virtual Machine (JVM), this adds a lot of power to my scripts. My scripts can directly call Java code in scripts.

A: I am sure, our readers are excited to try you and your APIs. Does anyone provide training or demo about you?
S: The folks at Tyto Software Pvt. Ltd seem to be quite helpful in this regard. Shoot an email to info[at]sahipro[dot]com or check out the documentation about me at
I also meet my friends every Thursday in a webinar at

A: Thank you for your time, Sahi Pro. We wish you all the best for your future releases and features.
S: My pleasure. All the best for your series too.

Feel free to add your questions as comments and we will get Sahi Pro to answer for you.

Five salient features of Sahi Pro that may surprise you!!!

Posted by | features, Sahi, web automation | No Comments

I have been using Sahi Pro for some time and each time I face an issue, the Sahi Documentation has been of great help to me. Apart from the documentation, one would also appreciate the number of example scripts bundled with the product. After testing Sahi Pro on a variety of applications, I could not hold myself from highlighting  few salient features of Sahi Pro that may surprise you.

Automatically waits for AJAX and page loads

The first tool I used to automate my tasks was AutoIt and I had to add lots of Sleep(5000) or WinWaitActive ( “Create a New Post”, “” , 10 ). A quarter of my code had these Sleep commands. I had realized that these commands were very powerful essential to ensure that my scripts did not fail during the demo. Then I shifted to Selenium and things were no different. My friends who used Selenium in their day to day work had explicit code for wait.

And when I started using Sahi Pro, I was surprised at how Sahi Pro automatically waits for all the AJAX activities to finish and waits till the page loads completely. I did not have to add even a single line for wait. Isn’t it surprising? What surprised me more was that it was NOT necessary to have the browser in focus.

Record in one language and playback in another language

Do you know the average number of languages the top 25 websites support? As per the Web Globalization Report Card 2015, the number is 45. Very soon, you will have your web application support multiple languages. It is quite easy to automate for English language but your customers are from different countries and use other languages.
What would be the cost of automating across languages? Think in terms of the language experts, the automation engineer effort and the confidence you get with such an exercise. Just when we thought that it would be a costly exercise, Sahi Pro comes to the rescue with the API named _setLanguage
More details about the API here.

In-built reporting system and automatic screenshots on failures/errors

It is no wonder that people love reports. Even if someone is not willing to get technical about what’s happening in the code, they want the high level reports. How the product is performing over a period of time? How are we on the automation front? When was the last time the automation suite passed without any failures?
Creating an automation suite is itself a challenging task and to build a custom reporting module is no mean feat. Sahi Pro’s reporting module is amazing and will surprise you with the clarity of reports.And every time the script fails, Sahi Pro will automatically capture a screenshot. One need not add explicit code to take screenshots.

Excel framework – Faster collaboration between domain experts and automation engineers

Sometimes, it is easier to automate scenarios than to convince people of the value of automation, done right. People resist change and fear if their jobs will be replaced by automation. Domain experts are not willing to accept that they are not strong in programming skills and automation engineers are not sure if they are automating the right stuff.

Imagine a platform for the domain expert to provide their views and the automation engineers use the input to translate it to code. Sahi Pro’s Excel Framework aims to be the platform. The domain experts need not know how the code is implemented. The intent and the implementation is clearly separated in the framework.

Call Java libraries and APIs from Sahi Script

Sahi’s Javascript is executed in a Rhino Javascript Interpreter, running inside Sahi’s proxy. Only relevant individual statements are sent to the browser for execution. The rest of the runtime happens in Rhino inside Sahi’s proxy.
Rhino is a Javascript runtime running inside a Java Virtual Machine (JVM). This adds a lot of power to Sahi scripts. Sahi scripts can directly call Java code in scripts.

Isn’t it wonderful that you can leverage the power of Java libraries and APIs directly from your Sahi Script? Add to it, the power of Relational APIs like _near, _rightOf, _under and you will be surprised at how easy it is to use Sahi.

Have you used Sahi Pro? Which features are your favorite? I have listed my favorite five. Let me know your favorite ones in the comments.

If you are new to Sahi Pro, check out the weekly webinar at

Stable accessors/locators using UI Relations

Posted by | Sahi, stable tests, ui relations, web automation, web testing, xpath | No Comments

Identification of elements in a web interface is one of the toughest challenges of software UI automation. First came accessing by location (x,y coordinates), which quickly faded away due to window resolutions, rendering differences etc. Then came the concept of identification using code structure. XPath became hugely popular;

Reasons being

  1. Automation was only attempted by established developers and they understood XPaths
  2. 5 years back web applications were simple enough to easily look at the DOM and identify XPaths.
  3. Some (silly!) tools adopted and hugely promoted XPaths for want of innovation on that front.

But XPaths quickly became notorious for being unmaintainable and difficult to understand. If test automation was to spread to non-programmer testers, this would be a huge barrier. Tools then tried to move on to css-selectors, which is still complex for the target test automation teams.

So what could be a possible solution? The answer is in the User Interface.

What is often forgotten in the software industry, is that applications are built to satisfy business needs. So whatever the id, XPath or css-selector is, a textbox meant for “loan amount” will always be near some label saying “Loan Amount”. An expand or collapse icon in a tree gets its meaning from the attached “User name” label for that node. These business requirements do not change as often as code or underlying HTML structure. An HTML table may get converted to an ext-js grid with scrollbars, but the cost will still be associated (and aligned) with a product and listed under the heading “Cost”. Items related to each other would be shown inside a box with an appropriate heading.

How can we use this information to identify elements? Use UI relations for identification. Sahi, which has been a pioneer in web-automation innovation, handles it as below:

A textbox meant for “loan amount” becomes

_textbox(0, _near(_label("Loan Amount")))


browser.textbox(0).near(browser.label("Loan Amount"))

The cost becomes
_cell(0, _near(_div("My product one")), _under(_div("Cost")))
The expand collapse icon becomes
_image("/tree-node-icon/", _near(_span("Expand me")))

  1. These accessors clearly communicate what the intention of the accessor is, in a straight forward way (within the constraints of programming language constructs).
  2. These also take away the complexity in identifying and stabilizing XPaths, or understanding complex css-selectors, or writing custom javascript loops to accomplish the same thing.
  3. They are quite stable. _near allows for more elements to come between two related elements, _under is spatially aligned. So you can move different elements around on the UI and still have your scripts working properly.

UI Relations are guaranteed to exist in any business application, irrespective of whether you have ids or not.

One argument that comes up is, what if there are two similar elements which satisfy the same condition. While it is still possible to index the similar accessors and uniquely identify them, it seldom happens in a real world application. If you have two textboxes near “Loan amount”, it is going to confuse your end user. User-interfaces do not generally have such anomalies. That said, an added index to the accessor handles that scenario too, if it arises.

There is one other simplification that Sahi does in its accessor APIs. It does not explicitly state what the identifying property is. For example what could have been
is simply given as
_textbox("username") in Sahi.

Why? Because there are very few cases where one textbox has name=”username” and another has id=”username”. Such naming would obviously confuse the web developer forcing him to not do something like this.

Combined with UI relations, Sahi also takes care of automatically waiting for AJAX requests and page loads. This makes for robust scripts which hardly have unexpected failures. Other features like parallel playback of suites, automatic report generation, ant integration etc. make Sahi one of the most advanced web testing tools in the industry.

If you have not tried it yet, download from now. You can also use Sahi from inside ThoughtWorks Studios Twist or PushToTest’s TestMaker 6.

Use fully-loaded Sahi Pro FREE for a month. Download Now Request a Demo