Python寫RF測試-SeleniumLibrary關(guān)鍵字封裝

時(shí)隔幾日,RF嫁接到原有的自動(dòng)化測試框架已經(jīng)基本完成,今天抽點(diǎn)時(shí)間給大家分享一下SeleniumLibrary關(guān)鍵字使用

時(shí)的二次封裝以及自定義關(guān)鍵字,希望對(duì)大家在做自動(dòng)化測試時(shí)會(huì)有所幫助

來,閑話太多,上代碼:

# 獲取元素信息

def get_locator(self,locator):

ltype=locator["type"]

value=locator["value"]

return"%s=%s"%(ltype,value)

# 運(yùn)行測試

def test_run(self):

self.suite.run()

# 創(chuàng)建一個(gè)測試

def testes_create(self,string):

test=self.suite.tests.create(string)

returntest

# 啟動(dòng)瀏覽器

def open_browser(self,http,browserName,obj):

# test = self.testes_create("啟動(dòng)瀏覽器")

obj.keywords.create("Open Browser",args=[http,browserName])

# 關(guān)閉瀏覽器

def close_browsers(self,test):

#test=self.testes_create("關(guān)閉瀏覽器")

test.keywords.create("Close All Browsers")

# 瀏覽器最大化

def max_window(self,test):

# test = self.testes_create("瀏覽器最大化")

test.keywords.create("Maximize Browser Window")

# 文本輸入

def input_text(self,locator,text,test):

loc=self.get_locator(locator)

#test = self.testes_create("文本輸入")

test.keywords.create("Input Text",args=[loc,text])

# 點(diǎn)擊按鈕

def click_button(self,locator,test):

loc=self.get_locator(locator)

# test = self.testes_create("點(diǎn)擊按鈕")

test.keywords.create("Click Button",args=[loc])

# 點(diǎn)擊元素

def click_element(self,locator,test):

loc=self.get_locator(locator)

# test = self.testes_create("點(diǎn)擊元素")

test.keywords.create("Click Element",args=[loc])

# 等待元素出現(xiàn)

def wait(self,locator,error,test):

loc=self.get_locator(locator)

# test = self.testes_create("等待元素出現(xiàn)")

test.keywords.create("Wait Until Page Contains Element",args=[loc,20,error])

# 獲取瀏覽器窗口的title信息

def get_title(self):

test=self.testes_create("獲取")

returntest.keywords.create("Get Title")

# 獲取元素文本信息

def get_text(self,locator,test):

loc=self.get_locator(locator)

# test = self.testes_create("獲取元素文本信息")

returntest.keywords.create("Get Text",args=[loc])

# 獲取元素屬性值

def get_attribute(self,locator,test):

loc=self.get_locator(locator)

# test = self.testes_create("獲取元素屬性值")

returntest.keywords.create("Get Element Attribute",args=[loc])

# 下拉框的選擇

def select_list(self,locator,value,test):

loc=self.get_locator(locator)

# test = self.testes_create("下拉框選擇")

test.keywords.create("Unselect From List By Value",args=[loc+value])

# 表單嵌套

def select_frame(self,locator,test):

loc=self.get_locator(locator)

# test = self.testes_create("選擇表單")

test.keywords.create("Select Frame",args=[loc])

# 退出表單選擇

def unselect_frame(self,test):

# test = self.testes_create("退出表單選擇")

test.keywords.create("Unselect Frame")

# 點(diǎn)擊圖片

def click_image(self,locator,test):

loc=self.get_locator(locator)

# test = self.testes_create("點(diǎn)擊圖片")

test.keywords.create("Click Image",args=[loc])

# 點(diǎn)擊鏈接

def click_link(self,locator,test):

loc=self.get_locator(locator)

# test = self.testes_create("點(diǎn)擊鏈接")

test.keywords.create("Click Link",args=[loc])

# 關(guān)閉當(dāng)前彈出的窗口

def close_window(self,test):

test.keywords.create("Close_Window")

以上是關(guān)鍵字的封裝,細(xì)心的伙伴會(huì)發(fā)現(xiàn),SeleniumLibrary庫中的關(guān)鍵字在做實(shí)際項(xiàng)目中會(huì)有很多操作的關(guān)鍵字沒有,比如:
窗口的切換,鼠標(biāo)的懸停等,這時(shí)候就需要自己向SeleniumLibrary庫中自行封裝添加。
之后講解一下怎么自定義關(guān)鍵字,還請(qǐng)小伙伴多多支持

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容