Calling python script from Test Complete
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2014
12:12 AM
05-23-2014
12:12 AM
Calling python script from Test Complete
Hi
I am looking to call python script from Test complete.
Is this possible?
If not, then can I call a python script from a jscript?
Means that, this jscript will be called into the test complete which in turns finally call that python script.
is this possible?
If still not, is there any other possible way?
Looking forward to someones reply.
Regards,
Ritesh Chauhan
I am looking to call python script from Test complete.
Is this possible?
If not, then can I call a python script from a jscript?
Means that, this jscript will be called into the test complete which in turns finally call that python script.
is this possible?
If still not, is there any other possible way?
Looking forward to someones reply.
Regards,
Ritesh Chauhan
5 REPLIES 5
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2014
12:19 AM
05-23-2014
12:19 AM
Sys.OleObject("WScript.Shell").Run("C:\\Python27\\python.exe C:\\myfile.py");
Gennadiy Alpaev
Software Testing Automation Tips - my new book
TestComplete Cookbook is published!
About Community Experts
Gennadiy Alpaev
Software Testing Automation Tips - my new book
TestComplete Cookbook is published!
About Community Experts
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2014
08:32 PM
05-23-2014
08:32 PM
Hello Gena,
Thanks for your reply.
I tried this but didn't worked out for me.
Sys.OleObject("WScript.Shell").Run("C:\\Python27\\python.exe C:\\myfile.py");
I have attached a sample python script (its in txt format, please change this into.py as this format was not attachable) which i tried to execute via TestComplete. This script generates a .txt file.
My python file: test.py
Path where it is placed: C:\\
Output of this python file: test.txt
I placed this test.py file in C:\ and then used below function in TestComplete as you suggested
Sys.OleObject("WScript.Shell").Run("C:\\Python27\\python.exe C:\\test.py");
But the output file test.txt didn't get generated.
Please advice.
Regards,
Ritesh Chauhan
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2014
08:52 PM
05-25-2014
08:52 PM
Because your Python script doesn't explicitly specify the file folder, it creates the file in the current working folder, which in case of TestComplete is the project folder (where the .mds file is).
To create a file in a specific folder, you can do any of these:
1) Use the full file path in your Python script.
2) Use the aqFileSystem.SetCurrentFolder method to set the current working folder:
3) Specify the working folder in the command line:
Note: If you use Windows Vista+ and create the file in C:\, you need to run TestComplete as an Administrator.
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
To create a file in a specific folder, you can do any of these:
1) Use the full file path in your Python script.
2) Use the aqFileSystem.SetCurrentFolder method to set the current working folder:
aqFileSystem.SetCurrentFolder("C:\\");
Sys.OleObject("WScript.Shell").Run("C:\\Python27\\python.exe C:\\test.py");
3) Specify the working folder in the command line:
Sys.OleObject("WScript.Shell").Run("cmd /c cd C:\\ && C:\\Python27\\python.exe C:\\test.py");
Note: If you use Windows Vista+ and create the file in C:\, you need to run TestComplete as an Administrator.
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2014
11:42 PM
05-26-2014
11:42 PM
Thanks a lot Helen!
It worked 🙂
Here is the code:
function Test()
{
aqFileSystem.SetCurrentFolder("C:\\");
Sys.OleObject("WScript.Shell").Run("C:\\Python27\\python.exe C:\\test.py");
Sys.OleObject("WScript.Shell").Run("cmd /c cd C:\\ && C:\\Python27\\python.exe C:\\test.py");
}
Regards,
Ritesh Chauhan
It worked 🙂
Here is the code:
function Test()
{
aqFileSystem.SetCurrentFolder("C:\\");
Sys.OleObject("WScript.Shell").Run("C:\\Python27\\python.exe C:\\test.py");
Sys.OleObject("WScript.Shell").Run("cmd /c cd C:\\ && C:\\Python27\\python.exe C:\\test.py");
}
Regards,
Ritesh Chauhan
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2014
08:01 PM
05-27-2014
08:01 PM
Glad to help!
Just one note - your code runs the Python script twice. Use either SetWorkingFolder + Run("C:\\..."), or just Run("cmd /c ..."), not both.
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Just one note - your code runs the Python script twice. Use either SetWorkingFolder + Run("C:\\..."), or just Run("cmd /c ..."), not both.
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
