Commit 66cfc891 authored by Gabriel L. Oliveira's avatar Gabriel L. Oliveira

2011-05-17 gabriel.oliveira

* refactor base test class to apply code patterns
parent 2e14569a
......@@ -2,78 +2,91 @@ from selenium import selenium
import unittest
import urllib2
from time import sleep
import os
ERP5_URL = "http://localhost:18080/erp5/"
UNG_URL = ERP5_URL + "web_site_module/ung/"
class BaseUNGTest(unittest.TestCase):
class UNGTestMixin(unittest.TestCase):
"""Base class for selenium UNG tests, containing useful methods."""
def setUp(self):
"""set up instance environment"""
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", UNG_URL)
self.selenium.start()
#do default actions
self.init()
def init(self):
"""clear cache, open default page, login, wait for activities
and then set default tree view as 'All Documents'"""
self.clear_cache()
self.open_ung_default_page()
self.login_as_default_user()
self.wait_for_activities()
self.set_default_tree_view()
#XXX all tests parsed may have
# <tal:block metal:use-macro="here/Zuite_CommonTemplateForUNG/macros/delete-all-documents"/>
# but it was omitted since it's not permited to delete objects
def init(self):
sel = self.selenium
sel.open("")
sel.wait_for_page_to_load(30000)
def login_as_default_user(self):
sel = self.selenium
#open default page -- equals to macros/init since user is already created
sel.open("")
sel.wait_for_page_to_load('30000')
"""login as default user 'test_user'"""
#login to access home page -- equals to macros/login
sel.type("name", "test_user")
sel.type("password", "test_user")
sel.click("logged_in:method")
sel.wait_for_page_to_load("30000")
self.selenium.type("name", "test_user")
self.selenium.type("password", "test_user")
self.selenium.click("logged_in:method")
self.selenium.wait_for_page_to_load("30000")
def set_default_tree_view(self):
"""select default opened tree view as 'All Documents'"""
try:
if not "All Documents" == self.selenium.get_text("//button[@class=\"tree-open\"]"):
self.selenium.click("//table[@class='your_listbox-table-domain-tree']/tbody/tr[1]/td/button")
self.selenium.wait_for_page_to_load("30000")
except:
self.selenium.click("//table[@class='your_listbox-table-domain-tree']/tbody/tr[1]/td/button")
self.selenium.wait_for_page_to_load("30000")
def clear_cache(self):
sel = self.selenium
sel.open("Base_clearCache")
sel.wait_for_page_to_load("30000")
"""call method 'Base_clearCache' of bt5 erp5_ui_test, that orders
portal_catalog to clear all allocated cache"""
self.selenium.open("Base_clearCache")
self.selenium.wait_for_page_to_load("30000")
def wait_for_activities(self):
"""wait untill all activities end up, trying 60 times to see it,
sleeping 2 seconds after each try"""
activities = urllib2.urlopen(ERP5_URL + 'portal_activities/getMessageList')
for _try in range(60):
#XXX 'readlines' is proxyfied, so url is opened everytime it's called
message_queue = activities.readlines()
if not message_queue:
break
sleep(2) #XXX give time to selenium to recompose page when refresh
unittest.time.sleep(2) #XXX give time to selenium to recompose page when refresh
def go_home(self, clear_cache=0, wait_for_activities=0):
sel = self.selenium
def open_ung_default_page(self, clear_cache=0, wait_for_activities=0):
"""open ung default page set under 'setUp'
clear_cache = if enabled, will call 'clear_cache'
wait_for_activities = if enabled, will call 'wait_for_activities'"""
if clear_cache:
self.clear_cache()
if wait_for_activities:
self.wait_for_activities()
sel.open("")
sel.wait_for_page_to_load("30000")
def set_default_tree_view(self):
sel = self.selenium
try:
if not "All Documents" == sel.get_text("//button[@class=\"tree-open\"]"):
sel.click("//table[@class='your_listbox-table-domain-tree']/tbody/tr[1]/td/button")
sel.wait_for_page_to_load("30000")
except:
sel.click("//table[@class='your_listbox-table-domain-tree']/tbody/tr[1]/td/button")
sel.wait_for_page_to_load("30000")
self.selenium.open("")
self.selenium.wait_for_page_to_load("30000")
def get_test_file_path(self, filename):
"""returns the absolute path to a test file given a 'filename'"""
return os.path.join(os.path.abspath(os.curdir), 'test_data', filename)
def tearDown(self):
"""method called immediately after the test method has been called and
the result recorded."""
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
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