Understanding Sahi Pro Architecture

Core Components

  • Sahi Controller: The browser overlay used during test recording and debugging.
  • Sahi Script Engine: Executes Sahi scripts (.sah) and manages browser interaction.
  • Sahi Dashboard: Provides scheduling, test suite execution, and reporting features.
  • Launcher/Runner: Executes tests in headless or CI-integrated mode via command line or API.

How It Works

Sahi operates as a proxy-based tool, intercepting browser traffic to inject automation code. This architecture is sensitive to browser updates, proxy settings, and dynamic DOM behaviors, all of which can cause subtle test failures.

Common Enterprise-Grade Issues

1. Inconsistent Element Identification

Sahi relies on APIs like _setValue() or _click() with loosely typed identifiers. In dynamic SPAs, DOM shifts or duplicated labels can cause Sahi to select the wrong element.

2. Proxy Configuration Failures

Since Sahi injects JavaScript through a proxy, misconfigured environments (especially in VPNs or secure zones) can block proxy routing, breaking script execution entirely.

3. License Validation Errors

Sahi Pro checks its license validity periodically. Clock skew, VM snapshots, or invalid hostname configurations can cause tests to fail silently or with vague errors.

4. Browser Update Incompatibility

Automated tests may break after browser updates (especially Chrome or Edge), due to changes in rendering behavior or JavaScript execution. Sahi patches may be required.

Diagnostic Workflow

Step 1: Enable Verbose Logging

userdata.properties
debug=true
loglevel=3

-- Logs location:
/userdata/logs/

Look for lines like:

Could not identify element using API: _click(_link("Submit"))

Step 2: Use the Highlight Utility

Use _highlight() in your script to debug incorrect element selections:

_highlight(_textbox("username"))

This confirms if Sahi's locator matches the expected element at runtime.

Step 3: License and Machine Fingerprint Validation

-- Run license diagnostics:
sahi.sh license-info

-- Check logs for:
"License check failed: Fingerprint mismatch"

Ensure hostnames and MAC addresses have not changed unexpectedly on virtual machines.

Step 4: Validate Proxy Injection

From browser:

Navigate to http://localhost:9999/sahi.js

If this fails, the proxy is not injecting, possibly due to:

  • Custom firewall or antivirus
  • Improper proxy settings in browser
  • Network stack corruption

Step-by-Step Fixes

1. Stabilize Element Selection

-- Replace ambiguous locators:
_click(_link("OK"))

-- With indexed or parent-scoped locators:
_click(_in(_div("modal"), _link("OK")))

Use _near() or _in() to disambiguate elements with duplicate labels.

2. Reconfigure Proxy Settings

-- Configure proxy manually:
browser.network.proxy.type=1
browser.network.proxy.http=localhost
browser.network.proxy.http_port=9999

Avoid browser auto-configuration (PAC) when using Sahi.

3. Fix License-Related Failures

-- Resync system clock (especially after VM suspend):
sudo ntpdate time.google.com

-- Re-register license if needed:
sahi.sh register-license

4. Roll Back or Patch for Browser Updates

If tests break after an update:

  • Downgrade to known working browser version
  • Request patch from Sahi support
  • Run tests in dedicated Dockerized environments

Common Pitfalls

  • Overusing default APIs without dynamic wait strategies
  • Not validating locators under all DOM states (loading, error, modal)
  • Ignoring hostname and MAC changes in VM images used for execution
  • Using Sahi without headless browser isolation in CI/CD pipelines

Best Practices for Enterprise Stability

  • Use dynamic waits like _wait(), _exists() instead of hardcoded delays
  • Group reusable locator logic in functions or modules
  • Use version control for Sahi scripts and configuration
  • Automate test triggers via REST APIs or command-line runner
  • Regularly sync browser versions with approved Sahi patches

Conclusion

Sahi Pro is ideal for web automation in dynamic environments, but its proxy-based model and license enforcement introduce unique challenges in enterprise-scale pipelines. By understanding the root causes of common issues—such as selector ambiguity, proxy interference, and environmental drift—teams can proactively harden their test suites. Coupled with proper logging, versioning, and modular scripting practices, Sahi Pro can be an extremely reliable tool for continuous testing success.

FAQs

1. Why is Sahi not clicking the right element?

It likely matched an unintended duplicate element. Use _near(), _in(), or unique attribute-based locators for precision.

2. How do I fix proxy injection issues?

Ensure Sahi's proxy port (9999) is open, not blocked by antivirus/firewall, and correctly set in browser configuration.

3. Can I run Sahi tests in parallel?

Yes, using multiple browsers and data-driven runners, but tests must be stateless and avoid shared global context.

4. Why do license errors appear after a VM restart?

Clock drift or changes in hardware fingerprint (e.g., MAC address) can invalidate licenses. Revalidate via sahi.sh license-info.

5. Is Sahi Pro compatible with CI tools like Jenkins?

Yes, via command-line integration or REST APIs. Use headless mode with log parsing for CI-friendly test feedback.