RaiMan / SikuliX1

SikuliX version 2.0.0+ (2019+)
https://sikulix.github.io
MIT License
2.78k stars 356 forks source link

Java: Run python scripts directly from java program #492

Open Phreag opened 2 years ago

Phreag commented 2 years ago

I have some .sikuli scripts created with the SikuliX IDE. These Scripts will do some testing on a GUI of a custom program. I have written a small java application which manages all my tests and does some small setup (setting paths in sites.txt, preparing a clean launched app,ication for each test). By now i can only use the Java ProcessBuilder to run my tests and retrieve a result:

Example: ProcessBuilder pb = new ProcessBuilder("java", "-jar", sikuliXPath + "\Sikulix.jar", "-v", "-f", currentDir + "/logs/" + startTime + "/" + testToRun.getName() + ".log", "-r", testToRun.getSikuliXScriptFile().getAbsolutePath() ); pb.directory(new File(currentDir)); pb.inheritIO(); Process proc = pb.start(); proc.waitFor(); if (proc.exitValue() == exitCodeSuccess) { success = true; }

This allows me to run a huge bunch of tests completely independent from each other. But it would be more comfortable if i could just use a methode linke Sikulix.run(String[] args) and it will throw an Exception or return a number as return code. But since sikuliX uses System.exit it will also close my application.

Is there a possibility to have this feature in a future version?

RaiMan commented 2 years ago

Did you try to solve this on the Python level as well? Should be possible. Another option would be to use the server feature.

I will have a look into it.

Phreag commented 2 years ago

No, i did not try it with python. The server also seemed a good solution, but i did not get it to work properly with my advanced logging. I use a custom return code (42) on my scripts to indicate that they have finished without errors. When i do not receive this return code form the process my test management tool takes a screenshot and saves it for further investigation.

RaiMan commented 2 years ago

ok, thanks.

RaiMan commented 2 years ago

Just tested with the server feature:

curl http://192.168.178.26:50001/RUN/serverTest                    
PASS 200 runScript: returned: 42

So you might have a chance to check your return code.

RaiMan commented 2 years ago

BTW: 42 = The Hitchhiker's Guide to the Galaxy/Douglas Adams ? ;-)

Phreag commented 2 years ago

Thanks, i will check that... And yes, the Answer to the Ultimate Question of Life, the Universe, and Everything ;)