Selenium2 + Python3.6 Combat (V): Generate an HTML test report Invalid argument

Source: Internet
Author: User

Today in the advanced application of automated testing, the first one is to generate an HTML test report, because the name of the test report is not set, so the runtime will overwrite the original report without manually modifying the previous report name before running the test. This is obviously a hassle, and the best solution is to include the current time in the report name so that the generated reports will not overlap and will be clearer about when the report was generated.

But in the process of running the code, an error occurred:

Traceback (most recent):
File "d:/python/selenium/test_baidu.py", line at <module>
fp = open (filename, ' WB ')
OSError: [Errno] Invalid argument: './2017-07-25 16:52:00result.html '

At first glance I thought it was something that was going on, and I didn't feel a problem checking my code carefully. Thinking for a long time, suddenly realized that I set the time of the file name to now = Time.strftime ("%y-%m-%d%h:%m:%s")

The file name is not allowed to appear similar to/\: such as special characters. In a moment I was clear, immediately corrected, and again allowed, sure enough success.

From selenium import Webdriver

Import UnitTest

Import time

From Htmltestrunner import Htmltestrunner

Class Baidu (UnitTest. TestCase):

"Baidu Search Test"

def setUp (self):

Self.driver = Webdriver. Firefox ()

Self.driver.implicitly_wait (10)

Self.base_url = "http://www.baidu.com/"

def test_baidu_search (self):

"Keyword search: Htmltestrunner"

Driver = Self.driver

Driver.get (Self.base_url)

driver.find_element_by_id ("kw"). Send_keys ("Htmltestrunner")

driver.find_element_by_id ("su"). Click ()

def tearDown (self):

Self.driver.quit ()

if __name__ = = "__main__":

Testunit = UnitTest. TestSuite ()

Testunit.addtest (Baidu ("Test_baidu_search"))

#按照一定格式获取当前时间

Now = Time.strftime ("%y-%m-%d%h_%m_%s") #一定不要包括禁止使用的文件名特殊符号

#定义报告存放路径

filename = './' + now + ' result.html '

fp = open (filename, ' WB ')

#定义测试报告

Runner = Htmltestrunner (STREAM=FP,

Title= ' Baidu Search test Report ',

description= ' use case execution: ')

Runner.run (Testunit) #运行测试用例

Fp.close () #关闭报告文件

Selenium2 + Python3.6 Combat (V): Generate an HTML test report Invalid argument

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.