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()

你可能感兴趣的:(UI自动化4_基础封装操作)