Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
officejs
Commits
66cfc891
Commit
66cfc891
authored
May 17, 2011
by
Gabriel L. Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2011-05-17 gabriel.oliveira
* refactor base test class to apply code patterns
parent
2e14569a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
UNGTestMixin.py
UNGTestMixin.py
+92
-0
No files found.
base
.py
→
UNGTestMixin
.py
View file @
66cfc891
...
@@ -2,78 +2,91 @@ from selenium import selenium
...
@@ -2,78 +2,91 @@ from selenium import selenium
import
unittest
import
unittest
import
urllib2
import
urllib2
from
time
import
sleep
import
os
import
os
ERP5_URL
=
"http://localhost:18080/erp5/"
ERP5_URL
=
"http://localhost:18080/erp5/"
UNG_URL
=
ERP5_URL
+
"web_site_module/ung/"
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
):
def
setUp
(
self
):
"""set up instance environment"""
self
.
verificationErrors
=
[]
self
.
verificationErrors
=
[]
self
.
selenium
=
selenium
(
"localhost"
,
4444
,
"*chrome"
,
UNG_URL
)
self
.
selenium
=
selenium
(
"localhost"
,
4444
,
"*chrome"
,
UNG_URL
)
self
.
selenium
.
start
()
self
.
selenium
.
start
()
#XXX all tests parsed may have
#do default actions
# <tal:block metal:use-macro="here/Zuite_CommonTemplateForUNG/macros/delete-all-documents"/>
self
.
init
()
# but it was omitted since it's not permited to delete objects
def
init
(
self
):
def
init
(
self
):
sel
=
self
.
selenium
"""clear cache, open default page, login, wait for activities
sel
.
open
(
""
)
and then set default tree view as 'All Documents'"""
sel
.
wait_for_page_to_load
(
30000
)
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
login_as_default_user
(
self
):
def
login_as_default_user
(
self
):
sel
=
self
.
selenium
"""login as default user 'test_user'"""
#open default page -- equals to macros/init since user is already created
sel
.
open
(
""
)
sel
.
wait_for_page_to_load
(
'30000'
)
#login to access home page -- equals to macros/login
#login to access home page -- equals to macros/login
sel
.
type
(
"name"
,
"test_user"
)
self
.
selenium
.
type
(
"name"
,
"test_user"
)
sel
.
type
(
"password"
,
"test_user"
)
self
.
selenium
.
type
(
"password"
,
"test_user"
)
sel
.
click
(
"logged_in:method"
)
self
.
selenium
.
click
(
"logged_in:method"
)
sel
.
wait_for_page_to_load
(
"30000"
)
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
):
def
clear_cache
(
self
):
sel
=
self
.
selenium
"""call method 'Base_clearCache' of bt5 erp5_ui_test, that orders
sel
.
open
(
"Base_clearCache"
)
portal_catalog to clear all allocated cache"""
sel
.
wait_for_page_to_load
(
"30000"
)
self
.
selenium
.
open
(
"Base_clearCache"
)
self
.
selenium
.
wait_for_page_to_load
(
"30000"
)
def
wait_for_activities
(
self
):
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'
)
activities
=
urllib2
.
urlopen
(
ERP5_URL
+
'portal_activities/getMessageList'
)
for
_try
in
range
(
60
):
for
_try
in
range
(
60
):
#XXX 'readlines' is proxyfied, so url is opened everytime it's called
#XXX 'readlines' is proxyfied, so url is opened everytime it's called
message_queue
=
activities
.
readlines
()
message_queue
=
activities
.
readlines
()
if
not
message_queue
:
if
not
message_queue
:
break
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
):
def
open_ung_default_page
(
self
,
clear_cache
=
0
,
wait_for_activities
=
0
):
sel
=
self
.
selenium
"""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
:
if
clear_cache
:
self
.
clear_cache
()
self
.
clear_cache
()
if
wait_for_activities
:
if
wait_for_activities
:
self
.
wait_for_activities
()
self
.
wait_for_activities
()
sel
.
open
(
""
)
self
.
selenium
.
open
(
""
)
sel
.
wait_for_page_to_load
(
"30000"
)
self
.
selenium
.
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"
)
def
get_test_file_path
(
self
,
filename
):
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
)
return
os
.
path
.
join
(
os
.
path
.
abspath
(
os
.
curdir
),
'test_data'
,
filename
)
def
tearDown
(
self
):
def
tearDown
(
self
):
"""method called immediately after the test method has been called and
the result recorded."""
self
.
selenium
.
stop
()
self
.
selenium
.
stop
()
self
.
assertEqual
([],
self
.
verificationErrors
)
self
.
assertEqual
([],
self
.
verificationErrors
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
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