wget http://sourceforge.net/projects/pyqt/files/sip/sip-4.14.6/sip-4.14.6.tar.gz
tar zxvf sip-4.14.6.tar.gz
cd sip-4.14.6
python configure.py
make
sudo make install
wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10.1/PyQt-mac-gpl-4.10.1.tar.gz
tar zxvf PyQt-mac-gpl-4.10.1.tar.gz
cd PyQt-mac-gpl-4.10.1
python configure.py
make
sudo make install
wget http://pyside.markus-ullmann.de/pyside-1.1.1-qt48-py27apple.pkg
open pyside-1.1.1-qt48-py27apple.pkg
git clone https://github.com/mitsuhiko/flask.git
cd flask
sudo python setup.py install
git clone git://github.com/carrerasrodrigo/Ghost.py.git
cd Ghost.py
sudo python setup.py install
If you set optional parameter blur to False, the focus will be left on the field (usefull for autocomplete tests).
For filling file input field, simply pass file path as value. 你可以填写form表单 Ghost.fill(selector, values, expect_loading=False):
That wait until a new page is loaded.page, resources = ghost.wait_for_page_loaded()
这个是等 页面都加载完毕,类似jquery $(document).ready(function() wait_for_selector(selector)
That wait until a element match the given selector.result, resources = ghost.wait_for_selector("ul.results")
等你指定的dom名称出现 wait_for_text(text)
That wait until the given text exists inside the frame.result, resources = ghost.wait_for_selector("My result")
等我们要的字符出现
官网出现了 FlASK 的例子:可以通过ghost.py和unittest实现程序的单元测试:
import unittest
from flask import Flask
from ghost import GhostTestCase
app = Flask(__name__)
@app.route('/')
def home():
return 'hello world'
class MyTest(GhostTestCase):
port = 5000
@classmethod
def create_app(cls):
return app
def test_open_home(self):
self.ghost.open("http://localhost:%s/" % self.port)
self.assertEqual(self.ghost.content, 'hello world')
if __name__ == '__main__':
unittest.main()
~~~整体的小demo~~~
# Opens the web page
ghost.open('http://www.openstreetmap.org/')Waits for form search field
ghost.wait_for_selector('input[name=query]')Fills the form
ghost.fill("#search_form", {'query': 'France'})Submits the form
ghost.fire_on("#search_form", "submit")Waits for results (an XHR has been called here)
ghost.wait_for_selector(
'#search_osm_nominatim .search_results_entry a')Clicks first result link
ghost.click(
'#search_osm_nominatim .search_results_entry:first-child a')Checks if map has moved to expected latitude
lat, resources = ghost.evaluate("map.center.lat")
assert float(lat.toString()) == 5860090.806537