Commit 03b27851 authored by Rafael Monnerat's avatar Rafael Monnerat

Accept url/user/password definition via URL on Selenium Test

This change permit via URL (or request) define custom base_url, user and password information when generate a test code. This generation can be always be blocked by redefining such information inside the test body itself.
parent 95360f72
...@@ -50,6 +50,25 @@ ...@@ -50,6 +50,25 @@
</tr>\n </tr>\n
</thead>\n </thead>\n
<tbody>\n <tbody>\n
<tr tal:condition="python: request.get(\'url\', None) is not None">\n
<td>store</td>\n
<td tal:content="python:request.get(\'url\', None)">http://example.com/erp5</td>\n
<td>base_url</td>\n
</tr>\n
<tal:block tal:condition="python: request.get(\'url\', None) is None">\n
&lt;span metal:use-macro=&quot;container/Zuite_CommonTemplate/macros/init&quot; style=&quot;display: none;&quot;&gt;init&lt;/span&gt;\n
</tal:block>\n
<tr>\n
<td>store</td>\n
<!-- ERP5TypeTestCase is the default for any UnitTest -->\n
<td tal:content="python:request.get(\'user\', \'ERP5TypeTestCase\')">User</td>\n
<td>base_user</td>\n
</tr>\n
<tr>\n
<td>store</td>\n
<td tal:content="python:request.get(\'password\', \'\')">Password</td>\n
<td>base_password</td>\n
</tr>\n
<tal:block tal:replace="structure python:context.TestPage_extractTest(context.getTextContent())" />\n <tal:block tal:replace="structure python:context.TestPage_extractTest(context.getTextContent())" />\n
</tbody>\n </tbody>\n
</table>\n </table>\n
......
...@@ -136,7 +136,7 @@ class TestRunMyDoc(ERP5TypeTestCase): ...@@ -136,7 +136,7 @@ class TestRunMyDoc(ERP5TypeTestCase):
self.assertEquals(image_page_2.getFilename(), image_reference + '.png') self.assertEquals(image_page_2.getFilename(), image_reference + '.png')
self.assertEquals(image_page.getData(), '') self.assertEquals(image_page.getData(), '')
def test_getSeleniumTest(self): def test_viewSeleniumTest(self):
""" """
Test the script that extracts Selenium Test from HTML body. Test the script that extracts Selenium Test from HTML body.
""" """
...@@ -174,9 +174,7 @@ class TestRunMyDoc(ERP5TypeTestCase): ...@@ -174,9 +174,7 @@ class TestRunMyDoc(ERP5TypeTestCase):
</tr> </tbody></table> </test> </tr> </tbody></table> </test>
</section>""" </section>"""
expected_test_html = """ expected_test_html = u"""<html>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TEST</title> <title>TEST</title>
...@@ -189,7 +187,22 @@ class TestRunMyDoc(ERP5TypeTestCase): ...@@ -189,7 +187,22 @@ class TestRunMyDoc(ERP5TypeTestCase):
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<span metal:use-macro="container/Zuite_viewTestMacroLibrary/macros/init_test_environment" style="display: none;">init</span><tr><td>selectAndWait</td>
&lt;span metal:use-macro=&quot;container/Zuite_CommonTemplate/macros/init&quot; style=&quot;display: none;&quot;&gt;init&lt;/span&gt;
<tr>
<td>store</td>
<!-- ERP5TypeTestCase is the default for any UnitTest -->
<td>%s</td>
<td>base_user</td>
</tr>
<tr>
<td>store</td>
<td>%s</td>
<td>base_password</td>
</tr>
<span metal:use-macro="container/Zuite_viewTestMacroLibrary/macros/init_test_environment" style="display: none;">init</span><tr><td>selectAndWait</td>
<td>name=select_module</td> <td>name=select_module</td>
<td>label=Test Pages</td> <td>label=Test Pages</td>
</tr><tr><td>verifyTextPresent</td> </tr><tr><td>verifyTextPresent</td>
...@@ -210,7 +223,8 @@ class TestRunMyDoc(ERP5TypeTestCase): ...@@ -210,7 +223,8 @@ class TestRunMyDoc(ERP5TypeTestCase):
test_page = self.portal.test_page_module.newContent(title="TEST", test_page = self.portal.test_page_module.newContent(title="TEST",
reference='TESTPAGEREFERENCE', reference='TESTPAGEREFERENCE',
text_content=test_page_html) text_content=test_page_html)
self.assertEquals(test_page.TestPage_getSeleniumTest(), expected_test_html) self.assertEquals(test_page.TestPage_viewSeleniumTest(), expected_test_html %
("ERP5TypeTestCase", ""))
self.stepTic() self.stepTic()
test_page.TestPage_runSeleniumTest() test_page.TestPage_runSeleniumTest()
...@@ -221,9 +235,75 @@ class TestRunMyDoc(ERP5TypeTestCase): ...@@ -221,9 +235,75 @@ class TestRunMyDoc(ERP5TypeTestCase):
zptest = getattr(zuite, "TEST", None) zptest = getattr(zuite, "TEST", None)
self.assertNotEquals(zptest, None) self.assertNotEquals(zptest, None)
self.assertEquals(zptest._text, expected_test_html.strip()) expected_html = expected_test_html % ("ERP5TypeTestCase", "")
self.assertEquals(zptest._text, expected_html.strip())
expected_test_html = """<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TEST</title>
</head>
<body>
<table name="SELENIUM-TEST" cellpadding="1" cellspacing="1" border="1">
<thead>
<tr class="title">
<td colspan="3">TEST</td>
</tr>
</thead>
<tbody>
<tr>
<td>store</td>
<td>%s</td>
<td>base_url</td>
</tr>
<tr>
<td>store</td>
<!-- ERP5TypeTestCase is the default for any UnitTest -->
<td>%s</td>
<td>base_user</td>
</tr>
<tr>
<td>store</td>
<td>%s</td>
<td>base_password</td>
</tr>
<span metal:use-macro="container/Zuite_viewTestMacroLibrary/macros/init_test_environment" style="display: none;">init</span><tr><td>selectAndWait</td>
<td>name=select_module</td>
<td>label=Test Pages</td>
</tr><tr><td>verifyTextPresent</td>
<td>Test Pages</td>
<td> <br></td>
</tr><tr style="opacity: 1;"><td>clickAndWait</td>
<td>css=a.fast_input &gt; span.image</td>
<td> <br></td>
</tr><tr><td>verifyTextPresent</td>
<td>Test Pages</td>
<td> <br></td>
</tr>
</tbody>
</table>
</body>
</html>"""
# Mimic usage of TestPage_viewSeleniumTest?url=...
self.portal.REQUEST['url'] = "http://toto.com"
self.portal.REQUEST['user'] = "toto"
self.portal.REQUEST['password'] = "toto"
self.assertEquals(test_page.TestPage_viewSeleniumTest(REQUEST=self.portal.REQUEST),
expected_test_html % ("http://toto.com", "toto", "toto"))
self.stepTic()
test_page.TestPage_runSeleniumTest()
zuite = getattr(self.portal.portal_tests, 'TESTPAGEREFERENCE', None)
self.assertNotEquals(zuite, None)
zptest = getattr(zuite, "TEST", None)
self.assertNotEquals(zptest, None)
expected_html = expected_test_html % ("http://toto.com", "toto", "toto")
self.assertEquals(zptest._text, expected_html.strip())
55 56
\ No newline at end of file \ 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