Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use the higher-order functions of Python to write logs and capture abnormal information

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Import logging

Import time

Import traceback

From selenium import webdriver

Def log (test_case_func):

Def wraps (* args, * * keywords):

Log_name= time.strftime ("% Y%m%d%H%M%S", time.localtime ()) + test_case_func.__name__

Logging.basicConfig (level=logging.INFO,filemode='w',filename='./'+log_name+'.log')

Test_time = time.strftime ("% Y-%m-%d% H:%M:%S", time.localtime ())

Logging.info (test_time+': now starts testing:'+ test_case_func.__name__)

Try:

Test_case_func (* args, * * keywords)

Logging.info (test_time+': test completed successfully!' )

Except:

Logging.info (test_time+': test has an exception:'+ traceback.format_exc ())

Return wraps

@ log

Def test_case1 (driver):

Driver.get ('https://www.baidu.com/?tn=sitehao123_15')

Driver.maximize_window ()

Driver.find_element_by_id ('kw11')

If _ _ name__ = ='_ _ main__':

Driver = webdriver.Firefox ()

Test_case1 (driver)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report