From 30df125bbfa41f48e7bb43adf354665083764819 Mon Sep 17 00:00:00 2001 From: Rafael Monnerat <rafael@nexedi.com> Date: Thu, 1 Mar 2012 01:20:34 -0300 Subject: [PATCH] Use page template instead a python script to render the selenium test --- .../ExtensionTemplateItem/ERP5RunMyDocs.py | 32 ++----- .../TestPage_getSeleniumTest.xml | 67 --------------- .../TestPage_runSeleniumTest.xml | 13 ++- .../TestPage_viewSeleniumTest.xml | 84 +++++++++++++++++++ bt5/erp5_run_my_doc/bt/revision | 2 +- 5 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_getSeleniumTest.xml create mode 100644 bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_viewSeleniumTest.xml diff --git a/bt5/erp5_run_my_doc/ExtensionTemplateItem/ERP5RunMyDocs.py b/bt5/erp5_run_my_doc/ExtensionTemplateItem/ERP5RunMyDocs.py index b08a55353b..23d484f3d9 100644 --- a/bt5/erp5_run_my_doc/ExtensionTemplateItem/ERP5RunMyDocs.py +++ b/bt5/erp5_run_my_doc/ExtensionTemplateItem/ERP5RunMyDocs.py @@ -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 diff --git a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_getSeleniumTest.xml b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_getSeleniumTest.xml deleted file mode 100644 index d0f4b543bd..0000000000 --- a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_getSeleniumTest.xml +++ /dev/null @@ -1,67 +0,0 @@ -<?xml version="1.0"?> -<ZopeData> - <record id="1" aka="AAAAAAAAAAE="> - <pickle> - <global name="PythonScript" module="Products.PythonScripts.PythonScript"/> - </pickle> - <pickle> - <dictionary> - <item> - <key> <string>Script_magic</string> </key> - <value> <int>3</int> </value> - </item> - <item> - <key> <string>_bind_names</string> </key> - <value> - <object> - <klass> - <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> - </klass> - <tuple/> - <state> - <dictionary> - <item> - <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> - </item> - </dictionary> - </value> - </item> - </dictionary> - </state> - </object> - </value> - </item> - <item> - <key> <string>_body</string> </key> - <value> <string>return context.TestPage_extractTest(context.getTitle(), context.getTextContent())\n -</string> </value> - </item> - <item> - <key> <string>_params</string> </key> - <value> <string></string> </value> - </item> - <item> - <key> <string>id</string> </key> - <value> <string>TestPage_getSeleniumTest</string> </value> - </item> - </dictionary> - </pickle> - </record> -</ZopeData> diff --git a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_runSeleniumTest.xml b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_runSeleniumTest.xml index 31ebe20af9..6a86bf98a0 100644 --- a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_runSeleniumTest.xml +++ b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_runSeleniumTest.xml @@ -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> diff --git a/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_viewSeleniumTest.xml b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_viewSeleniumTest.xml new file mode 100644 index 0000000000..ad962fc9bc --- /dev/null +++ b/bt5/erp5_run_my_doc/SkinTemplateItem/portal_skins/erp5_run_my_doc/TestPage_viewSeleniumTest.xml @@ -0,0 +1,84 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <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>expand</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>id</string> </key> + <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> + </record> +</ZopeData> diff --git a/bt5/erp5_run_my_doc/bt/revision b/bt5/erp5_run_my_doc/bt/revision index 8783e30511..43c451e0c6 100644 --- a/bt5/erp5_run_my_doc/bt/revision +++ b/bt5/erp5_run_my_doc/bt/revision @@ -1 +1 @@ -53 \ No newline at end of file +54 \ No newline at end of file -- 2.30.9