Commit 30df125b authored by Rafael Monnerat's avatar Rafael Monnerat

Use page template instead a python script to render the selenium test

parent e920ddfd
......@@ -110,44 +110,22 @@ def urlread(url):
import urllib
return urllib.urlopen(url).read()
"""
Remove everything but the test in a webpage
"""
def extractTest(title, text):
def extractTest(text):
import lxml.html
from lxml import etree
root = lxml.html.fromstring(text)
table_list = root.xpath('//test')
html = """
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>"""+ title + """</title>
</head>
<body>
<table name="SELENIUM-TEST" cellpadding="1" cellspacing="1" border="1">
<thead>
<tr class="title">
<td colspan="3">"""+ title + """</td>
</tr>
</thead>
<tbody>
"""
testcode = ""
for table in table_list:
table = table[0]
if len(table) > 0:
for row in table[-1]:
if len(row) == 1:
# Include Macros as it is defined by the user.
html += row[0].text
testcode += row[0].text
else:
html += lxml.html.tostring(row)
html +="""
</tbody>
</table>
</body>
</html>"""
return html
\ No newline at end of file
testcode += lxml.html.tostring(row)
return testcode
......@@ -51,15 +51,20 @@
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Launch Test Embedded at the Test Page.\n
"""\n
reference = context.getReference()\n
if reference not in [None, \'\']:\n
zuite_id = reference\n
\n
return context.Zuite_createAndLaunchSeleniumTest(text=context.TestPage_getSeleniumTest(),\n
title=context.getTitle(), \n
zuite_id=zuite_id,\n
test_id=test_id)\n
test_script = getattr(context, \'Zuite_createAndLaunchSeleniumTest\', None)\n
if test_script is None:\n
raise ValueError("Unable to Launch the Test. Please install erp5_test_ui_core business template.")\n
\n
return test_script(text=context.TestPage_viewSeleniumTest(),\n
title=context.getTitle(), \n
zuite_id=zuite_id,\n
test_id=test_id)\n
</string> </value>
</item>
<item>
......
......@@ -2,14 +2,10 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
......@@ -24,18 +20,6 @@
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
......@@ -49,17 +33,50 @@
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>return context.TestPage_extractTest(context.getTitle(), context.getTextContent())\n
</string> </value>
<key> <string>_text</string> </key>
<value> <unicode encoding="cdata"><![CDATA[
<html xmlns:tal="http://xml.zope.org/namespaces/tal"\n
xmlns:metal="http://xml.zope.org/namespaces/metal">\n
<head>\n
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n
<title tal:content="context/title">The title</title>\n
</head>\n
<body>\n
<table name="SELENIUM-TEST" cellpadding="1" cellspacing="1" border="1">\n
<thead>\n
<tr class="title">\n
<td colspan="3" tal:content="context/title">title</td>\n
</tr>\n
</thead>\n
<tbody>\n
<tal:block tal:replace="structure python:context.TestPage_extractTest(context.getTextContent())" />\n
</tbody>\n
</table>\n
</body>\n
</html>
]]></unicode> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TestPage_getSeleniumTest</string> </value>
<value> <string>TestPage_viewSeleniumTest</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
......
53
\ No newline at end of file
54
\ No newline at end of file
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 to comment