1
votes

I am trying to run the following Python 2.7.10 code on Win7:

from robot import run

run("Login.robot", variable=['USERNAME:[email protected]'])

Login.robot is a very simple robot framework test that opens a browser window, loads our log in page, enters in a username and password, then confirms the user has logged in. I have tested it by running it from the command line with pybot and the test suite runs correctly. But trying to run the test suite from this script generates

Traceback (most recent call last):
  File "C:\Users\dmdunn\Desktop\test_user_data.py", line 4, in <module>
run("Login.robot", variable=['USERNAME:[email protected]'])
  File "C:\Python27\lib\site-packages\robot\run.py", line 471, in run
return RobotFramework().execute(*datasources, **options)
  File "C:\Python27\lib\site-packages\robot\utils\application.py", line 83, in execute
return self._execute(list(arguments), options)
  File "C:\Python27\lib\site-packages\robot\utils\application.py", line 96, in _execute
details, rc=FRAMEWORK_ERROR)
  File "C:\Python27\lib\site-packages\robot\utils\application.py", line 110, in _report_error
self._logger.error(message)
  File "C:\Python27\lib\site-packages\robot\output\loggerhelper.py", line 59, in error
self.write(msg, 'ERROR')
  File "C:\Python27\lib\site-packages\robot\output\loggerhelper.py", line 62, in write
self.message(Message(message, level, html))
  File "C:\Python27\lib\site-packages\robot\output\logger.py", line 109, in message
logger.message(msg)
  File "C:\Python27\lib\site-packages\robot\output\monitor.py", line 66, in message
self._writer.error(msg.message, msg.level, clear=self._running_test)
  File "C:\Python27\lib\site-packages\robot\output\monitor.py", line 142, in error
self._highlight('[ ', level, ' ] ' + message, error=True)
  File "C:\Python27\lib\site-packages\robot\output\monitor.py", line 158, in _highlight
self._write(before, newline=False, error=error)
  File "C:\Python27\lib\site-packages\robot\output\monitor.py", line 154, in _write
stream.flush()
IOError: [Errno 9] Bad file descriptor

Any suggestions? I've tried using an absolute path to the robot file, single quotes, double quotes, referencing via an open file object, referencing via a closed file object. Thanks!

2
I can't duplicate your problem. Your code ran exactly as posted for me on a linux box.Bryan Oakley
Well, at least now I know it's a Windows problem.Dawn-Marie Dunn

2 Answers

0
votes

I discovered it was due to using IDLE, which prevented robot framework from writing to the console. My script runs when started from the Windows command line.

0
votes

Open a file handle and call robot.run method inside while handle is open. I hope this will solve your issue.

mydir = os.path.join('c:/','....')
os.makedirs(mydir)    
with open('mydir', 'w') as stdout_file:
            k = run("Login.robot", 
                     variable=['USERNAME:[email protected]'],
                     stdout=stdout_file)