Add _save_screenshot functionality to helpers.
Having screenshot of failed test might increase speed of understanding the failure reason. partially-implements blueprint: selenium-integration-testing Depends-On: I0fd89ede7a3d04ce9b4bd4c8fba0789770048d40 Change-Id: Ibc4a6235423736e5938fb348bbe83211917b08d1
This commit is contained in:
parent
bd71ffe34b
commit
bc109d33ed
|
@ -22,6 +22,7 @@ openstack_dashboard/wsgi/horizon.wsgi
|
||||||
doc/build/
|
doc/build/
|
||||||
doc/source/sourcecode
|
doc/source/sourcecode
|
||||||
/static/
|
/static/
|
||||||
|
integration_tests_screenshots/
|
||||||
.venv
|
.venv
|
||||||
.tox
|
.tox
|
||||||
node_modules
|
node_modules
|
||||||
|
|
|
@ -74,12 +74,16 @@ Pros:
|
||||||
* Catches *many* bugs that unit and functional tests will not.
|
* Catches *many* bugs that unit and functional tests will not.
|
||||||
* Doesn't rely on assumptions about the inputs and outputs.
|
* Doesn't rely on assumptions about the inputs and outputs.
|
||||||
* Will warn you when changes in external components break your code.
|
* Will warn you when changes in external components break your code.
|
||||||
|
* Will take screenshot of the current page on test fail for easy debug
|
||||||
|
|
||||||
Cons:
|
Cons:
|
||||||
|
|
||||||
* Difficult and time-consuming to create a repeatable test environment.
|
* Difficult and time-consuming to create a repeatable test environment.
|
||||||
* Did I mention that setting it up is a pain?
|
* Did I mention that setting it up is a pain?
|
||||||
|
|
||||||
|
Screenshot directory could be set through horizon.conf file, default value:
|
||||||
|
"./integration_tests_screenshots"
|
||||||
|
|
||||||
So what should I write?
|
So what should I write?
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,9 @@ SeleniumGroup = [
|
||||||
cfg.IntOpt('page_timeout',
|
cfg.IntOpt('page_timeout',
|
||||||
default=30,
|
default=30,
|
||||||
help="Page load timeout in seconds"),
|
help="Page load timeout in seconds"),
|
||||||
|
cfg.StrOpt('screenshots_directory',
|
||||||
|
default="integration_tests_screenshots",
|
||||||
|
help="Output screenshot directory"),
|
||||||
]
|
]
|
||||||
|
|
||||||
ScenarioGroup = [
|
ScenarioGroup = [
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import uuid
|
import uuid
|
||||||
|
@ -22,6 +24,11 @@ from openstack_dashboard.test.integration_tests import config
|
||||||
from openstack_dashboard.test.integration_tests.pages import loginpage
|
from openstack_dashboard.test.integration_tests.pages import loginpage
|
||||||
from openstack_dashboard.test.integration_tests import webdriver
|
from openstack_dashboard.test.integration_tests import webdriver
|
||||||
|
|
||||||
|
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
if ROOT_PATH not in sys.path:
|
||||||
|
sys.path.append(ROOT_PATH)
|
||||||
|
|
||||||
|
|
||||||
def gen_random_resource_name(resource="", timestamp=True):
|
def gen_random_resource_name(resource="", timestamp=True):
|
||||||
"""Generate random resource name using uuid and timestamp.
|
"""Generate random resource name using uuid and timestamp.
|
||||||
|
@ -64,6 +71,7 @@ class BaseTestCase(testtools.TestCase):
|
||||||
self.driver.set_page_load_timeout(
|
self.driver.set_page_load_timeout(
|
||||||
self.CONFIG.selenium.page_timeout)
|
self.CONFIG.selenium.page_timeout)
|
||||||
self.addOnException(self._dump_page_html_source)
|
self.addOnException(self._dump_page_html_source)
|
||||||
|
self.addOnException(self._save_screenshot)
|
||||||
else:
|
else:
|
||||||
msg = "The INTEGRATION_TESTS env variable is not set."
|
msg = "The INTEGRATION_TESTS env variable is not set."
|
||||||
raise self.skipException(msg)
|
raise self.skipException(msg)
|
||||||
|
@ -82,6 +90,21 @@ class BaseTestCase(testtools.TestCase):
|
||||||
finally:
|
finally:
|
||||||
self.addDetail("PageHTMLSource.html", content)
|
self.addDetail("PageHTMLSource.html", content)
|
||||||
|
|
||||||
|
def _save_screenshot(self, exc_info):
|
||||||
|
screenshot_dir = os.path.join(
|
||||||
|
ROOT_PATH,
|
||||||
|
self.CONFIG.selenium.screenshots_directory)
|
||||||
|
if not os.path.exists(screenshot_dir):
|
||||||
|
os.makedirs(screenshot_dir)
|
||||||
|
date_string = datetime.datetime.now().strftime(
|
||||||
|
'%Y.%m.%d-%H%M%S')
|
||||||
|
test_name = self._testMethodName
|
||||||
|
name = '%s_%s.png' % (test_name, date_string)
|
||||||
|
filename = os.path.join(screenshot_dir, name)
|
||||||
|
self.driver.get_screenshot_as_file(filename)
|
||||||
|
content = testtools.content.text_content(filename)
|
||||||
|
self.addDetail("Screenshot", content)
|
||||||
|
|
||||||
def _get_page_html_source(self):
|
def _get_page_html_source(self):
|
||||||
"""Gets html page source.
|
"""Gets html page source.
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,10 @@ help_url=http://docs.openstack.org/
|
||||||
# (integer value)
|
# (integer value)
|
||||||
page_timeout=30
|
page_timeout=30
|
||||||
|
|
||||||
|
# Output directory for screenshots.
|
||||||
|
# (string value)
|
||||||
|
screenshots_directory=integration_tests_screenshots
|
||||||
|
|
||||||
# Implicit timeout to wait until element become available,
|
# Implicit timeout to wait until element become available,
|
||||||
# this timeout is used for every find_element, find_elements call.
|
# this timeout is used for every find_element, find_elements call.
|
||||||
# (integer value)
|
# (integer value)
|
||||||
|
|
Loading…
Reference in New Issue