Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba19ad0
Merge pull request #1 in IFT/robotframework-selenium2library from QAR…
eweitz Aug 19, 2014
54b7709
Merge pull request #2 in IFT/robotframework-selenium2library from neg…
eweitz Aug 22, 2014
45b588b
Modified the run-on-failure mechanism so that only one screenshot is …
dpsfrishberg Oct 8, 2014
6007ac0
Added comments
dpsfrishberg Oct 9, 2014
c0d0eab
Fixed indentation
dpsfrishberg Oct 9, 2014
4c7e074
Added test
dpsfrishberg Oct 10, 2014
d39b3db
Fixed reference in resourse.txt
dpsfrishberg Oct 10, 2014
0465c8f
Moved run-on-failure test to new file
dpsfrishberg Oct 10, 2014
37822fc
Fixed test
dpsfrishberg Oct 10, 2014
fc1174b
Setting keyword to run on failure
dpsfrishberg Oct 10, 2014
44815c5
Tests are working now
dpsfrishberg Nov 4, 2014
81a673e
Restored permissions
dpsfrishberg Nov 4, 2014
0636b6d
Merge remote-tracking branch 'rtomac/master'
dpsfrishberg Nov 7, 2014
1e4d418
Merge branch 'master' into run-on-failure-flag
dpsfrishberg Nov 7, 2014
795a67c
Modified the run-on-failure mechanism so that only one screenshot is …
dpsfrishberg Oct 8, 2014
46a1343
Added comments
dpsfrishberg Oct 9, 2014
4095549
Fixed indentation
dpsfrishberg Oct 9, 2014
f9f48c3
Added test
dpsfrishberg Oct 10, 2014
d6b29f8
Fixed reference in resourse.txt
dpsfrishberg Oct 10, 2014
e13f9ba
Moved run-on-failure test to new file
dpsfrishberg Oct 10, 2014
5e35ce8
Fixed test
dpsfrishberg Oct 10, 2014
97340ed
Setting keyword to run on failure
dpsfrishberg Oct 10, 2014
b07cee2
Tests are working now
dpsfrishberg Nov 4, 2014
e6bc25d
Restored permissions
dpsfrishberg Nov 4, 2014
32fb53e
Simplified browser management for run-on-failure test
dpsfrishberg Nov 7, 2014
e713ed4
Moved run_on_failure_only_once test out into run_on_failure.txt
dpsfrishberg May 12, 2015
213f634
Moving tests into run_on_failure.txt
dpsfrishberg May 12, 2015
73c296f
Comments
dpsfrishberg May 12, 2015
1206fad
Comments
dpsfrishberg May 12, 2015
2025650
Removing old test file
dpsfrishberg May 12, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Selenium2Library/keywords/keywordgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@
decorator = None # decorator module doesn't work with IronPython 2.6

def _run_on_failure_decorator(method, *args, **kwargs):
self = args[0]
already_in_keyword = getattr(self, "_already_in_keyword", False) # If False, we are in the outermost keyword (or in `run_keyword`, if it's a dynamic library)
self._already_in_keyword = True # Set a flag on the instance so that as we call keywords inside this call and this gets run again, we know we're at least one level in.
try:
return method(*args, **kwargs)
except Exception, err:
self = args[0]
if hasattr(self, '_run_on_failure'):
if hasattr(self, '_run_on_failure') and not self._has_run_on_failure:
# If we're in an inner keyword, track the fact that we've already run on failure once
self._has_run_on_failure = True
self._run_on_failure()
raise
finally:
if not already_in_keyword:
# If we are in the outer call, reset the flags.
self._already_in_keyword = False
self._has_run_on_failure = False

class KeywordGroupMetaClass(type):
def __new__(cls, clsname, bases, dict):
Expand Down
25 changes: 24 additions & 1 deletion test/acceptance/keywords/run_on_failure.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
*** Settings ***
Suite Setup Run Keywords Go To Front Page Set Info Loglevel
Suite Teardown Set Debug Loglevel
Test Teardown Register Keyword to Run on Failure Nothing
Resource ../resource.txt

*** Variables ***
${PAGE TITLE} (root)/index.html
${FAILURE MESSAGE} Page should not have contained text 'needle'
${old order}

*** Keywords ***
On Fail
${count}= Evaluate ${ON FAIL COUNT} + 1
Set Test Variable ${ON FAIL COUNT} ${count}

Prefer Custom Keywords
Import Library CustomSeleniumKeywords
${old order}= Set Library Search Order CustomSeleniumKeywords

Restore Old Search Order
Set Library Search Order ${old order}

Open Browser To Front Page
Open Browser ${FRONT PAGE}

*** Test Cases ***
Run On Failure Keyword Only Called Once
[Setup] Prefer Custom Keywords
Set Test Variable ${ON FAIL COUNT} ${0}
Register Keyword To Run On Failure On Fail
Run Keyword And Ignore Error Custom Selenium Keyword
Should Be Equal ${ON FAIL COUNT} ${1} On Failure Keyword called ${ON FAIL COUNT} times.
[Teardown] Register Keyword to Run On Failure Nothing

Log Title On Failure
[Documentation] LOG 1 Log Title will be run on failure. LOG 2:2 NONE LOG 3.1.1:1 ${PAGE TITLE} LOG 3.1:3 NONE
Register Keyword to Run on Failure Log Title
Expand Down
Empty file modified test/acceptance/resource.txt
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions test/env.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ACCEPTANCE_TEST_DIR = os.path.join(ROOT_DIR, "acceptance")
LIB_DIR = os.path.join(ROOT_DIR, "lib")
RESOURCES_DIR = os.path.join(ROOT_DIR, "resources")
TEST_LIBS_DIR = os.path.join(RESOURCES_DIR, "testlibs")
RESULTS_DIR = os.path.join(ROOT_DIR, "results")
HTTP_SERVER_FILE = os.path.join(RESOURCES_DIR, 'testserver', 'testserver.py')
SRC_DIR = os.path.join(ROOT_DIR, "..", "src")
Expand Down
18 changes: 18 additions & 0 deletions test/resources/testlibs/CustomSeleniumKeywords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from Selenium2Library import Selenium2Library
from robot.utils import asserts
from robot.libraries.BuiltIn import BuiltIn

class CustomSeleniumKeywords(Selenium2Library):

def __init__(self, *args, **kwargs):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've got everything in the one test file, but I had to introduce this __init__ hack, so that the Go To command would work with this library.

"""Share `Selenium2Library`'s cache of browsers, so that
we don't have to open a separate browser instance for the
`Run On Failure Keyword Only Called Once` test."""
ret = super(CustomSeleniumKeywords, self).__init__(*args, **kwargs)
self._cache = BuiltIn().get_library_instance("Selenium2Library")._cache

def custom_selenium_keyword(self):
self.custom_selenium_keyword_inner()

def custom_selenium_keyword_inner(self):
asserts.assert_false(True)
2 changes: 1 addition & 1 deletion test/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'--critical', 'regression',
'--noncritical', 'inprogress',
]
ARG_VALUES = {'outdir': env.RESULTS_DIR, 'pythonpath': env.SRC_DIR}
ARG_VALUES = {'outdir': env.RESULTS_DIR, 'pythonpath': ':'.join((env.SRC_DIR, env.TEST_LIBS_DIR))}

def acceptance_tests(interpreter, browser, args):
ARG_VALUES['browser'] = browser.replace('*', '')
Expand Down