围绕selenium webdriver的轻量级api,用于使用django进行端到端测试。
ghostl的Python项目详细描述
围绕selenium webdriver和端到端测试帮助程序的轻量级api 和Django在一起。
这个包是alpha,api很可能会改变!
对于python 2.7、3.3、3.4、3.5和pypy版本,它支持django 1.6-1.8(其中 这是Django version supports said Python version)。
安装
您可以通过python包索引(pypi)或 github。
使用pip;安装
pip install ghostly
来自Github;
$ pip install git+https://github.com/alexhayes/ghostly.git
用法
您可以在django之外使用这个包,但是它的用途有限。
基本上有两个组件,如下所示;
- Ghostly-硒的轻量级包装器和帮助器方法 网络驱动程序。目前,它提供了一些使用xpath的方法来 处理页面,例如xpath,xpath_wait等。
- GhostlyDjangoTestCase-扩展的轻量级测试用例 StaticLiveServerTestCase并设置Ghostly的实例。它 提供诸如assertCurrentUrl、assertXpathEqual等方法。
Ghostlydjangotestcase
GhostlyDjangoTestCase继承StaticLiveServerTestCase并因此激发 处理请求的wsgi服务器。
如果您有一个命名的url home,其中<h1>Hello World</h1>在 源代码,您可以执行以下操作;
classMyTestCase(GhostlyDjangoTestCase):deftest_homepage(self):self.goto(reverse('home'))# Assert that an element is equal to somethingself.assertXpathEqual('//h1','Hello World')# Assert the current url, relative or absoluteself.assertCurrentUrl('/home')
使用SVG
要使用selenium web驱动程序遍历svg,必须使用xpath。
classMyTestCase(GhostlyDjangoTestCase):deftest_homepage(self):self.goto(reverse('home'))# Click on an element, or example, in an SVG.self.ghostly.xpath_click('//*[@id="refresh"]')# Assert that an Xpath is equal to somethingself.assertXpathEqual('//h2','Hello World')# Wait for xpath to existself.ghostly.xpath_wait('//div[@id="something"]')
历史记录
这个包一开始是使用yaml构造浏览器测试的简单方法, 布伦顿·克莱兰写的。
这个fork的重点是允许开发人员编写编程单元 以unittest的样式进行测试。
目前,这个fork不包含任何css选择器样式的方法 最初是因为重点是只支持xpath,直到 可以提供更健壮的css选择器工具包。
许可证
此软件是根据麻省理工学院的许可证授权的。请参阅LICENSE 文件位于顶级分发目录中,以获取完整的许可证文本。