UI自动化4_基础封装操作

基础操作封装

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这个类中,我们再写用例的时候,就可以简化代码量了。

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("//input[@name='t2']","sdfisdjif")

    sleep(2)

    driver.quit()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容