'Test js code running in the browser
- optionnally log as \'login\'
- load page given by url_path
- wait for ready object to be available
- eval(code) inside the page
To signal success test do:
console.log(\'ok\')
To signal failure do:
console.log(\'error\')
If neither are done before timeout test fails.'

def phantom_js(self, url_path, code, ready='window', login=None, timeout=60, **kw):

    options = {'port': PORT, 'db': get_db_name(), 'url_path': url_path, 'code': code, 'ready': ready, 'timeout': timeout, 'session_id': self.session_id}
    options.update(kw)
    self.authenticate(login, login)
    phantomtest = os.path.join(os.path.dirname(__file__), 'phantomtest.js')
    cmd = ['phantomjs', phantomtest, json.dumps(options)]
    self.phantom_run(cmd, timeout)
