UI自動(dòng)化4_基礎(chǔ)封裝操作

基礎(chǔ)操作封裝

conf.config.py:

#!/usr/bin/env python

# -*- coding:utf-8 -*-

import os

WEB_DRIVER=os.path.join(os.path.dirname(__file__),"../chrome_driver_v79/chromedriver.exe")

test_case.ui.base_ui.py:

#!/usr/bin/env python

# -*- coding:utf-8 -*-

from selenium import webdriver

from conf.config import WEB_DRIVER

# 把selenium常用操作封裝到BaseUI這個(gè)類中,我們?cè)賹懹美臅r(shí)候,就可以簡(jiǎn)化代碼量了。

class BaseUI():

? ? def start_browser(self):

? ? ? ? driver = webdriver.Chrome(WEB_DRIVER)

? ? ? ? # 窗口最大化

? ? ? ? driver.maximize_window()

? ? ? ? driver.implicitly_wait(20) # 隱式等待

? ? ? ? self.driver = driver

? ? def quit(self):

? ? ? ? self.driver.quit()

? ? def get(self,url):

? ? ? ? self.driver.get(url)

? ? def click(self,xpath):

? ? ? ? el = self.driver.find_element_by_xpath(xpath)

? ? ? ? el.click()

? ? def send_keys(self,xpath,text):

? ? ? ? el = self.driver.find_element_by_xpath(xpath)

? ? ? ? el.clear()

? ? ? ? el.send_keys(text)

test_case.ui.test_demo.py:

#!/usr/bin/env python

# -*- coding:utf-8 -*-

from time import sleep

from test_case.ui.base_ui import BaseUI

def test_input():

? ? driver = BaseUI()

? ? driver.start_browser()

? ? driver.get("http://ui.yansl.com/#/input")

? ? driver.send_keys("http://input[@name='t2']","sdfisdjif")

? ? sleep(2)

? ? driver.quit()

最后編輯于
?著作權(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),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

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