How to create the log file before finishing the test cases

Hi Fellas, greetings!

I’m building a keyword that will turn the computer off when all the test cases finishes. But if I do that I gonna loose all the generated logs during the tests because it is saved only when the tests finishes. So my question is… do somenone know if it is possible to create the log files before finishin the test or if is there some library I can use to do that? I have searched on the internet but didn’t find anything about that… thanks in advance for your help!

Why not making your keyword waiting for the logs to be completed?

Hi Rafael,

The problem you will face here is if the shutdown happens successfully before RF is finished the logs won’t be written, it’s similar to the threads where people were trying to upload the RF logs before RF finished, logs don’t get written till after execution and teardown is finished.

As a suggestion, instead of having the keyword shutdown the computer, have the keyword schedule a shutdown the computer using the OS scheduler to run the actual shutdown command.

You could then schedule the shutdown time for 5 or 10 min after the keyword ran so that there is time for RF to finish executing and write logs and even potentially upload the logs somewhere.

A small difference in this keyword is that the pass would indicate the success of scheduling the shutdown rather the success of the actual shutdown.

Both windows and linux (I didn’t check MacOS it’s probably similar to Linux) have the ability to specify a time in the future for the shutdown to occur when using the command line, so it’s probably a matter of a small modification to what you have.

  • On Windows when calling shutdown use the /t 300 option for 5 min
  • On Linux when calling shutdown use the +5 option for 5 min

Hope this suggestion helps,

Dave.

Thanks dude! You helped very much…
I’m using the ssh library to execute the command shutdown in linux and all I had to do was to change the parameter “now” to “+5”(time to shutdown)…
I hadn’t thought about doing like this…
So now, it finishes the test cases and has the time to create all log files and so then turn the computer off…

In the beggining of base.robot file I call the library…
Library SSHLibrary

by the end of the file, I created the keyword…

Turn the Computer Off
[Documentation] turns the computer off after finishing the test cases

Open SSH Connection
Execute Command  shutdown -h +5  sudo=True  sudo_password=***
Close Connection

I have another keyword called ‘Open SSH Connection’ opening the SSH conection.

thank you very much for your help!

cheers!

1 Like

Hi dude!
I solved the problem just changing the parameter “now” to “+5” as Dave suggest and it works fine…

Thanks for your attention!
cheers!

1 Like

Hey Rafael,

I’m a little surprised you ssh’d into the machine you are running on to execute the shutdown command.
I would have used either Run Process or Run as those will let you execute the command without having to authenticate. But I guess if you need admin rights to shutdown the machine and you are running as a restricted user then the ssh method might be easier?

Anyway glad I could help :+1:t3:

Dave.