Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Commit

Permalink
Separate wd routes for /vmmaster/<command>
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Zubov authored and Stanislav Zubov committed Oct 21, 2015
1 parent d707bd1 commit f8ba683
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions tests/unit/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def get_session_request(address, session):

def run_script(address, session, script):
return request("%s:%s" % address, "POST",
"/wd/hub/session/%s/runScript" % str(session),
"/wd/hub/session/%s/vmmaster/runScript" % str(session),
body=json.dumps({"script": script}))


def vmmaster_label(address, session, label=None):
return request("%s:%s" % address, "POST",
"/wd/hub/session/%s/vmmasterLabel" % str(session),
"/wd/hub/session/%s/vmmaster/vmmasterLabel" % str(session),
body=json.dumps({"label": label}))

from core.utils.network_utils import get_socket
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ deps = selenium==2.46.0
mock==1.0.1
flake8==2.4.1
coverage==3.7.1
git+https://github.com/2gis/vmmaster-client
git+https://github.com/2gis/vmmaster-client@urls-for-custom-commands
git+https://github.com/2gis/lode_runner
{[testenv:base]deps}

Expand Down
55 changes: 36 additions & 19 deletions vmmaster/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,7 @@ def get_session(session_id):
return helpers.form_response(status, headers, body)


@webdriver.route("/session/<string:session_id>/<path:url>",
methods=['GET', 'POST', 'DELETE'])
def proxy_request(session_id, url=None):
request.session = current_app.sessions.get_session(session_id)

if url:
last = url.split("/")[-1]
else:
last = None

if last in commands.AgentCommands:
status, headers, body = helpers.vmmaster_agent(
commands.AgentCommands[last])
elif last in commands.InternalCommands:
status, headers, body = helpers.internal_exec(
commands.InternalCommands[last])
else:
status, headers, body = helpers.transparent()

def take_screenshot(status, body):
words = ["url", "click", "execute", "keys", "value"]
only_screenshots = ["element", "execute_async"]
parts = request.path.split("/")
Expand All @@ -140,4 +122,39 @@ def proxy_request(session_id, url=None):
utils.to_thread(
helpers.take_screenshot_from_response(request.session, body))


@webdriver.route(
"/session/<string:session_id>/vmmaster/runScript", methods=['POST']
)
def agent_command(session_id):
request.session = current_app.sessions.get_session(session_id)

status, headers, body = helpers.vmmaster_agent(
commands.AgentCommands['runScript'])

take_screenshot(status, body)
return helpers.form_response(status, headers, body)


@webdriver.route(
"/session/<string:session_id>/vmmaster/vmmasterLabel", methods=['POST']
)
def vmmaster_command(session_id):
request.session = current_app.sessions.get_session(session_id)

status, headers, body = helpers.internal_exec(
commands.InternalCommands['vmmasterLabel'])

take_screenshot(status, body)
return helpers.form_response(status, headers, body)


@webdriver.route("/session/<string:session_id>/<path:url>",
methods=['GET', 'POST', 'DELETE'])
def proxy_request(session_id, url=None):
request.session = current_app.sessions.get_session(session_id)

status, headers, body = helpers.transparent()

take_screenshot(status, body)
return helpers.form_response(status, headers, body)

0 comments on commit f8ba683

Please sign in to comment.