Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Papa Tamsir Kane
erp5
Commits
303caa3b
Commit
303caa3b
authored
May 11, 2017
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "ERP5Type/tests: process test result with xml parser"
This reverts commit
814afaf3
.
parent
bbd34edd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
49 deletions
+36
-49
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
+36
-49
No files found.
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
View file @
303caa3b
...
@@ -40,13 +40,21 @@ from zExceptions.ExceptionFormatter import format_exception
...
@@ -40,13 +40,21 @@ from zExceptions.ExceptionFormatter import format_exception
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
,
\
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
,
\
_getConversionServerDict
_getConversionServerDict
from
Products.ERP5Type.Utils
import
stopProcess
,
PR_SET_PDEATHSIG
from
Products.ERP5Type.Utils
import
stopProcess
,
PR_SET_PDEATHSIG
from
lxml
import
etree
from
lxml.html
import
builder
as
E
from
selenium
import
webdriver
from
selenium
import
webdriver
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
EC
from
selenium.webdriver.support
import
expected_conditions
as
EC
from
selenium.webdriver.firefox.firefox_binary
import
FirefoxBinary
# REGEX FOR ZELENIUM TESTS
TEST_PASS_RE
=
re
.
compile
(
'<th[^>]*>Tests passed</th>
\
n
\
s*<
t
d[^>]*>([^<]*)'
)
TEST_FAILURE_RE
=
re
.
compile
(
'<th[^>]*>Tests failed</th>
\
n
\
s*<
t
d[^>]*>([^<]*)'
)
IMAGE_RE
=
re
.
compile
(
'<img[^>]*?>'
)
TEST_ERROR_TITLE_RE
=
re
.
compile
(
'(?:error.gif.*?>|title status_failed"><td[^>]*>)([^>]*?)</td></tr>'
,
re
.
S
)
TEST_RESULT_RE
=
re
.
compile
(
'<div style="padding-top: 10px;">
\
s*<p>
\
s*'
'<img.*?</div>
\
s.*?</di
v
>
\
s*
'
, re.S)
TEST_ERROR_RESULT_RE = re.compile('
.
*
(
?
:
error
.
gif
|
title
status_failed
).
*
', re.S)
EXPECTED_FAILURE_RE = re.compile('
.
*
expected
failure
.
*
', re.I)
ZELENIUM_BASE_URL = "%s/portal_tests/%s/core/TestRunner.html?test=../test_suite_html&auto=on&resultsUrl=../postResults&__ac_name=%s&__ac_password=%s"
ZELENIUM_BASE_URL = "%s/portal_tests/%s/core/TestRunner.html?test=../test_suite_html&auto=on&resultsUrl=../postResults&__ac_name=%s&__ac_password=%s"
...
@@ -155,10 +163,8 @@ class FunctionalTestRunner:
...
@@ -155,10 +163,8 @@ class FunctionalTestRunner:
firefox_driver = firefox_bin.replace("firefox-slapos", "geckodriver")
firefox_driver = firefox_bin.replace("firefox-slapos", "geckodriver")
firefox_capabilities = webdriver.common.desired_capabilities.DesiredCapabilities.FIREFOX
firefox_capabilities = webdriver.common.desired_capabilities.DesiredCapabilities.FIREFOX
firefox_capabilities['
marionette
'] = True
firefox_capabilities['
marionette
'] = True
browser
=
webdriver
.
Firefox
(
firefox_capabilities['
binary
'] = firefox_bin
capabilities
=
firefox_capabilities
,
browser = webdriver.Firefox(capabilities=firefox_capabilities, executable_path=firefox_driver)
executable_path
=
firefox_driver
,
firefox_binary
=
FirefoxBinary
(
firefox_bin
))
start_time = time.time()
start_time = time.time()
browser.get(self._getTestURL())
browser.get(self._getTestURL())
...
@@ -174,49 +180,30 @@ class FunctionalTestRunner:
...
@@ -174,49 +180,30 @@ class FunctionalTestRunner:
WebDriverWait(browser, self.timeout).until(EC.presence_of_element_located((
WebDriverWait(browser, self.timeout).until(EC.presence_of_element_located((
By.XPATH, '
//
td
[
@
id
=
"testRuns"
and
contains
(
text
(),
"%i"
)]
' % test_count
By.XPATH, '
//
td
[
@
id
=
"testRuns"
and
contains
(
text
(),
"%i"
)]
' % test_count
)))
)))
self
.
execution_duration
=
round
(
time
.
time
()
-
start_time
,
2
)
html_parser
=
etree
.
HTMLParser
(
recover
=
True
)
iframe
=
etree
.
fromstring
(
browser
.
execute_script
(
"return document.getElementById('testSuiteFrame').contentDocument.querySelector('html').innerHTML"
).
encode
(
'UTF-8'
),
html_parser
)
browser
.
quit
()
finally:
finally:
xvfb.quit()
xvfb.quit()
return
iframe
def processResult(self):
def
processResult
(
self
,
iframe
):
file_content = self.getStatus().encode("utf-8", "replace")
tbody
=
iframe
.
xpath
(
'.//body/table/tbody'
)[
0
]
sucess_amount = int(TEST_PASS_RE.search(file_content).group(1))
tr_count
=
failure_amount
=
expected_failure_amount
=
0
failure_amount = int(TEST_FAILURE_RE.search(file_content).group(1))
error_title_list
=
[]
error_title_list = [re.compile('
\
s
+
').sub('
', x).strip()
detail
=
""
for x in TEST_ERROR_TITLE_RE.findall(file_content)]
for
tr
in
tbody
:
if
tr_count
:
is_expected_failure = lambda x: EXPECTED_FAILURE_RE.match(x)
# First td is the main title
expected_failure_amount = len(filter(is_expected_failure, error_title_list))
test_name
=
tr
[
0
][
0
].
text
# Remove expected failures from list
error
=
False
error_title_list = filter(lambda x: not is_expected_failure(x), error_title_list)
if
len
(
tr
)
==
1
:
failure_amount -= expected_failure_amount
# Test was not executed
failure
+=
1
detail = ''
detail
+=
'Test '
+
test_name
+
' not executed'
for test_result in TEST_RESULT_RE.findall(file_content):
error_title_list
.
append
(
test_name
)
if TEST_ERROR_RESULT_RE.match(test_result):
else
:
detail += test_result
test_table
=
tr
[
1
].
xpath
(
'.//table'
)[
0
]
status
=
tr
.
attrib
.
get
(
'class'
)
detail = IMAGE_RE.sub('', detail)
if
'status_failed'
in
status
:
if
etree
.
tostring
(
test_table
).
find
(
"expected failure"
)
!=
-
1
:
expected_failure_amount
+=
1
else
:
failure_amount
+=
1
error_title_list
.
append
(
test_name
)
detail_element
=
E
.
DIV
()
detail_element
.
append
(
E
.
DIV
(
E
.
P
(
test_name
),
E
.
BR
,
test_table
))
detail
+=
etree
.
tostring
(
detail_element
)
tr_count
+=
1
sucess_amount
=
tr_count
-
1
-
failure_amount
-
expected_failure_amount
if detail:
if detail:
detail = IMAGE_RE.sub('', detail)
detail = '''<html>
detail = '''<html>
<head>
<head>
<style type="text/css">tr.status_failed { background-color:red };</style>
<style type="text/css">tr.status_failed { background-color:red };</style>
...
@@ -307,7 +294,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
...
@@ -307,7 +294,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
debug = self.foreground or os.environ.get("erp5_debug_mode")
debug = self.foreground or os.environ.get("erp5_debug_mode")
error = None
error = None
try:
try:
iframe
=
self
.
runner
.
test
(
debug
=
debug
)
self.runner.test(debug=debug)
except TimeoutError, e:
except TimeoutError, e:
error = repr(e)
error = repr(e)
self._verboseErrorLog(20)
self._verboseErrorLog(20)
...
@@ -319,7 +306,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
...
@@ -319,7 +306,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
self._verboseErrorLog(20)
self._verboseErrorLog(20)
detail, success, failure,
\
detail, success, failure,
\
expected_failure
,
error_title_list
=
self
.
runner
.
processResult
(
iframe
)
expected_failure, error_title_list = self.runner.processResult()
self.logMessage("-" * 79)
self.logMessage("-" * 79)
total = success + failure + expected_failure
total = success + failure + expected_failure
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment