Skip to content

Commit

Permalink
Merge pull request #127 from iariasleon/feature/check_ggr_session
Browse files Browse the repository at this point in the history
[FEATURE] Check GGR session
  • Loading branch information
rgonalo committed Mar 21, 2019
2 parents 2fb315e + 2dbfee2 commit 756b210
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ v1.5.2

*Release date: WIP*

- Check if a GGR session (current) is still active

v1.5.1
------

Expand Down
25 changes: 25 additions & 0 deletions toolium/selenoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

# constants
STATUS_OK = 200
STATUS_PORT = "8888"
DOWNLOADS_PATH = u'downloads'
MP4_EXTENSION = u'mp4'
LOG_EXTENSION = u'log'
Expand Down Expand Up @@ -66,6 +67,7 @@ def __init__(self, driver_wrapper, **kwargs):
self.output_directory = kwargs.get('output_dir', DriverWrappersPool.output_directory)
self.browser_remote = driver_wrapper.config.getboolean_optional('Server', 'enabled', False)
self.enabled_logs = driver_wrapper.config.getboolean_optional('Server', 'logs_enabled', False)
self.browser = driver_wrapper.driver.desired_capabilities['browserName']

if self.browser_remote:
self.session_id = driver_wrapper.driver.session_id
Expand Down Expand Up @@ -127,6 +129,29 @@ def get_selenoid_info(self):
self.driver_wrapper.logger.info('Selenoid host info: \n %s' % selenoid_info)
return selenoid_info

def is_the_session_still_active(self):
"""
Is the GGR session still active? Associated to a browser and the sessionId
Example of GGR status:
{"browsers":{"MicrosoftEdge":{"latest":{}},"android":{"8.1":{}},"chrome":{"70.0":{},"latest":{"test_tef":{"count":1,"sessions":[{"caps":{"browserName":"chrome","enableVNC":true,"enableVideo":true,"platform":"ANY","screenResolution":"1280x1024x24","version":"latest","videoName":"selenoide952e551bb9395e16d060f28c54e5d31.mp4","videoScreenSize":"1280x1024"},"container":"8489205e28c9781472e99c3921a6240de3894a3603ed9e187ad6360b6b013b8b","containerInfo":{"id":"8489205e28c9781472e99c3921a6240de3894a3603ed9e187ad6360b6b013b8b","ip":"172.17.0.4"},"id":"1345506093dfed8dbcef610da476911a228ca315978e5464ae49fb1142bbc49b","screen":"1280x1024x24","vnc":true}]}}},"firefox":{"59.0":{},"63.0":{},"64.0":{},"latest":{}},"internet explorer":{"11":{}},"opera":{"56.0":{},"latest":{}},"safari":{"latest":{}}},"pending":0,"queued":0,"total":30,"used":1}
:return boolean (although in case of error in the request will be returned None)
"""
server_url_splitted = self.server_url.split(":")
host_url = "{}:{}:{}:{}/status".format(server_url_splitted[0], server_url_splitted[1], server_url_splitted[2], STATUS_PORT)

try:
response = requests.get(host_url).json()["browsers"][self.browser]
except Exception as e:
self.driver_wrapper.logger.warn("the GGR status request has failed: \nResponse: %s \nError message: %s\n" % (response.content, e))
return None
for browser in response:
if response[browser] != {}:
sessions = response[browser][server_url_splitted[1].split("@")[0].replace("//", "")]["sessions"]
for session in sessions:
if session["id"] == self.session_id:
return True
return False

def download_session_video(self, scenario_name, timeout=5):
"""
download the execution video file if the scenario fails or the video is enabled,
Expand Down

0 comments on commit 756b210

Please sign in to comment.