Selenium+python (Modular Drive test)

Source: Internet
Author: User

Modular drive testing, is to learn from the programming language of the modular thinking, the repeated operation of the independent success of the announcement module, understand the use of this module during the execution of the case is called when the operation is required, which can greatly eliminate duplication and improve the maintainability of test cases

The following specific 126 mailbox as an example:

First of all to use the login log out independently, put in the public module

public.py

# Coding=utf-8class Login (): # Login Login def login (self,driver):      driver.find_element_by_id ("Idinput"). Clear ()    driver.find_element_by_id ("Idinput"). Send_keys ("username")    driver.find_element_by_id ("Pwdinput"). Clear ()    driver.find_element_by_id ("Pwdinput"). Send_keys ("123456")    driver.find_element_by_id ("Loginbtn"). Click ()  # Click to confirm Login Button # logout logout def logout (self,driver):    time.sleep (2)    driver.find_element_by_link_text (U "Exit") . Click ()

Separate the function into a separate script, mainly to increase the browser-driven parameters for the function, because the implementation of the function requires a browser-driven driver,driver needs to be given by a specific invocation of the use case.

test_case.py,test_case.py by invoking Login, Exit function for modularity

#coding =utf-8from  Selenium import webdriverfrom public import Loginimport unittestclass logintest (unittest. TestCase):    def setUp (self):        self.driver = Webdriver. Firefox ()        self.base_url = "http://www.126.com"        self.driver.implicitly_wait (5)    def test_write_letter_ Case (self):        driver = self.driver        driver.get (self.base_url)        #调用登录函数        login (). Login (Driver)        # Realize receiving, Operation        # ...        #调用退出函数        Login (). Logout (Driver)    def tearDown (self):        self.driver.quit () if __name__ = = "__main__":    Unittest.main ()

First, you need to import login () from the public.py file in the current directory, call the login () and loginout () functions in the class where needed, so it's much easier to write and maintain for each use case

Selenium+python (Modular Drive test)

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.