Usage¶
You can use use this package outside of Django however it has limited use.
Essentially there are two components, as follows;
Ghostly
- A lightweight wrapper and helper methods for Selenium Webdriver. Presently it provides a handful of methods that utilise xpath to deal with a page, such asxpath
,xpath_wait
et al.GhostlyDjangoTestCase
- A lightweight test case that extends StaticLiveServerTestCase and sets up an instance ofGhostly
. It provides methods such asassertCurrentUrl
,assertXpathEqual
et al.
GhostlyDjangoTestCase¶
GhostlyDjangoTestCase
inherits StaticLiveServerTestCase and thus fires up
a WSGI server that handles requests.
Given you have a named URL home
with a <h1>Hello World</h1>
visible in
the source, you can do the following;
class MyTestCase(GhostlyDjangoTestCase):
def test_homepage(self):
self.goto(reverse('home'))
# Assert that an element is equal to something
self.assertXpathEqual('//h1', 'Hello World')
# Assert the current url, relative or absolute
self.assertCurrentUrl('/home')
Working with SVG¶
To traverse SVG with Selenium web driver you must use xpath.
class MyTestCase(GhostlyDjangoTestCase):
def test_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 something
self.assertXpathEqual('//h2', 'Hello World')
# Wait for xpath to exist
self.ghostly.xpath_wait('//div[@id="something"]')