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.
how to create new file using sahi ?
Dear All,
Can Anybody tell me how to create new file in sahi ?
I am running sahi in linux.
thanks in advance.
Can Anybody tell me how to create new file in sahi ?
I am running sahi in linux.
thanks in advance.
This discussion has been closed.
Comments
Sahi is Browser and Operating System independent so it is the same way as for the other OS.
Could you please let me know what file creation are you talking about?
If it is creating a .sah file in linux machine then it is the same as other OS.
You have start Sahi >> Open the controller( Ctrl+Alt double click on the browser) >> mention the script name( it will be saved in <sahi-home>/userdata/scripts folder with an extension of .sah) >> Click on Record.
Let me know if you face any problem.
Regards
Sumitra
I thing you misunderstand the thing.
I know how to create sahi file, but while i executing sahi scripts how can i create file and directory ?
_writeFile and _writeToFile API is to write into file that is already created. but if i want to create one new file and also directory during run time, how can i do that thing ?
hope now my question is cleared.
Thanks in advance.
You dont have to create a separate file to write the contents into it. You can use : _writeFile() or _writeToFile() API to directly write the contents into the specified file path.
Here is the explanation:
_writeFile(text, filePath[, overwrite]);
If you want to write abc content in some file which is in C:\\trial.txt, then _writeFile() API itself creates the file in C drive and writes the abc in trial.txt.
The usage would be:
_writeFile("abc", "C:\\trial.txt");
The _writeToFile() API is same as _writeFile() API.
Let me know if you face any problem.
Regards
Sumitra
I am not able to create the file using the above API.
I had tried those thing already but not able to create the file.
I am using Ubuntu and my syntax in sahi script is shown below:
_writeToFile("hi","/home/parth/sahi/userdata/scripts/Factory_Reset/LogFileName");
or
var $LogFileName="/home/parth/sahi/userdata/scripts/Factory_Reset/LogFileName";
_writeToFile("hi",$LogFileName);
Can you give me some other way to create the file and directory ?
As in the morning, when I have seen your post you had given some post in which "java." was given but now u had given the post with _writeFile Function.
Can u show me that "java" way ?
DEBUG:
While in sahi controller "View Parsed Script" is shown below:
_sahi._writeToFile("hi","/home/parth/sahi/userdata/scripts/Factory_Reset/LogFileName");
but then also it is not creating any file.
With Regards,
Parth Shah.
You need to mention full path to the file and you have to mention type of the file.
It should be:
_writeToFile("hi","C:/home/parth/sahi/userdata/scripts/Factory_Reset/LogFileName.txt");
OR
var $LogFileName="C:/home/parth/sahi/userdata/scripts/Factory_Reset/LogFileName.txt";
_writeToFile("hi",$LogFileName);
In the other way , you will have to create the file explicitly using:
var $dir = new java.io.File("C:\\path\to\\folder");
$dir.createNewFile();
And now you will have to use _writeFile() API.
Its suggested to use _writeFile() API which will create a file and write the contents to the mentined file path.
Let me know if this solves your issue.
Regards
Sumitra
It works for me.
Thank you very much.