1

I am trying to execute my .bat script in robot framework. I looked at this answer on stackoverflow. But the question didn't really get a correct answer. I have tried to run:

*** Settings ***
Library    Process

*** Test Case ***
Launch Bat File
    Run Process       ${CURDIR}/script.bat

I got error: [WinError 2] The system cannot find the file specified

I then tried:

*** Settings ***
Library    OperatingSystem

*** Test Case ***
Lauch Bat File
    Run       ${CURDIR}/script.bat

The test passed, but nothing was executed

Next I tried inputting my script.bat as a resource:

*** Settings ***
Library    OperatingSystem
Resource  ${CURDIR}/script.bat

*** Test Case ***
Lauch Bat File
    Run       ${CURDIR}/script.bat

Error: Unsupported file format 'bat'.

I'm unsure about the first two errors. But for the "unsupported .bat" error, I downloaded the automatic plugins that PyCharm told me to in order to support my bat file. What am I missing here?

9
  • Have you tried the Run Process keyword in the Process Library? Commented Aug 3, 2020 at 17:01
  • You sure the path is correct, and the .bat script is correct, and it actually does something so you can observe it? Commented Aug 3, 2020 at 17:05
  • @A.Kootstra: it's in the first example Commented Aug 3, 2020 at 17:06
  • Run and Run Process are different keywords, and part of different libraries. Commented Aug 3, 2020 at 17:11
  • 1
    @pavelsaman Thanks for the clarifying questions. So the .bat script is supposed to generate Robotframework metrics after execution of my tests. This way I don't have to type: robot Tests/* && robotmetrics everytime. The reason why I wrote a new test case is to narrow down my problem for you guys: My problem being that I cannot execute a .bat script Commented Aug 3, 2020 at 19:29

1 Answer 1

1

If I take the comments into account, I'll answer the question like this.

My example RF test suite looks like:

test.robot

*** Test Cases *** 
Log
    Log To Console    abc        

I've created a .bat file with the following content:

test-and-report.bat

@echo off
robot test.robot && robotmetrics

Now I can run > test-and-report.bat, which runs the test and then creates a robotmetrics report in the same directory.


However, your original question was about how to run a .bat file form RF. I don't think you want to do this in this situation, but I'll demonstrate it anyway.

test.robot

*** Settings ***
Library    Process    

*** Test Cases *** 
Open Chrome
    Run Process    ${CURDIR}/open-chrome.bat      

And the .bat file.

open-chrome.bat

@echo off
start chrome

Then I can run: > robot test.robot from the same directory where test.robot is present and Chrome will open.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for this. I really appreciate it. And it looks like you are right about not using RF for executing the .bat file. I messaged the developer himself about his code and he said not to use RF to execute the .bat file but to use the terminal instead. So the answers given here stackoverflow.com/questions/50924613/… will not work.
@JasonMason: And the first approach without RF works? Or are you experiencing some problems/errors?
Sorry for the delayed response. Yes, it works perfectly with no problems. You're awesome!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.