18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
Reading javascript variables in sahi
Hi -
OS - Windows 7 64 bit
Browser - IE 8
Sahi - build 3.5
We are trying to validate a button on the brower which opens a pdf letter. When you click on the button it opens up a new window with the pdf file displayed. Now we want to automate and make sure the URL that the button opens up is a correct one and there are no 404, 401 errors.
We wrote sahi script to click on the button but since the button generates a dynamic URL to the pdf letter sahi clicks on the link and says success. We are not able to assert it.
One other way is to generate the URL and then see if it navigates. For that the browser has the following value
<input type=hidden name="param1" value="abc"/>
<javascript>
var token="mTYUiOPsAsdad7yuDadd"
--- other javasript functions ..
--
</javascript>
We need to create a url like https://www.fadv.com/lettergen?param1=\"abc\"&token=\"mTYUiOPsAsdad7yuDadd\".
Can someone tell me how to read a variable inside a </javascript> block or is there any other better way to test this in SAHI
Thanks
Vinod
OS - Windows 7 64 bit
Browser - IE 8
Sahi - build 3.5
We are trying to validate a button on the brower which opens a pdf letter. When you click on the button it opens up a new window with the pdf file displayed. Now we want to automate and make sure the URL that the button opens up is a correct one and there are no 404, 401 errors.
We wrote sahi script to click on the button but since the button generates a dynamic URL to the pdf letter sahi clicks on the link and says success. We are not able to assert it.
One other way is to generate the URL and then see if it navigates. For that the browser has the following value
<input type=hidden name="param1" value="abc"/>
<javascript>
var token="mTYUiOPsAsdad7yuDadd"
--- other javasript functions ..
--
</javascript>
We need to create a url like https://www.fadv.com/lettergen?param1=\"abc\"&token=\"mTYUiOPsAsdad7yuDadd\".
Can someone tell me how to read a variable inside a </javascript> block or is there any other better way to test this in SAHI
Thanks
Vinod
Comments
What you can do is you can download the pdf and do assertion on the last downloaded file using _lastDownloadedFileName() API.
Here is the documentation for how to handle file downloads:
http://sahi.co.in/w/handle-file-downloads
Let me know if you face any problem.
Regards
Sumitra
The generated PDF is shown in a separate window and i cannot download it. when the button is clicked the browser generates a URL like this
https://abc.com/render?q_disputeProcessID=6936926&q_disputeActionTypeID=3&FCRAListValue=Y&page_handler=MEYwTTB0M3Y0WTEzMjIwNTU4MjM3NTkhMzM1MTU4NA%3D%3D
and this gets opened in a new browser. All the values in this URL are dynamic and these values are passed from the server in the format mentioned below
<input type=hidden name="q_disputeProcessID" value="6936926"/>
<input type=hidden name="q_disputeActionTypeID" value="3"/>
<input type=hidden name="FCRAListValue" value="Y"/>
<javascript>
var token="MEYwTTB0M3Y0WTEzMjIwNTU4MjM3NTkhMzM1MTU4NA%3D%3D"
--- the javascript here will construct the above url and submit it
--
</javascript>
Thanks
Vinod
If the pdf is shown in a different window then you can force Sahi to download it by adding:
application/pdf
application/x-pdf
application/acrobat
applications/vnd.pdf
text/pdf
text/x-pdf
to sahi/userdata/config/download_contenttypes.txt.
Now you should be able to download the pdf file.Once the pdf is downloaded ,do assertion on the last downloaded file using _lastDownloadedFileName() API.
For more Details:
http://sahi.co.in/w/handle-file-downloads
Let me know if you face any problem.
Regards
Sumitra
For example, you can do
_alert(token)
or
var $token = ""
_set($token, token);
var $url = "https://www.fadv.com/lettergen?param1=abc&token=" + $token;
_alert($url);