UI对象库

能够使用配置文件存储被测试页面上页面元素的定位方式和定位表达式,做到定位数据和程序的分离。

1.页面元素定位表达式配置文件,“.ini”文件,可用text文本编辑保存后直接修改文件后缀

[sogou]
searchBox=id>query
searchButton=id>stb

2.ObjectMap工具类文件,供测试程序调用

#!usr/bin/env python
#-*- coding:utf-8 -*-
"""
@author:   sleeping_cat
@Contact : [email protected]
"""
from selenium.webdriver.support.ui import WebDriverWait
import configparser#在python 3 中ConfigParser模块名已更名为configparser
import os

class ObjectMap(object):
    def __init__(self):
        self.uiObjMapPath = os.path.dirname(os.path.abspath(__file__))+"\\UiObjectMap.ini"
        print(self.uiObjMapPath)

    def getElementObject(self,driver,webSiteName,elementName):
        try:
            cf = configparser.ConfigParser()
            cf.read(self.uiObjMapPath)
            locators = cf.get(webSiteName,elementName).split(">")
            locatorMethod = locators[0]
            locatprExpression = locators[1]
            print(locatorMethod,locatprExpression)
            element = WebDriverWait(driver,10).                until(lambda x: x.find_element(locatorMethod,locatprExpression))
        except Exception as e:
            raise e
        else:
            return element

3.调用ObjectMap工具类实现测试逻辑

#!usr/bin/env python
#-*- coding:utf-8 -*-
"""
@author:   sleeping_cat
@Contact : [email protected]
""" 

from selenium import webdriver
import unittest,time,traceback
from ObjectMap import ObjectMap

class TestSoGouSearch(unittest.TestCase):
    def setUp(self):
        self.obj = ObjectMap()
        self.driver = webdriver.Firefox()

    def testSoGouSearch(self):
        url = ‘http://www.sogou.com‘
        self.driver.get(url)
        try:
            searchBox = self.obj.getElementObject(self.driver,‘sogou‘,‘searchBox‘)
            searchBox.send_keys(‘WebDriver实战宝典‘)
            searchButton = self.obj.getElementObject(self.driver,‘sogou‘,‘searchButton‘)
            searchButton.click()
            time.sleep(3)
            self.assertTrue(‘吴晓华‘ in self.driver.page_source,‘assert error!‘)
        except Exception as e:
            print(traceback.print_exc())

    def tearDown(self):
        self.driver.quit()

if __name__ == ‘__main__‘:
    unittest.main()

说明:

实现了程序与数据分离,首先从UI对象库文件“xxx.ini”文件中取得需要操作的页面元素的定位方式,然后再ObjectMap类中取得该页面元素的实例对象,最后返回给测试用例方法中进行后续处理。

原文地址:https://www.cnblogs.com/sleeping-cat/p/8278518.html

时间: 2024-07-30 00:51:05

UI对象库的相关文章

android UI开源库

. ActionBarSherlock ActionBarSherlock是一个独立的Android设计库,可以让Android 2.x的系统也能使用ActionBar.此 外,ActionBarSherlock还能够允许开发者只通过一个API,就可以方便地使用和设计ActionBar. ActionBarSherlock还可以自主判断选择并调用原生Action Bar还是扩展ActionBar.如果在Android 3.x以上使 用ActionBarSherlock,它还会调用系统原生的Act

常见MFC UI界面库[转]

Xtrme toolkit,BCGControlBar,SkinMagic,AppFace,Skin++,Uskin++,SYGUI,LibUIDK,GuiToolkit,GardenUI等等,除了后两种一个是开源,一个是免费的外,其余的都是收费的. The Ultimate Toolbox http://www.codeproject.com/KB/MFC/UltimateToolbox.aspx GuiToolkit(开源,mfc扩展框架,类似Visual Studio 2003风格)htt

UI标签库专题三:JEECG智能开发平台 FormValidation(表单提交及验证标签)

?? 1. FormValidation(表单提交及验证标签) 1.1.  参数 属性名 类型 描述 是否必须 默认值 action string 表单提交路径 否 null formid string 表单唯一标示 是 formobj refresh boolean dialog为true时是否刷新父页面 否 true callback string 表单提交完成后的回调函数 否 null beforeSubmit string 表单提交前的处理函数 否 null btnsub string

UI标签库专题四:JEECG智能开发平台 Upload(上传标签)

?? 1. Upload(上传标签) 1.1.  参数 属性名 类型 描述 是否必须 默认值 id string 上传控件唯一标示 是 null name string 控件name 是 null formData string 上传文件提交后台的其他表单参数取ID 否 null uploader string 上传提交路径 是 null extend string 上传文件扩展名(可选类型组1,pic[*.jpg;*,jpeg;*.png;*.gif;*.bmp;*.ico;*.tif],2,

UI标签库专题十三:JEECG智能开发平台 ckfinder(ckfinder插件标签)

1. ckfinder(ckfinder插件标签) 1.1. 参数 属性名 类型 描述 是否必须 默认值 name string 属性名称 是 null value string 默认值 否 null width string 显示图片宽(上传类型为Images时) 否 null height string 显示图片高(上传类型为Images时) 否 null buttonClass string 按钮样式 否 null buttonValue string 按钮文本 否 null upload

UI标签库专题二:JEECG智能开发平台Column(列) 子标签

 1.1. Column(列) 子标签 1.1.1. 示例 <t:dgCol title="年龄" field="age" query="true" extend="{data-options:{required:false,groupSeparator:\"','\"},class:{value:'easyui-numberbox'}}"></t:dgCol> 1.1.2. 参

UFT 添加对象库,根据对象库进行编写

1.使用对象侦测器识别对象并添加对象库 2.打开对象库,可以查看对象属性及结构 3.根据结构对象类及属性进行编写,比如登入 Dialog("Login").WinEdit("Agent Name:").Set username Dialog("Login").WinEdit("Password:").Set password Dialog("Login").WinButton("OK")

Delphi下将自己写的Form加入到对象库

1.设计好窗体,在窗体空白的地方点击右键,在弹出的菜单中选中“Add to Respository”.在弹出的对话框中填写标题.描述.作者等信息,选择存放的页.完成后点“OK”保存. 2.打开Tools->Repository,选中相应的页,可以修改已加入对象(窗体)的属性或删除已加入的对象. 相关资料:对象库(Object Respository)(1)Delphi提供了一种可以在工程之间共享对象的功能,对象库(ObjectRespository)就是负责 这项功能的机制.你可以将开发完成的窗

UI标签库专题九:JEECG智能开发平台 Choose(选则操作标签)

?? 1. Choose(选则操作标签) 1.1. 参数 属性名 类型 描述 是否必须 默认值 hiddenName string 隐藏域的ID 否 null hiddenid string 隐藏框id 否 null textname string 文档名称 否 null name string 名称 是 null icon string 选择按钮的图标 是 null height string 弹出框的高度 否 null width string 弹出框的宽度 否 null left stri