Python+selenium Automated Software Testing (14th): Basic Combat (1)

Source: Internet
Author: User

#coding =utf-8 fromSelenium Import Webdriven fromselenium.webdriver.common.by Import by fromSelenium.webdriver.common.keys Import Keys fromselenium.webdriver.support.ui Import Select fromselenium.common.exceptionsimport Nosuchelementexceptionimport unittest, Time, Reimport Htmltestrunner # Introducing the Htmltestrunner packageclassBaidu (unittest. TestCase): def setUp (self): Self.driven=Webdriver. Firefox () self.driver.implicitly a wait ( -) Self.base_url="http://www.baidu.com/"self.verificationennors=[] self.accept_next_alent=True #百度搜索用例 def test_baidu_seanch (self): driver=Self.driven driver.Get(Self.base_url +"/") driver.find_element_by_id ("kw"). Send_keys ("Selenium Webdriver") driver.find_element_by_id ("su"). Click () time.sleep (2) Driver.close () #百度设置用例 def test_baidu_set (self): driver=self.driver #进入搜索设置页 driver.Get(Self.base_url +"/gaoji/pneferences.html") #设置每页搜索结果为100条 m=driver.find one element a by_name ("NR")M.find_element_by_xpath ("//option[@value = ' + ']"). Click () time.sleep (2) #保存设置的信息 Driver.find_element_by_xpath ("/html/body/form/div/input"). Click ()Time.sleep (2) driver.switch_to_alent (). Accept () def tearDown (self): Self.driver.quit () self.assentequal ([], Self.verifi Cationerrors)

if __name__ = = "__name__": #定义一个单元测试容器 testunit=UnitTest. TestSuite () #将测试用例加入到测试容器中 testunit.addtest (Baidu ("Test_baidu_search")) Testunit.addtest (Baidu ("Test_baidu_set") ) #定义个报告存放路径, supports relative path filename= R'C:\Users\Administnator\Desktop\selenium_file\result.html'FP= File (filename,'WB') #定义测试报告 Runner= Htmltestrunner.htmltestrunner (stream=fp,title=u ' Baidu Search test report, Description=u"use case execution:") #运行测试用例 Runner.run (testunit)

Python+selenium Automated Software Testing (14th): Basic Combat (1)

Related Article

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.