IOError:[Errno 9]使用Python的机器人框架的错误文件描述符

时间:2015-10-09 19:13:29

标签: python-2.7 robotframework

我试图在Win7上运行以下Python 2.7.10代码:

from robot import run

run("Login.robot", variable=['USERNAME:testuser@fakemail.com'])

Login.robot是一个非常简单的机器人框架测试,它打开浏览器窗口,加载我们的登录页面,输入用户名和密码,然后确认用户已登录。我已经通过从命令运行它来测试它与pybot一致,测试套件运行正常。但是尝试从此脚本运行测试套件会生成

Traceback (most recent call last):
  File "C:\Users\dmdunn\Desktop\test_user_data.py", line 4, in <module>
run("Login.robot", variable=['USERNAME:testuser@fakemail.com'])
  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

有什么建议吗?我尝试使用机器人文件的绝对路径,单引号,双引号,通过打开的文件对象引用,通过关闭的文件对象引用。谢谢!

2 个答案:

答案 0 :(得分:0)

我发现这是因为使用了IDLE,这阻止了机器人框架写入控制台。我的脚本在从Windows命令行启动时运行。

答案 1 :(得分:0)

打开文件句柄并在句柄打开时调用robot.run方法。 我希望这能解决你的问题。

var moment = require('moment'),
    fs = require('fs'),
    json = [
        { "_id":"56d97671f6ad671b7d1c3d76", "parseId": "TdKxj9FFPY", "phone": "6643545645", "dob": "15-06-87", "age": 121, "createdAt": "2016-03-01T16:39:00.947Z", "updatedAt": "2016-03-01T16:39:00.947Z", "__v": 0 },
        { "_id":"56d97671f6ad671b7d1c3d76", "parseId": "TdKxj9FFPY", "phone": "9847523654", "dob": "15-06-93", "age": 100, "createdAt": "2016-03-01T16:39:00.947Z", "updatedAt": "2016-03-01T16:39:00.947Z", "__v": 0 },
        { "_id":"56d97671f6ad671b7d1c3d76", "parseId": "TdKxj9FFPY", "phone": "4564646646", "dob": "15-06-43", "age": 152, "createdAt": "2016-03-01T16:39:00.947Z", "updatedAt": "2016-03-01T16:39:00.947Z", "__v": 0 }
    ];

Object.keys(json).forEach(function(key) {
    age = moment().diff(moment(json[key].dob,"DD/MM/YY"),'years');

    //
    //dates before 1970 are negative
    //
    if (parseInt(age) < 0) {
        age += 100;
    }

    json[key].age = age;
});

fs.writeFile('data.json', JSON.stringify(json), function (err) {
  if (err) return console.log(err);
  console.log('compeleted');
});