Python collocation unittest

Source: Internet
Author: User

UnitTest is the unit test framework for Python,

Similar to the testng inside Java.

From time import sleep
From selenium import Webdriver
Import UnitTest


Class UnitTest (UnitTest. TestCase):
# UnitTest class Inherits Unittest.testcase class

def setUp (self):
# Setup is used to set up initialization work, which is executed before each test case
Self.driver = Webdriver. Firefox ()
Self.base_url = "https://www.baidu.com/"
Self.driver.maximize_window ()
Sleep (2)

def test_baidu (self):
# Search for Chinese test cases
Driver = Self.driver
Driver.get (Self.base_url)
Driver.find_element_by_xpath (".//*[@id = ' kw ']"). Send_keys ("China")
Driver.find_element_by_xpath (".//*[@id = ' su ']"). Click ()
Sleep (2)
Self.assertequal (Driver.find_element_by_xpath (".//*[@id = ' 1 ']/h3/a"). Text, "China _ Baidu Encyclopedia")
# assert China _ Baidu encyclopedia element

def tearDown (self):
# Teardown method is called after each test method is executed for clean-up work after testing
Self.driver.quit ()

if __name__ = = "__main__":
Unittest.main ()
# The entire test process is integrated in the Unitest.main () module, which defaults to the method that starts with test

Python collocation unittest

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.