一种实现页面对象模式的好方法。
stere的Python项目详细描述
立方米是一个用于编写页面对象的库,用于在现有的自动化库上工作。
设计理念
页面对象模型的许多实现都侧重于消除测试中元素定位器的重复。 stere更进一步,为驱动自动化的代码提供了一个完整的包装器。
本项目的目标是:
1-消除测试函数中的实现代码。测试应该像行为描述一样阅读,而不是selenium命令。
2-减少在页面对象中手工编写助手方法的需要。共同行动应该有普遍的解决办法。
3-为编写可维护的页面对象提供一个简单的模式。
基本用法
基本上,页面对象只是一个python类。
最小的stere page对象应该:
1-对页类进行子类划分
2-在初始化方法中声明字段和区域
例如,这里是维基百科的主页:
fromstereimportPagefromstere.areasimportArea,RepeatingAreafromstere.fieldsimportButton,Input,Link,Root,TextclassWikipediaHome(Page):def__init__(self):self.search_form=Area(query=Input('id','searchInput'),submit=Button('xpath','//*[@id="search-form"]/fieldset/button'))self.other_projects=RepeatingArea(root=Root('xpath','//*[@class="other-project"]'),title=Link('xpath','//*[@class="other-project-title"]'),tagline=Text('xpath','//*[@class="other-project-tagline"]'))
字段表示单个项,而区域表示字段的唯一集合。
查询和提交字段不必放置在区域内。 但是,这样做可以使用area的perform()方法。
其他产品的链接表示为RepeatingArea。 repeatingarea表示页面上字段的非唯一集合。 使用根参数作为非唯一选择器,repeatingarea将找到所述根的所有实例, 然后用所有其他字段构建适当数量的区域。
把其他产品作为一个单独的区域来声明也是有效的 一次一个,就像这样:
self.commons=Area(root=Root('xpath','//*[@class="other-project"][1]'),title=Link('xpath','//*[@class="other-project-title"]'),tagline=Text('xpath','//*[@class="other-project-tagline"]'))self.wikivoyage=Area(root=Root('xpath','//*[@class="other-project"][2]'),title=Link('xpath','//*[@class="other-project-title"]'),tagline=Text('xpath','//*[@class="other-project-tagline"]'))
您选择哪种样式完全取决于您希望如何对页面建模。 repeatingarea对区域数量和/或区域内容最多的集合最有效 无法预测,如库存清单。
在测试中使用页面对象可以这样做:
deftest_search_wikipedia():home=WikipediaHome()home.search_form.perform('kittens')
许可证
根据MIT许可证的条款分发,“stere”是免费的开源软件
问题
如果您遇到任何问题,请file an issue连同详细说明。
谢谢
跨浏览器测试平台和开源<;3由Sauce Labs