Commit 2195d4c8 by Csók Tamás

selenium: screenshots upon test breaking exceptions

parent 2d5d6d20
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime from datetime import datetime
import inspect
import logging import logging
import random import random
import re import re
...@@ -37,6 +38,12 @@ logger = logging.getLogger(SeleniumConfig.logger_name) ...@@ -37,6 +38,12 @@ logger = logging.getLogger(SeleniumConfig.logger_name)
class SeleniumMixin(object): class SeleniumMixin(object):
def create_screenshot(self):
name = 'ss_from_%(caller_name)s.png' % {
'caller_name': inspect.stack()[1][3]}
logger.warning('Creating screenshot "%s"' % name)
self.driver.save_screenshot(name)
def get_url(self, fragment_needed=False, fragment=None): def get_url(self, fragment_needed=False, fragment=None):
url_base = urlparse.urlparse(self.driver.current_url) url_base = urlparse.urlparse(self.driver.current_url)
url_save = ("%(host)s%(url)s" % { url_save = ("%(host)s%(url)s" % {
...@@ -64,6 +71,7 @@ class SeleniumMixin(object): ...@@ -64,6 +71,7 @@ class SeleniumMixin(object):
except: except:
logger.exception("Selenium cannot list the" logger.exception("Selenium cannot list the"
" select possibilities") " select possibilities")
self.create_screenshot()
raise Exception( raise Exception(
'Cannot list the select possibilities') 'Cannot list the select possibilities')
...@@ -96,6 +104,7 @@ class SeleniumMixin(object): ...@@ -96,6 +104,7 @@ class SeleniumMixin(object):
select.select_by_value(my_choice) select.select_by_value(my_choice)
except: except:
logger.exception("Selenium cannot select the chosen one") logger.exception("Selenium cannot select the chosen one")
self.create_screenshot()
raise Exception( raise Exception(
'Cannot select the chosen one') 'Cannot select the chosen one')
...@@ -118,6 +127,7 @@ class SeleniumMixin(object): ...@@ -118,6 +127,7 @@ class SeleniumMixin(object):
except: except:
logger.exception( logger.exception(
"Selenium cannot find the href=%s link" % target_href) "Selenium cannot find the href=%s link" % target_href)
self.create_screenshot()
raise Exception('Cannot find the requested href') raise Exception('Cannot find the requested href')
def click_on_link(self, link): def click_on_link(self, link):
...@@ -145,6 +155,7 @@ class SeleniumMixin(object): ...@@ -145,6 +155,7 @@ class SeleniumMixin(object):
self.driver.execute_script(javascript, link) self.driver.execute_script(javascript, link)
except: except:
logger.exception("Selenium cannot inject javascript to the page") logger.exception("Selenium cannot inject javascript to the page")
self.create_screenshot()
raise Exception( raise Exception(
'Cannot inject javascript to the page') 'Cannot inject javascript to the page')
...@@ -214,6 +225,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -214,6 +225,7 @@ class CircleSeleniumMixin(SeleniumMixin):
time.sleep(0.5) time.sleep(0.5)
except: except:
logger.exception("Selenium cannot find the form controls") logger.exception("Selenium cannot find the form controls")
self.create_screenshot()
raise Exception('Cannot find the form controls') raise Exception('Cannot find the form controls')
def fallback(self, fallback_url, fallback_function): def fallback(self, fallback_url, fallback_function):
...@@ -256,6 +268,10 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -256,6 +268,10 @@ class CircleSeleniumMixin(SeleniumMixin):
self.fallback( self.fallback(
fallback_url, fallback_url,
lambda: self.wait_and_accept_operation(argument)) lambda: self.wait_and_accept_operation(argument))
else:
self.create_screenshot()
raise Exception(
'Cannot accept the operation confirmation')
except: except:
logger.exception("Selenium cannot accept the" logger.exception("Selenium cannot accept the"
" operation confirmation") " operation confirmation")
...@@ -264,7 +280,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -264,7 +280,7 @@ class CircleSeleniumMixin(SeleniumMixin):
fallback_url, fallback_url,
lambda: self.wait_and_accept_operation(argument, try_wait)) lambda: self.wait_and_accept_operation(argument, try_wait))
else: else:
self.driver.save_screenshot('error_at_try_wait.png') self.create_screenshot()
raise Exception( raise Exception(
'Cannot accept the operation confirmation') 'Cannot accept the operation confirmation')
...@@ -322,6 +338,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -322,6 +338,7 @@ class CircleSeleniumMixin(SeleniumMixin):
return name return name
except: except:
logger.exception("Selenium cannot save a vm as a template") logger.exception("Selenium cannot save a vm as a template")
self.create_screenshot()
raise Exception( raise Exception(
'Cannot save a vm as a template') 'Cannot save a vm as a template')
...@@ -344,6 +361,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -344,6 +361,7 @@ class CircleSeleniumMixin(SeleniumMixin):
By.ID, 'id_name'))) By.ID, 'id_name')))
template_name.clear() template_name.clear()
template_name.send_keys(name) template_name.send_keys(name)
self.select_option(self.driver.find_element_by_id( self.select_option(self.driver.find_element_by_id(
"id_arch"), architecture) "id_arch"), architecture)
self.select_option(self.driver.find_element_by_id( self.select_option(self.driver.find_element_by_id(
...@@ -361,6 +379,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -361,6 +379,7 @@ class CircleSeleniumMixin(SeleniumMixin):
except: except:
logger.exception("Selenium cannot create a base" logger.exception("Selenium cannot create a base"
" template virtual machine") " template virtual machine")
self.create_screenshot()
raise Exception( raise Exception(
'Cannot create a base template virtual machine') 'Cannot create a base template virtual machine')
...@@ -427,6 +446,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -427,6 +446,7 @@ class CircleSeleniumMixin(SeleniumMixin):
return found_template_ids return found_template_ids
except: except:
logger.exception('Selenium cannot find the template\'s id') logger.exception('Selenium cannot find the template\'s id')
self.create_screenshot()
raise Exception( raise Exception(
'Cannot find the template\'s id') 'Cannot find the template\'s id')
...@@ -478,6 +498,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -478,6 +498,7 @@ class CircleSeleniumMixin(SeleniumMixin):
except: except:
logger.exception("Selenium cannot check the" logger.exception("Selenium cannot check the"
" result of an operation") " result of an operation")
self.create_screenshot()
raise Exception( raise Exception(
'Cannot check the result of an operation') 'Cannot check the result of an operation')
...@@ -510,6 +531,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -510,6 +531,7 @@ class CircleSeleniumMixin(SeleniumMixin):
except: except:
logger.exception("Selenium cannot filter timeline " logger.exception("Selenium cannot filter timeline "
"activities to find most recent") "activities to find most recent")
self.create_screenshot()
raise Exception( raise Exception(
'Cannot filter timeline activities to find most recent') 'Cannot filter timeline activities to find most recent')
...@@ -554,17 +576,20 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -554,17 +576,20 @@ class CircleSeleniumMixin(SeleniumMixin):
fallback_url, fallback_url,
lambda: self.get_timeline_elements(code)) lambda: self.get_timeline_elements(code))
else: else:
self.driver.save_screenshot('lost-timeline.png') self.create_screenshot()
raise Exception('Selenium could not locate the timeline') raise Exception('Selenium could not locate the timeline')
except: except:
logger.exception('Selenium cannot get timeline elemets') logger.exception('Selenium cannot get timeline elemets')
self.create_screenshot()
raise Exception('Cannot get timeline elements') raise Exception('Cannot get timeline elements')
if len(activity_dict) == 0: if len(activity_dict) == 0:
logger.warning('Found activity list is empty') logger.warning('Found activity list is empty')
self.create_screenshot()
raise Exception('Selenium did not found any activity') raise Exception('Selenium did not found any activity')
return activity_dict return activity_dict
except: except:
logger.exception('Selenium cannot find the searched activity') logger.exception('Selenium cannot find the searched activity')
self.create_screenshot()
raise Exception('Cannot find the searched activity') raise Exception('Cannot find the searched activity')
def create_template_from_base(self, delete_disk=True, name=None): def create_template_from_base(self, delete_disk=True, name=None):
...@@ -608,6 +633,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -608,6 +633,7 @@ class CircleSeleniumMixin(SeleniumMixin):
except: except:
logger.exception("Selenium cannot start a" logger.exception("Selenium cannot start a"
" template from a base one") " template from a base one")
self.create_screenshot()
raise Exception( raise Exception(
'Cannot start a template from a base one') 'Cannot start a template from a base one')
...@@ -634,6 +660,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -634,6 +660,7 @@ class CircleSeleniumMixin(SeleniumMixin):
'pk': template_id}) 'pk': template_id})
except: except:
logger.exception("Selenium cannot delete the desired template") logger.exception("Selenium cannot delete the desired template")
self.create_screenshot()
raise Exception('Cannot delete the desired template') raise Exception('Cannot delete the desired template')
def create_random_vm(self): def create_random_vm(self):
...@@ -663,6 +690,7 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -663,6 +690,7 @@ class CircleSeleniumMixin(SeleniumMixin):
return pk return pk
except: except:
logger.exception("Selenium cannot start a VM") logger.exception("Selenium cannot start a VM")
self.create_screenshot()
raise Exception('Cannot start a VM') raise Exception('Cannot start a VM')
def view_change(self, target_box): def view_change(self, target_box):
...@@ -729,4 +757,5 @@ class CircleSeleniumMixin(SeleniumMixin): ...@@ -729,4 +757,5 @@ class CircleSeleniumMixin(SeleniumMixin):
return False return False
except: except:
logger.exception("Selenium can not destroy a VM") logger.exception("Selenium can not destroy a VM")
raise Exception("Can not destroy a VM") self.create_screenshot()
raise Exception("Cannot destroy a VM")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment