51Testing软件测试论坛

标题: 如何把python运行结果保存到log文件,我运行下面代码 log文件为空?谢谢! [打印本页]

作者: yzlfzs    时间: 2016-3-15 11:52
标题: 如何把python运行结果保存到log文件,我运行下面代码 log文件为空?谢谢!
# coding = utf-8
import os
path = "E:\\python\\case"
caselist = os.listdir(path)
for n in caselist:
    s = n.split('.')[1:][0]
    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()




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2