Selenium Baidu search + Youdao translation Simple testcase execution-----use case report (Htmltestrunner)

Source: Internet
Author: User

This article mainly implements the selenium automated test Baidu search + Youdao translation Simple test case execution, and through the HTML Testrunner generates an HTML test report. This is the first Htmltestrunner script, based on the Python3 script, that was followed shortly after learning the video.

Test_baidu,py

#Coding=utf-8ImportUnitTestImportHtmltestrunnerImport Time#define a directory for test file lookupsTest_dir='E:\\pycode\\unittest_baidu\\test_case'#define parameters for the Discover methodDiscover=unittest.defaulttestloader.discover (test_dir, pattern ='test_b*.py', top_level_dir=None) now=time.strftime ('%y_%m_%d%h_%m_%s')Print(now)#define a report storage pathFilename='e:\\pycode\\unittest_baidu\\report\\'+now+'result.html'FP=open (filename,'WB')if __name__=='__main__':    #Defining test ReportsRunner = Htmltestrunner.htmltestrunner (STREAM=FP, Title=u'Baidu Search test Report', Description=u'use case Execution')    #Run test CasesRunner.run (Discover)#Close Report FileFp.close ()

test_youdao.py

#Coding=utf-8 fromSeleniumImportWebdriverImportUnitTest fromTimeImportSleepclassMyTest (unittest. TestCase):defsetUp (self): Self.driver=Webdriver. Firefox () Self.driver.maximize_window () Self.base_url="http://www.youdao.com"Sleep (5)    defTest_youdao (self): driver=self.driver driver.get (Self.base_url+"/") driver.find_element_by_id ("translatecontent"). Clear () driver.find_element_by_id ("translatecontent"). Send_keys ("Webdriver") driver.find_element_by_id ("translatecontent"). Submit () Sleep (2) Title=driver.title self.assertequal (U"what does "Webdriver" mean _ English Webdriver Translation _ Phonetic Transcription _ pronunciation _ Usage _ _ _ _", title)defTearDown (self): Self.driver.quit ()if __name__=="__main__": Unittest.main ()

all_test.py

#Coding=utf-8ImportUnitTestImportHtmltestrunnerImport Time#define a directory for test file lookupsTest_dir='E:\\pycode\\unittest_baidu\\test_case'#define parameters for the Discover methodDiscover=unittest.defaulttestloader.discover (test_dir, pattern ='test_*.py', top_level_dir=None) now=time.strftime ('%y_%m_%d%h_%m_%s')Print(now)#define a report storage pathFilename='e:\\pycode\\unittest_baidu\\report\\'+now+'result.html'FP=open (filename,'WB')if __name__=='__main__':    #Defining test ReportsRunner = Htmltestrunner.htmltestrunner (STREAM=FP, Title=u'Baidu Search test Report', Description=u'use case Execution')    #Run test CasesRunner.run (Discover)#Close Report FileFp.close ()

The script can run normally, if it fails, check if the environment configuration is OK, if the browser driver is installed correctly.

Selenium Baidu search + Youdao translation Simple testcase execution-----use case report (Htmltestrunner)

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.