一、首先是打开要测试UI自动化的操作: 日志类[戳这里],最后一个类便是,可以引用过来。
from selenium import webdriver
import time
from common.log import *
def OpenURL(url):
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches",["enable-automation"])
driver = webdriver.Chrome(options=options)
if str("https") in url:
driver.get(url)
driver.implicitly_wait(1)
driver.maximize_window()
try:
driver.find_element_by_id("details-button").click()
time.sleep(1)
driver.find_element_by_id("proceed-link").click()
time.sleep(1)
except Exception as error:
Log().logMsg(1,error.args)
else:
driver.get(url)
driver.maximize_window()
二、写一个公共的类,然后利用一个文件是调取它,这样的话省去了多个问题调用省去 很多的代码。
第一个文件,case文件
class CaseStep:
def __init__(self):
self.Step = 0
self.Behavior = ''
self.operationPage = ''
self.Description = ''
self.ObjctName = ''
self.PositioningExpression = ''
self.InputValue = ''
self.OutputValue = ''
self.ExpectedResult = ''
self.WaitTime = 0
self.Enabled = 1
self.IgnoreErr = 0
self.LoopCnt = 1
class ElementMap:
def __init__(self):
self.Page = ''
self.Type = ''
self.Name = ''
self.TmpText = ''
self.SourceName = ''
class Case:
def __init__(self):
self.caseSteps = list()
self.elementMaps = list()
第二个文件:ibehavior_handler.py
from models.case import *
class IBehaviorHandler:
def handle_behavior(self,selenium_wd_class, step:CaseStep):
"""
:param selenium_wd_class:
:param step:
:return:
"""
这个就是把第一个文件和第二个文件中的方法给关联上去了。
|