ThoughtWorks
  • Contact
  • Español
  • Português
  • Deutsch
  • 中文
Go to overview
  • Engineering Culture, Delivery Mindset

    Embrace a modern approach to software development and deliver value faster

    Intelligence-Driven Decision Making

    Leverage your data assets to unlock new sources of value

  • Frictionless Operating Model

    Improve your organization's ability to respond to change

    Platform Strategy

    Create adaptable technology platforms that move with your business strategy

  • Experience Design and Product Capability

    Rapidly design, deliver and evolve exceptional products and experiences

    Partnerships

    Leveraging our network of trusted partners to amplify the outcomes we deliver for our clients

Go to overview
  • Automotive
  • Cleantech, Energy and Utilities
  • Financial Services and Insurance
  • Healthcare
  • Media and Publishing
  • Not-for-profit
  • Public Sector
  • Retail and E-commerce
  • Travel and Transport
Go to overview

Featured

  • Technology

    An in-depth exploration of enterprise technology and engineering excellence

  • Business

    Keep up to date with the latest business and industry insights for digital leaders

  • Culture

    The place for career-building content and tips, and our view on social justice and inclusivity

Digital Publications and Tools

  • Technology Radar

    An opinionated guide to technology frontiers

  • Perspectives

    A publication for digital leaders

  • Digital Fluency Model

    A model for prioritizing the digital capabilities needed to navigate uncertainty

  • Decoder

    The business execs' A-Z guide to technology

All Insights

  • Articles

    Expert insights to help your business grow

  • Blogs

    Personal perspectives from ThoughtWorkers around the globe

  • Books

    Explore our extensive library

  • Podcasts

    Captivating conversations on the latest in business and tech

Go to overview
  • Application process

    What to expect as you interview with us

  • Grads and career changers

    Start your tech career on the right foot

  • Search jobs

    Find open positions in your region

  • Stay connected

    Sign up for our monthly newsletter

Go to overview
  • Conferences and Events
  • Diversity and Inclusion
  • News
  • Open Source
  • Our Leaders
  • Social Change
  • Español
  • Português
  • Deutsch
  • 中文
ThoughtWorksMenu
  • Close   ✕
  • What we do
  • Who we work with
  • Insights
  • Careers
  • About
  • Contact
  • Back
  • Close   ✕
  • Go to overview
  • Engineering Culture, Delivery Mindset

    Embrace a modern approach to software development and deliver value faster

  • Experience Design and Product Capability

    Rapidly design, deliver and evolve exceptional products and experiences

  • Frictionless Operating Model

    Improve your organization's ability to respond to change

  • Intelligence-Driven Decision Making

    Leverage your data assets to unlock new sources of value

  • Partnerships

    Leveraging our network of trusted partners to amplify the outcomes we deliver for our clients

  • Platform Strategy

    Create adaptable technology platforms that move with your business strategy

  • Back
  • Close   ✕
  • Go to overview
  • Automotive
  • Cleantech, Energy and Utilities
  • Financial Services and Insurance
  • Healthcare
  • Media and Publishing
  • Not-for-profit
  • Public Sector
  • Retail and E-commerce
  • Travel and Transport
  • Back
  • Close   ✕
  • Go to overview
  • Featured

  • Technology

    An in-depth exploration of enterprise technology and engineering excellence

  • Business

    Keep up to date with the latest business and industry insights for digital leaders

  • Culture

    The place for career-building content and tips, and our view on social justice and inclusivity

  • Digital Publications and Tools

  • Technology Radar

    An opinionated guide to technology frontiers

  • Perspectives

    A publication for digital leaders

  • Digital Fluency Model

    A model for prioritizing the digital capabilities needed to navigate uncertainty

  • Decoder

    The business execs' A-Z guide to technology

  • All Insights

  • Articles

    Expert insights to help your business grow

  • Blogs

    Personal perspectives from ThoughtWorkers around the globe

  • Books

    Explore our extensive library

  • Podcasts

    Captivating conversations on the latest in business and tech

  • Back
  • Close   ✕
  • Go to overview
  • Application process

    What to expect as you interview with us

  • Grads and career changers

    Start your tech career on the right foot

  • Search jobs

    Find open positions in your region

  • Stay connected

    Sign up for our monthly newsletter

  • Back
  • Close   ✕
  • Go to overview
  • Conferences and Events
  • Diversity and Inclusion
  • News
  • Open Source
  • Our Leaders
  • Social Change
Blogs
Select a topic
View all topicsClose
Technology 
Agile Project Management Cloud Continuous Delivery  Data Science & Engineering Defending the Free Internet Evolutionary Architecture Experience Design IoT Languages, Tools & Frameworks Legacy Modernization Machine Learning & Artificial Intelligence Microservices Platforms Security Software Testing Technology Strategy 
Business 
Financial Services Global Health Innovation Retail  Transformation 
Careers 
Career Hacks Diversity & Inclusion Social Change 
Blogs

