我一直使用Python编写Selenium单元测试。我正在尝试将输出写入文件,但由于某种原因,我的代码甚至没有打开文件。当我在命令行中使用它时,相同的代码可以工作,但是当我用seltest运行它时没有任何反应。 Webdriver API中是否有某种限制阻止我这样做?我也没有收到任何错误。
非常感谢任何帮助,谢谢!
〜Carpetfizz
def mailGen(self):
self.email = "tester%s@example.com" % floor(uniform(1,10)*100)
logFile = open('log.txt','w')
logFile.write('')
logFile.write(self.email)
logFile.close()
return self.email
我已经将这些代码复制并粘贴到控制台中,如下所示,它运行正常。除了它在我的C:/Python33
目录中打开文件的事实,这是预期的。
>>> def mailGen():
email = "tester%s@example.com" % floor(uniform(1,10)*100)
logFile = open('log.txt','w')
logFile.write('')
logFile.write(email)
logFile.close()
return email
>>> mailGen()
'tester508@example.com'
>>> mailGen()
'tester827@example.com'
>>>