如何把python运行结果保存到log文件,我运行下面代码 log文件为空?谢谢!
# coding = utf-8import os
path = "E:\\python\\case"
caselist = os.listdir(path)
for n in caselist:
s = n.split('.')
if s =='py':
os.system('E:\\python\\case\\%s >>E://log.txt' %n)
用例代码:
# coding = utf-8
from selenium import webdriver
import time,unittest
class scroll(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(10)
self.driver.maximize_window()
self.url = "http://www.baidu.com"
def test_baidu_scroll(self):
driver = self.driver
driver.get(self.url)
time.sleep(3)
driver.find_element_by_id("kw").send_keys("selenim")
driver.find_element_by_id("su").click()
driver.implicitly_wait(10)
time.sleep(2)
driver.quit()
if __name__=="__main__":
unittest.main() 试试os.system('echo E:\\python\\case\\%s >>E://log.txt' %n)
不是 s = n.split('.')么? 为什么不用HTMLTestRunner呢! 不好意思, 以前误解了你的意思, os.system('E:\\python\\case\\%s >>E://log.txt' %n) 应该改为os.system('python E:\\python\\case\\%s >>E://log.txt' %n)
不过如果要生成测试报告,还是用HTMLTestRunner.py生成的模板更专业,美观点。
页:
[1]