Topics

Choose a topic
  • Technology
    Technology
  • Technology Overview
  • Agile Project Management
  • Cloud
  • Continuous Delivery
  • Data Science & Engineering
  • Defending the Free Internet
  • Evolutionary Architecture
  • Experience Design
  • IoT
  • Languages, Tools & Frameworks
  • Legacy Modernization
  • Machine Learning & Artificial Intelligence
  • Microservices
  • Platforms
  • Security
  • Software Testing
  • Technology Strategy
  • Business
    Business
  • Business Overview
  • Financial Services
  • Global Health
  • Innovation
  • Retail
  • Transformation
  • Careers
    Careers
  • Careers Overview
  • Career Hacks
  • Diversity & Inclusion
  • Social Change
Software TestingTechnology

An introduction to Sahi: Part 1

ThoughtWorks ThoughtWorks

Published: Jan 11, 2011

Sahi is an automation and testing tool for web applications. Different from many other commercial testing tools, Sahi is an open source tool. As an automation tool, Sahi provides the facility of recording and play backing of scripts. Sahi supports Java and JavaScript. Even though the Sahi script looks like JavaScript, it is not executed as the regular JavaScript on the browser.

Introduction

Sahi is an automation and testing tool for web applications. Different from many other commercial testing tools, Sahi is an open source tool. As an automation tool, Sahi provides the facility of recording and play backing of scripts. Sahi supports Java and JavaScript. Even though the Sahi script looks like JavaScript, it is not executed as the regular JavaScript on the browser.

The basic idea of how Sahi work is described below: Sahi's core parts include the Sahi proxy server and the JavaScript engine.

HTML responses which pass through the proxy are modified such that JavaScript is injected at the start and the end of the response. This will allow the browser to record and playback scripts and talk back to the proxy when needed. Apart from handling requests for pages that the browser requests, Sahi also handles custom commands related to recording, playback etc. which the browser sends.

Besides the normal features like supporting ant, Sahi has its own features, like good support of database files, supporting JavaScript, AJAX and also the simple APIs.

Why Sahi

Compared to other web testing tools, Sahi controller (IDE) can be used in various browsers.

Sahi's APIs do not depend much on the HTML structure. Sahi does not use XPaths and has APIs like _near, _in etc. to help finding one element in relation to another. Even if the structure of the page changes, these work properly. Our client website is an ExtJS site; Sahi is helpful in dealing with the changing pages.

Getting Started

First of all, we can download the latest Sahi zip file from sourceforge. The prerequisite for Sahi is JRE 1.4 or above.

  • Unzip sahi.zip to a desired location.
  • Navigate to \bin to start sahi proxy server.
  • Next, config the browser to use sahi proxy.

After finishing the setup, we can start creating scripts. The scripts can be written using any text editor with the facility of recording by controller. Press ALT and double click on the window, which you want to record.

The controller is as below:

Recording

  • On the popup that appears, give a name for the script you wish to generate, and click 'Record'
  • Most actions on the page will now get recorded.
  • Moving the mouse over any html element while pressing Ctrl key will show the JavaScript accessor info in the popup.
  • Clicking the "Add Assertions" button generates assertions for the element. These assertions can be added to the script by clicking "Add to Script".The script being generated can be viewed by opening the .sah file in the scripts directory. The script can be edited even while recording, so that logical segregation into functions etc. can be done while recording happens.
  • Once done, click stop.

Note that custom code can be tested, by entering code in the "debug" text area and clicking on "Test->". The command will be executed and the result will be displayed in the textbox near the” Test->"button.

Once confirmed that the desired result has been achieved, that code snippet can be added to the recording by clicking "Append to Recording".

Script Playback

  • Open (alt-dblclick) the popup window.
  • Select script file from the dropdown.
  • Or go to the "[from url]" section and specify the full URL of the script file. (e.g. http://proxyhost:proxyport/_s_/scrcipts/scriptName.sah)
  • Click 'Set'.
  • Wait for the pages to reload.
  • Click 'Play'.

Test Suite

Multiple tests can be run through ant. For each test in the suite, the ant target opens a browser, runs the test and closes the browser. The ant target specifies a suite file, say SuiteName.suite.

Data Driven Testing

Sahi has some inbuilt features for data driven testing. Sahi can read and write to CSV (Comma Separated Value) files, databases and Excel sheets.

  • _readCSVFile (csvFilePath) reads a CSV file and returns a two dimensional array.
  • _writeCSVFile (array2D, filePath) writes the two dimensional array into a file in CSV format.

What's next?

View Sahi in-detail with more examples in part 2 of this article.

  • What we do
  • Who we work with
  • Insights
  • Careers
  • About
  • Contact

WeChat

×
QR code to ThoughtWorks China WeChat subscription account

Media and analyst relations | Privacy policy | Modern Slavery statement ThoughtWorks| Accessibility | © 2021 ThoughtWorks, Inc.