这个文件用来封装公共的方法,比如登录,使用的时候就可以直接调用登录方法,不需要在用例里面去一行一行的写
里面的所有全部都用了变量,直接从data里面导入,随后放一个data文件,当然也可以使用传参的方式,更加的灵活,还是那句话,怎么方便怎么来
#coding=utf-8
from base_01 import Base
from data import *
class Defined_Function(Base):
def Login(self):
base = Base(self.driver)
base.wait_element_sendkeys(username, *username_loc)
base.wait_element_click(*password_loc_1)
base.wait_element_sendkeys(password, *passowrd_loc_2)
base.wait_element_click(*province_loc_1)
base.wait_element_click(*province_loc_2)
base.wait_element_sendkeys(identifying_code, *validation_loc)
base.wait_element_click(*login_loc)
def Card_Menu(self):
base = Base(self.driver)
base.wait_element_click(*Card_loc)
base.wait_element_click(*Card_Select_loc)
base.wait_element_click(*Card_Select_general_loc)
用例模块,很方便,直接添加就可以,执行顺序和用例的名字有关系,可以使用数字
Testcase_1.py
from selenium.webdriver.support.wait import WebDriverWait
import os, sys, unittest
sys.path.append('..')
from Base.base_01 import Base
from other import Mytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from Base.data import *
from Base.modul import Defined_Function
from selenium.webdriver.support.select import Select
class TestCase_1(Mytest.Myunittest):
'''test case 1'''
def test_1(self):
'''case 1'''
driver = self.driver
fined = Defined_Function(driver)
base = Base(driver)
base.open_browser('http://10.124.147.245')
fined.Login()
fined.Card_Menu()
base.switch_frame('menu_card_infoquery_general')
base.select_list('未下载', By.XPATH, '/html/body/div[2]/div[2]/div[1]/form/div[8]/select')
base.wait_element_click(By.XPATH, '/html/body/div[2]/div[2]/div[1]/form/div[1]/input[1]')
base.wait_element_click(By.LINK_TEXT, u'树搜索')
base.wait_element_sendkeys('300056', By.XPATH, '/html/body/div[1]/div/div[2]/div/div[1]/input')
base.wait_element_click(By.XPATH, '/html/body/div[1]/div/div[2]/div/div[1]/button')
base.wait_element_click(By.XPATH, '/html/body/div[1]/div/div[2]/div/ul/li')
base.wait_element_click(By.XPATH, '/html/body/div[1]/div/div[2]/div/div[2]/button')
base.wait_element_click(By.XPATH, '/html/body/div[2]/div[2]/div[1]/form/div[2]/div/input[1]')
base.wait_element_click(By.XPATH, '/html/body/div[2]/div[2]/div[1]/form/div[12]/div[2]/div/button[1]')
self.assertEqual(base.element(By.XPATH, \
'/html/body/div[3]/div[2]/div[1]/div[2]/div[2]/table/tbody/tr[1]/td[1]').text, '8786011118504990088')
if __name__ == '__main__':
unittest.main()
举一个栗子,数据这可以另起一个文档专门来存放,也可以直接放在用例里面,根据项目怎么方便怎么来