Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
68bc38c8
authored
Mar 10, 2015
by
Csók Tamás
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
selenium: logging and a few extra
parent
3159f5f9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
25 deletions
+34
-25
circle/acl/tests/models.py
+5
-1
circle/circle/settings/selenium_test.py
+2
-1
circle/dashboard/tests/selenium/basic_tests.py
+27
-23
No files found.
circle/acl/tests/models.py
View file @
68bc38c8
...
...
@@ -15,4 +15,8 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
.test_acl
import
TestModel
,
Test2Model
# noqa
from
django.conf
import
settings
# https://code.djangoproject.com/ticket/7835
if
settings
.
SETTINGS_MODULE
==
'circle.settings.test'
:
from
.test_acl
import
TestModel
,
Test2Model
# noqa
circle/circle/settings/selenium_test.py
View file @
68bc38c8
...
...
@@ -40,7 +40,8 @@ INSTALLED_APPS += (
)
TEST_RUNNER
=
'django_nose.NoseTestSuiteRunner'
path_to_selenium_test
=
os
.
path
.
expanduser
(
'~/circle/circle/dashboard/tests/selenium'
)
path_to_selenium_test
=
os
.
path
.
join
(
SITE_ROOT
,
"dashboard/tests/selenium"
)
NOSE_ARGS
=
[
'--stop'
,
'--with-doctest'
,
'--with-selenium-driver'
,
'--selenium-driver=firefox'
,
'-w
%
s'
%
path_to_selenium_test
]
PASSWORD_HASHERS
=
[
'django.contrib.auth.hashers.MD5PasswordHasher'
]
...
...
circle/dashboard/tests/selenium/basic_tests.py
View file @
68bc38c8
...
...
@@ -22,12 +22,14 @@ import random
import
urlparse
import
re
import
time
import
logging
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
ec
from
selenium.webdriver.support.select
import
Select
from
selenium.webdriver.common.by
import
By
from
datetime
import
datetime
from
selenium.common.exceptions
import
NoSuchElementException
logging
.
getLogger
(
__name__
)
random_pass
=
""
.
join
([
random
.
choice
(
'0123456789abcdefghijklmnopqrstvwxyz'
)
for
n
in
xrange
(
10
)])
random_accents
=
random_pass
+
""
.
join
([
random
.
choice
(
...
...
@@ -75,7 +77,7 @@ class UtilityMixin(object):
except
:
time
.
sleep
(
0.5
)
except
:
raise
E
xception
(
'Selenium cannot find the form controls'
)
logging
.
e
xception
(
'Selenium cannot find the form controls'
)
def
list_options
(
self
,
select
):
try
:
...
...
@@ -87,7 +89,7 @@ class UtilityMixin(object):
option_dic
[
key
]
=
[
option
.
text
]
return
option_dic
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot list the select possibilities'
)
def
select_option
(
self
,
select
,
what
=
None
):
...
...
@@ -118,7 +120,7 @@ class UtilityMixin(object):
0
,
len
(
my_choose_list
)
-
1
)]
select
.
select_by_value
(
my_choice
)
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot select the chosen one'
)
def
get_link_by_href
(
self
,
target_href
,
attributes
=
None
):
...
...
@@ -138,7 +140,7 @@ class UtilityMixin(object):
if
perfect_fit
:
return
link
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot find the href=
%
s link'
%
target_href
)
def
click_on_link
(
self
,
link
):
...
...
@@ -165,7 +167,7 @@ class UtilityMixin(object):
"}"
)
self
.
driver
.
execute_script
(
javascript
,
link
)
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot inject javascript to the page'
)
def
wait_and_accept_operation
(
self
,
argument
=
None
):
...
...
@@ -190,8 +192,8 @@ class UtilityMixin(object):
form
.
send_keys
(
argument
)
accept
.
click
()
except
:
raise
Exception
(
"Selenium cannot accept the"
" operation confirmation"
)
logging
.
exception
(
'Selenium cannot accept the operation confirmation'
)
def
save_template_from_vm
(
self
,
name
):
try
:
...
...
@@ -206,7 +208,7 @@ class UtilityMixin(object):
if
not
self
.
check_operation_result
(
recent_deploy
):
print
(
"Selenium cannot deploy the "
"chosen template virtual machine"
)
raise
E
xception
(
'Cannot deploy the virtual machine'
)
logging
.
e
xception
(
'Cannot deploy the virtual machine'
)
self
.
click_on_link
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
...
...
@@ -217,7 +219,7 @@ class UtilityMixin(object):
if
not
self
.
check_operation_result
(
recent_shut_off
):
print
(
"Selenium cannot shut off the "
"chosen template virtual machine"
)
raise
E
xception
(
'Cannot shut off the virtual machine'
)
logging
.
e
xception
(
'Cannot shut off the virtual machine'
)
self
.
click_on_link
(
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
ec
.
element_to_be_clickable
((
By
.
CSS_SELECTOR
,
...
...
@@ -225,7 +227,7 @@ class UtilityMixin(object):
self
.
wait_and_accept_operation
(
name
)
return
name
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot save a vm as a template'
)
def
create_base_template
(
self
,
name
=
None
,
architecture
=
"x86-64"
,
...
...
@@ -261,7 +263,7 @@ class UtilityMixin(object):
"input.btn[type='submit']"
)
.
click
()
return
self
.
save_template_from_vm
(
name
)
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot create a base template virtual machine'
)
def
get_template_id
(
self
,
name
=
None
,
from_all
=
False
):
...
...
@@ -312,7 +314,7 @@ class UtilityMixin(object):
'name'
:
name
})
return
found_template_ids
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot found the template
\'
s id'
)
def
check_operation_result
(
self
,
operation_id
,
restore
=
True
):
...
...
@@ -350,7 +352,7 @@ class UtilityMixin(object):
self
.
driver
.
get
(
url_save
)
return
out
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot check the result of an operation'
)
def
recently
(
self
,
timeline_dict
,
second
=
90
):
...
...
@@ -362,7 +364,7 @@ class UtilityMixin(object):
if
delta
.
total_seconds
()
<=
second
:
return
value
except
:
raise
E
xception
(
logging
.
e
xception
(
'Selenium cannot filter timeline activities to recent'
)
def
get_timeline_elements
(
self
,
code
=
None
):
...
...
@@ -395,7 +397,7 @@ class UtilityMixin(object):
activity_dict
[
key
]
=
activity_id
return
activity_dict
except
:
raise
E
xception
(
'Selenium cannot find the searched activity'
)
logging
.
e
xception
(
'Selenium cannot find the searched activity'
)
def
create_template_from_base
(
self
,
delete_disk
=
True
,
name
=
None
):
try
:
...
...
@@ -433,10 +435,11 @@ class UtilityMixin(object):
if
not
self
.
check_operation_result
(
recent_remove_disk
):
print
(
"Selenium cannot delete disk "
"of the chosen template"
)
raise
E
xception
(
'Cannot delete disk'
)
logging
.
e
xception
(
'Cannot delete disk'
)
return
self
.
save_template_from_vm
(
name
)
except
:
raise
Exception
(
'Selenium cannot start a template from a base one'
)
logging
.
exception
(
'Selenium cannot start a template from a base one'
)
def
delete_template
(
self
,
template_id
):
try
:
...
...
@@ -451,9 +454,10 @@ class UtilityMixin(object):
By
.
CLASS_NAME
,
'alert-success'
)))
url
=
urlparse
.
urlparse
(
self
.
driver
.
current_url
)
if
"/template/list/"
not
in
url
.
path
:
raise
Exception
()
logging
.
exception
(
'System does not redirect to template listing'
)
except
:
raise
E
xception
(
'Selenium cannot delete the desired template'
)
logging
.
e
xception
(
'Selenium cannot delete the desired template'
)
def
create_random_vm
(
self
):
try
:
...
...
@@ -474,7 +478,7 @@ class UtilityMixin(object):
pk
=
re
.
search
(
r'\d+'
,
url
.
path
)
.
group
()
return
pk
except
:
raise
E
xception
(
'Selenium cannot start a VM'
)
logging
.
e
xception
(
'Selenium cannot start a VM'
)
def
view_change
(
self
,
target_box
):
driver
=
self
.
driver
...
...
@@ -522,7 +526,7 @@ class UtilityMixin(object):
print
(
"Selenium cannot destroy "
"the chosen
%(id)
s vm"
%
{
'id'
:
pk
})
raise
E
xception
(
'Cannot destroy the specified vm'
)
logging
.
e
xception
(
'Cannot destroy the specified vm'
)
self
.
driver
.
get
(
'
%
s/dashboard/vm/
%
s/'
%
(
host
,
pk
))
try
:
WebDriverWait
(
self
.
driver
,
wait_max_sec
)
.
until
(
...
...
@@ -533,7 +537,7 @@ class UtilityMixin(object):
except
:
return
False
except
:
raise
E
xception
(
"Selenium can not destroy a VM"
)
logging
.
e
xception
(
"Selenium can not destroy a VM"
)
class
VmDetailTest
(
UtilityMixin
,
SeleniumTestCase
):
...
...
@@ -571,7 +575,7 @@ class VmDetailTest(UtilityMixin, SeleniumTestCase):
chosen
=
template_pool
[
0
]
else
:
print
"Selenium did not found any templates"
raise
E
xception
(
logging
.
e
xception
(
"System did not meet required conditions to continue"
)
self
.
driver
.
get
(
'
%
s/dashboard/template/
%
s/'
%
(
host
,
chosen
))
acces_form
=
self
.
driver
.
find_element_by_css_selector
(
...
...
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