Skip to content

Instantly share code, notes, and snippets.

@VladSem
Last active October 1, 2015 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VladSem/11e9c29364a0d0eb460d to your computer and use it in GitHub Desktop.
Save VladSem/11e9c29364a0d0eb460d to your computer and use it in GitHub Desktop.
Python: Modem connection validator plus timeout...
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
from main_driver import driver
def check_modem_connection_status(path_to_modem_connection, path_to_reconnect_button):
modem_status = driver.find_element_by_xpath(path_to_modem_connection).text
start_time = time.time()
attempts_time = 0
try:
if modem_status == 'Connected':
end_time = time.time()
total_time = end_time - start_time
hours = total_time // 3600
total_time -= 3600 * hours
minutes = total_time // 60
seconds = total_time - 60 * minutes
final_time = ('%d:%d:%d' % (hours, minutes, seconds))
print 'Modem status: ' + modem_status + ' Test passed'
print 'Cnnec. time: ' + final_time
print 'Attempts: ' + str(attempts_time) + ' time(s)'
print '-'*50
elif modem_status == 'aborting..' or 'con-phase2' or 'connecting' or 'disconnected':
while not modem_status == 'Connected':
if modem_status == 'con-phase2':
print(modem_status)
elif modem_status == 'connecting':
print(modem_status)
elif modem_status == 'retrying':
print(modem_status)
elif modem_status == 'aborting..':
print(modem_status)
elif modem_status == 'disconnected':
driver.find_element_by_xpath(path_to_reconnect_button).click()
else:
print modem_status
time.sleep(5)
attempts_time += 1
modem_status = driver.find_element_by_xpath(path_to_modem_connection).text
print modem_status
if attempts_time == 6:
print 'Timeout...'
print 'Modem connec.: timeout..., after ' + str(
attempts_time * 5) + ' sec Test failed'
driver.close()
end_time = time.time()
total_time = end_time - start_time
hours = total_time // 3600
total_time -= 3600 * hours
minutes = total_time // 60
seconds = total_time - 60 * minutes
final_time = ('%d:%d:%d' % (hours, minutes, seconds))
print 'Modem status: ' + modem_status + ' Test passed'
print 'Connec. time: ' + final_time)
print 'Attempts: ' + str(attempts_time) + ' time(s)'
print '-'*50
else:
print 'Modem status: can\'t be found Test failed'
except:
print 'Modem status: error, modem can\'t be found Test failed'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment