expected framework to organize objectives:
1. Single use case maintenance can be performed individually in a single. py file, or batch-build component batch Execution
2. For positioning parameters, positioning methods, business function scripts, use-case scripts, use-case batch execution scripts, common constants for layered independent, each maintained in a separate. py file
3. Add log, HTLM report, send mail function
Frame Structure
Structure Description:
Config: configuration section, browser type and positioning information maintained here
Constant: Constant part, fixed data maintenance here
Data: Storing files for parameterized text tables, etc.
Encapsulation: Positioning and other selenium functions two times packaged here
Error_picture: Storing Error screenshots
Function: Business function script maintenance here
LOG: Storing log class
Report: Storing test reports files
Test_case: Storing use case files
all_case.py: Used to execute all use cases
debug_case.py: I debug use, you can ignore
Tst.log: Generated logs
Describe the. py file below each package, and attach the source code (see note haha ~):
1 #!/usr/bin/env python
2 #-*-Coding:utf-8-*-
3 # @Time : 2017-05-11 13:42
4 # config/config_01.py
5 from selenium import webdriver
6 import time
7 from selenium.webdriver.common.action_chains import *
8
9
config Section
12 # Browser Type maintenance here
Browser_config = { ' ie ': webdriver. Ie, ' Chrome ': Webdriver. Chrome
18 # Positioning Information maintenance here, the maintenance structure from the outside to: page name--page element name--element positioning method + parameter
locat_config = {
20 ' blog home ': ' Look for the input box ': [' id ', ' zzk_q '], ' Look for
the button ': [' XPath ', '//input[@value = ' Look for it] ' }
24}
1 #!/usr/bin/env python
2 #-*-Coding:utf-8-*-
3 # @Time : 2017-05-15 13:20
4 # constant/constant_1 . py
5
6 # constant parts (fixed invariant with frequent parameter maintenance at this place)
7 Login_url = ' https://www.cnblogs.com/'
1 #!/usr/bin/env Python 2 #-*-coding:utf-8-*-3 # @Time: 2017-05-15 13:20 4 # encapsulation/encapsulation.py 5 6 # Encapsulation Section maintains this 7 8 from config.config_01 import locat_config 9 to Log.log import Logger from Selenium.webdriver . support.wait Import webdriverwait selenium.webdriver.support import expected_conditions as EC class UI Handle (): Logger = logger () 16 17 # Construct method to receive Selenium driver object @classmethod def __init__ (CLS, Dr Iver): Cls.driver = driver 21 22 # Enter Address @classmethod def get (CLS, URL): Cls.logge R.loginfo (URL) cls.driver.get (URL) 27 28 # Close Browser driver @classmethod def quit (CLS): CL S.driver.quit () # Element Object (add try, screenshot etc. ...) @classmethod def Element (CLS, page, Element): 36 # Add Log cls.logger.loginfo (page) 38 # Join the hidden Wait 39 # Here you can pass in the dict positional parameter of Config_o1 = Webdriverwait (cls.driveR, Ten). Until (ec.presence_of_element_located (Locat_config[page][element])) 41 # Add Log cls.logger.loginfo ( Page+ ' OK ')-return EL # Element object (not yet completed ...) ) def elements (CLS, page, Element): 46 # Join Log cls.logger.loginfo (page) 48 # Add implicit wait 49 Webdriverwait (cls.driver) els = cls.driver.find_elements (*locat_config[page][element]) 51 # Note Return is the list of returns ELS # Send_keys method @classmethod def Input (CLS, page, Element, msg): 57 el = cls.element (page, Element) El.send_keys (msg) # click Method @classmethod def Click (CLS, page, Element): cls.element el = El.click (page, Element) ()
1 #!/usr/bin/env python
2 #-*-Coding:utf-8-*-
3 # @Time : 2017-05-15 13:22
4 # function/function_01.py
5 # Business Function script (the use case script can call the function script here)
6
7 from encapsulation.encapsulation import Uihandle
8 from Constant.constant_1 Import Login_url
9 from config.config_01 import Browser_config to time
import SLEEP
11
12 # Open the homepage of the blog, look for search function
def search (msg): # Open Browser driver = browser_config[' Chrome ' () # Incoming driver object uihandle = uihandle (driver) #输入url地址 Uihandle.get (login_url) calls the two-time encapsulated method, where you can see which page is being manipulated, which element, MSG is the value to insert, and inserting a worthwhile operation into another use case
file Uihandle. Input (' blog home ', ' Look for Input box ', msg) uihandle. Click (' blog home ', ' Look for button ') uihandle.quit ()
1 #!/usr/bin/env python
2 #-*-Coding:utf-8-*-
3 # @Time : 2017-05-17 11:19
4 # log/log.py
5