poium是一个基于Selenium/appium的 Page Object测试库,最大的特点是简化了Page层元素的定义。
基本使用
Page层
创建page层文件,如baidu_page.py文件,封装元素的定位。使用Element定义元素定位,并返回元素对象。
class BaiduPage(Page):
search_input =Element(id_="kw")
search_button = Element(id_="su")
测试用例
import os
import seldom
from seldom import file_data
#新增
from poium import Page, Element
from seldom import Seldom
CASE_DIR = os.path.dirname(os.path.abspath(__file__))
# data file path
YAML_FILE = os.path.join(CASE_DIR, "data.json")
class SampleTest(seldom.TestCase):
def test_case(self):
"""a simple test case """
self.get("http://www.itest.info")
self.assertInUrl("itest.info")
#新增
class BaiduPage(Page):
search_input =Element(id_="kw")
search_button = Element(id_="su")
class BaiduTest(seldom.TestCase):
@file_data(file=YAML_FILE, key="baidu")
def test_data_driver(self, _, keyword):
page = BaiduPage(Seldom.driver)
page.get("https://www.baidu.com")
page.search_input=keyword
page.search_button.click()
self.assertInTitle(keyword)
if __name__ == '__main__':
seldom.main(debug=True)