18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

how do i collect parameters from ANT build file in SAHI script?

shamsham Members
edited November -1 in Sahi - Open Source
Hi all,

I started automating some of my GUI tests using jenkins...
the flow is like this..
Jenkins defines a task and ANT executes it, ANT then calls testrunner.sh .
The SAHI file takes these parameters passed by ANT to execute the script.
But I'm having trouble passing parameters from ANT to SAHI script.

======= sample buildfile ========
<?xml version="1.0" encoding="ISO-8859-1"?>

<project name="nmv_tests" default="nmv-login" basedir=".">
<target name="data-suite" description="nmv data tests">
<exec executable="../nmv/run-all.sh" failonerror="true">
<env key="SAHI_HOME" value="${sahiHome}"/>
<env key="BROWSER" value="${browser}"/>
<env key="START_URL" value="http://${mutIP}:2000"/>
<env key="THREADS" value="${threads}"/>
<env key="SINGLE_SESSION" value="${singleSession}"/>
<env key="usernameValue" value="${usernameVal}"/>
<env key="passwordValue" value="${passwdVal}"/>
<env key="SCRIPTS_PATH" value="${scriptPath}"/>
<env key="Analytics_refreshValue" value="${refreshInterval}"/>
<env key="Analytics_timeout" value="${Timeout}"/>
</exec>
</target>
</project>
(All these values are obtained from jenkins job.)
========================================
run-all.sh
#!/bin/bash

# All parameters are supplied via the ANT buid.xml file

cd "$SAHI_HOME/userdata/bin"
./testrunner.sh $SCRIPTS_PATH $START_URL $BROWSER
=========================================
SAHI file that executes..
login($usernameValue, $passwordValue);
_navigateTo($analyticsSettingsURL);
CheckPageHeader();
var $RefreshIDTable = [$Analytics_refresh_intervalId];
var $RefreshValueTable = [$Analytics_refreshValue];
SetTextboxandRevert($RefreshIDTable, $RefreshValueTable, $Analytics_timeout, $analyticsSettingsURL);
logout();
==============================

Almost immediately the $usernameValue fails as reported by SAHI..

What am i doing wrong..
I'm new to ANT integration so any help pls

Comments

  • globalwormingglobalworming Moderators
    Hi

    haven't worked with jenkins yet, but it may help you to use the -initJS option on the testrunner. Unfortunately I have no idea how to make Jenkins print "key=value;" lines to add to -initJS.

    I hope this is at least a little bit to think about.
    Regards
    Wormi
  • shamsham Members
    hmm.. i did try but the thing is I"m not sure how to use it in ANT at all..
    There are no docs and since its quite new, cant seem to find any info on it either...

    Also there are more than one variables to be sent..
    so -initJS should be used multiple times..
    I"m not quite sure how to do it now.
    Anyone has idea guys? Its quite urgent
  • shamsham Members
    any updates on this guys?
  • globalwormingglobalworming Moderators
    -initJS takes an indefinit amount of javascript which will be executed befor each script, so -initJS "$constant1=10; $constant2='Str'" makes constant 1 and 2 accessible in every script. When you have to add more variables, just add them to the initJS.

    There must be a way to get ANT to print its values and use them as arguments for the testrunnen. Maybe ask google or stackoverflow?
  • shamsham Members
    This is not working...
    I looked at other post and i think I should use -jsInit, even in that case it's not working...
    here is my cmd line...
    java -cp ~/sahi/lib/ant-sahi.jar net.sf.sahi.test.TestRunner -test ~/jenkins/INTEGRATION/analytics/settings/settings.sah -browserType firefox -baseURL http://10.0.0.27:2000 -host localhost -port 9999 -threads 1 -useSingleSession false -jsInit "var $Analytics_refreshValue=3000; var $Analytics_timeout=3000;"

    I can see that the GUI comes up and login happens without hitch but when it comes to setting the values, namely Analytics_refreshValue , SAHI fails" saying variable $Analytics_refreshValue Not defined" in the logs...
    My sahi script has these exact same variables being listed in it as well.. but it does not work.
  • globalwormingglobalworming Moderators
    http://sahi.co.in/w/Running+multiple+tests+in+batch+mode

    "-initJS Any javascript which would be executed before every script"

    if the documentation us up to date, it should be -initJS
  • shamsham Members
    ok .. this is the cmd line..
    java -cp ~/sahi/lib/ant-sahi.jar net.sf.sahi.test.TestRunner -test ~/jenkins/INTEGRATION/analytics/settings/settings.sah -browserType firefox -baseURL http://10.0.0.27:2000 -host localhost -port 9999 -threads 1 -useSingleSession false -initJS "var $Analytics_refreshValue=3000;var $Analytics_timeout=3000;"

    Error i get is "Missing Variable Name"
  • shamsham Members
    ok great.. it works.. I had to escape $ that's all..
    Thanks for you're help.
Sign In or Register to comment.