Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos-mynij-dev
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mynij
slapos-mynij-dev
Commits
64d452d2
Commit
64d452d2
authored
Oct 18, 2011
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress : seleniumrunner
parent
57432a28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
112 deletions
+99
-112
slapos/recipe/selenium/__init__.py
slapos/recipe/selenium/__init__.py
+72
-89
slapos/recipe/selenium/testrunner.py
slapos/recipe/selenium/testrunner.py
+27
-23
No files found.
slapos/recipe/selenium/__init__.py
View file @
64d452d2
...
...
@@ -29,94 +29,77 @@ import os
import
sys
import
zc.buildout
from
slapos.recipe.librecipe
import
BaseSlapRecipe
import
pkg_resources
class
Recipe
(
BaseSlapRecipe
):
def
_install
(
self
):
"""
Set the connection dictionnary for the computer partition and create a list
of paths to the different wrappers
Parameters : none
Returns : List path_list
"""
self
.
path_list
=
[]
self
.
requirements
,
self
.
ws
=
self
.
egg
.
working_set
()
self
.
instanciateTestRunner
(
self
.
getDisplay
())
self
.
linkBinary
()
return
self
.
path_list
def
getDisplay
(
self
):
"""
Choose a display for the instance
Parameters : None
Returns : display
"""
display_list
=
[
":%s"
%
i
for
i
in
range
(
123
,
144
)]
for
display_try
in
display_list
:
lock_filepath
=
'/tmp/.X%s-lock'
%
display_try
.
replace
(
":"
,
""
)
if
not
os
.
path
.
exists
(
lock_filepath
):
display
=
display_try
break
return
display
def
instanciateTestRunner
(
self
,
display
):
"""
Instanciate a wrapper for the browser and the test report's
Parameters : display on which the browser will run
Returns : None
"""
if
self
.
parameter_dict
[
'browser'
]
==
'chrome'
or
self
.
parameter_dict
[
'browser'
]
==
'chromium'
:
self
.
path_list
.
extend
(
zc
.
buildout
.
easy_install
.
scripts
([(
'testrunner'
,
__name__
+
'.testrunner'
,
'run'
)],
self
.
ws
,
sys
.
executable
,
self
.
wrapper_directory
,
arguments
=
[
dict
(
browser_binary
=
self
.
options
[
'chromium_binary'
],
xvfb_binary
=
self
.
options
[
'xvfb_binary'
],
display
=
display
,
option_ssl
=
'--ignore-certificate-errors'
,
option_translate
=
'--disable-translate'
,
option_security
=
'--disable-web-security'
,
suite_name
=
self
.
parameter_dict
[
'suite_name'
],
base_url
=
self
.
parameter_dict
[
'url'
],
user
=
self
.
parameter_dict
[
'user'
],
password
=
self
.
parameter_dict
[
'password'
]
)]))
def
linkBinary
(
self
):
"""Links binaries to instance's bin directory for easier exposal"""
for
linkline
in
self
.
options
.
get
(
'link_binary_list'
,
''
).
splitlines
():
if
not
linkline
:
continue
target
=
linkline
.
split
()
if
len
(
target
)
==
1
:
target
=
target
[
0
]
path
,
linkname
=
os
.
path
.
split
(
target
)
else
:
linkname
=
target
[
1
]
target
=
target
[
0
]
link
=
os
.
path
.
join
(
self
.
bin_directory
,
linkname
)
if
os
.
path
.
lexists
(
link
):
if
not
os
.
path
.
islink
(
link
):
raise
zc
.
buildout
.
UserError
(
'Target link already %r exists but it is not link'
%
link
)
os
.
unlink
(
link
)
os
.
symlink
(
target
,
link
)
self
.
logger
.
debug
(
'Created link %r -> %r'
%
(
link
,
target
))
self
.
path_list
.
append
(
link
)
def
_install
(
self
):
"""Set the connection dictionnary for the computer partition and create a list
of paths to the different wrappers."""
self
.
path_list
=
[]
self
.
requirements
,
self
.
ws
=
self
.
egg
.
working_set
()
self
.
installtestrunner
(
self
.
getDisplay
())
self
.
linkBinary
()
return
self
.
path_list
def
getDisplay
(
self
):
"""Generate display id for the instance."""
display_list
=
[
":%s"
%
i
for
i
in
range
(
123
,
144
)]
for
display_try
in
display_list
:
lock_filepath
=
'/tmp/.X%s-lock'
%
display_try
.
replace
(
":"
,
""
)
if
not
os
.
path
.
exists
(
lock_filepath
):
display
=
display_try
break
return
display
def
installTestrunner
(
self
,
display
):
"""Instanciate a wrapper for the browser and the test reports."""
arguments
=
dict
(
xvfb_binary
=
self
.
options
[
'xvfb_binary'
],
display
=
display
,
suite_name
=
self
.
parameter_dict
[
'suite_name'
],
base_url
=
self
.
parameter_dict
[
'url'
],
browser_argument_list
=
[],
# XXX-Cedric : No need for user/pass
user
=
self
.
parameter_dict
[
'user'
],
password
=
self
.
parameter_dict
[
'password'
])
# Check wanted browser XXX-Cedric not yet used but can be useful
#if self.parameter_dict.get('browser', None) is None:
arguments
[
'browser_binary'
]
=
self
.
options
[
'firefox_binary'
]
#elif self.parameter_dict['browser'].strip().lowercase() == 'chrome' or
# self.parameter_dict['browser'].strip().lowercase() == 'chromium':
# arguments['browser_binary'] = self.options['chromium_binary']
# arguments['browser_argument_list'].extend['--ignore-certificate-errors',
# option_translate = '--disable-translate',
# option_security = '--disable-web-security']
#elif self.parameter_dict['browser'].strip().lowercase() == 'firefox':
# arguments['browser_binary'] = self.options['firefox_binary']
self
.
path_list
.
extend
(
zc
.
buildout
.
easy_install
.
scripts
([(
'testrunner'
,
__name__
+
'.testrunner'
,
'run'
)],
self
.
ws
,
sys
.
executable
,
self
.
wrapper_directory
,
arguments
=
[
arguments
]))
def
linkBinary
(
self
):
"""Links binaries to instance's bin directory for easier exposal"""
for
linkline
in
self
.
options
.
get
(
'link_binary_list'
,
''
).
splitlines
():
if
not
linkline
:
continue
target
=
linkline
.
split
()
if
len
(
target
)
==
1
:
target
=
target
[
0
]
path
,
linkname
=
os
.
path
.
split
(
target
)
else
:
linkname
=
target
[
1
]
target
=
target
[
0
]
link
=
os
.
path
.
join
(
self
.
bin_directory
,
linkname
)
if
os
.
path
.
lexists
(
link
):
if
not
os
.
path
.
islink
(
link
):
raise
zc
.
buildout
.
UserError
(
'Target link already %r exists but it is not link'
%
link
)
os
.
unlink
(
link
)
os
.
symlink
(
target
,
link
)
self
.
logger
.
debug
(
'Created link %r -> %r'
%
(
link
,
target
))
self
.
path_list
.
append
(
link
)
slapos/recipe/selenium/testrunner.py
View file @
64d452d2
...
...
@@ -29,16 +29,23 @@ from erp5functionaltestreporthandler import ERP5TestReportHandler
from
time
import
sleep
import
os
from
subprocess
import
Popen
,
PIPE
from
re
import
search
import
urllib2
def
run
(
args
):
config
=
args
[
0
]
test_url
=
assembleTestUrl
(
config
[
'base_url'
],
config
[
'user'
],
config
[
'password'
])
test_url
=
assembleTestUrl
(
config
[
'base_url'
],
config
[
'suite_name'
],
config
[
'user'
],
config
[
'password'
])
while
True
:
erp5_report
=
ERP5TestReportHandler
(
test_url
,
config
[
'suite_name'
])
import
pdb
;
pdb
.
set_trace
()
# Clean old test results
#TODO how to clean results / post results without password?
openUrl
(
'%s/TestTool_cleanUpTestResults'
%
(
config
[
'base_url'
]))
# TODO assert getresult is None
#XXX-Cedric : clean firefox data (so that it does not load previous session)
xvfb
=
Popen
([
config
[
'xvfb_binary'
],
config
[
'display'
]],
stdout
=
PIPE
)
os
.
environ
[
'DISPLAY'
]
=
config
[
'display'
]
...
...
@@ -46,23 +53,21 @@ def run(args):
command
=
[]
command
.
append
(
config
[
'browser_binary'
])
command
.
append
(
config
[
'option_ssl'
])
command
.
append
(
config
[
'option_translate'
])
command
.
append
(
config
[
'option_security'
])
for
browser_argument
in
config
[
'browser_argument_list'
]:
command
.
append
(
browser_argument
)
command
.
append
(
test_url
)
browser
=
Popen
(
command
,
stdout
=
PIPE
)
chromium
=
Popen
(
command
,
stdout
=
PIPE
)
erp5_report
.
reportStart
()
sleep
(
10
)
#while getStatus(config['base_url']) is None:
# sleep(10)
#erp5_report.reportFinished(getStatus(config['base_url']).encode("utf-8", "replace"))
chromium
.
kill
()
# Wait for test to be finished
while
getStatus
(
config
[
'base_url'
])
is
''
:
sleep
(
10
)
erp5_report
.
reportFinished
(
getStatus
(
config
[
'base_url'
]).
encode
(
"utf-8"
,
"replace"
))
browser
.
kill
()
terminateXvfb
(
xvfb
,
config
[
'display'
])
sleep
(
1
0
)
sleep
(
360
0
)
def
openUrl
(
url
):
# Send Accept-Charset headers to activate the UnicodeConflictResolver
...
...
@@ -83,24 +88,23 @@ def getStatus(url):
try
:
status
=
openUrl
(
'%s/portal_tests/TestTool_getResults'
%
(
url
))
except
urllib2
.
HTTPError
,
e
:
if
e
.
msg
==
"No Content"
:
if
e
.
msg
==
"No Content"
:
status
=
""
else
:
raise
return
status
def
assembleTestUrl
(
base_url
,
user
,
password
):
def
assembleTestUrl
(
base_url
,
suite_name
,
user
,
password
):
"""
Create the full url to the testrunner
"""
test_url
=
"%s/core/TestRunner.html?test=../test_suite_html&resultsUrl=%s/postResults&auto=on&__ac_name=%s&__ac_password=%s"
%
(
base_url
,
base_url
,
user
,
password
)
test_url
=
"%s/%s/core/TestRunner.html?test=../test_suite_html&"
\
"resultsUrl=%s/postResults&auto=on&__ac_name=%s&__ac_password=%s"
%
(
base_url
,
suite_name
,
base_url
,
user
,
password
)
return
test_url
def
terminateXvfb
(
process
,
display
):
process
.
kill
()
lock_filepath
=
'/tmp/.X%s-lock'
%
display
.
replace
(
":"
,
""
)
if
os
.
path
.
exists
(
lock_filepath
):
lock_filepath
=
'/tmp/.X%s-lock'
%
display
.
replace
(
":"
,
""
)
if
os
.
path
.
exists
(
lock_filepath
):
os
.
system
(
'rm %s'
%
lock_filepath
)
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