Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
4ddb9a01
Commit
4ddb9a01
authored
Oct 15, 2015
by
Jesse Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] Improvements to acceptance test field logic
parent
de0b01ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
33 deletions
+54
-33
common/test/acceptance/pages/lms/fields.py
+28
-26
common/test/acceptance/tests/helpers.py
+23
-4
common/test/acceptance/tests/lms/test_learner_profile.py
+3
-3
No files found.
common/test/acceptance/pages/lms/fields.py
View file @
4ddb9a01
...
...
@@ -16,17 +16,24 @@ class FieldsMixin(object):
"""
Return field with field_id.
"""
assert
False
,
"Why am I here?"
query
=
self
.
q
(
css
=
'.u-field-{}'
.
format
(
field_id
))
return
query
.
text
[
0
]
if
query
.
present
else
None
def
wait_for_field
(
self
,
field_id
):
"""Wait for a field to appear in DOM.
Args:
field_id (str): The ID of the field, used in locating it via css
Returns:
None
Raises:
BrokenPromise: If the field is not present in the DOM before the default timeout
"""
Wait for a field to appear in DOM.
"""
EmptyPromise
(
lambda
:
self
.
field
(
field_id
)
is
not
None
,
"Field with id
\"
{0}
\"
is in DOM."
.
format
(
field_id
)
)
.
fulfill
()
field_css
=
'.u-field-{}'
.
format
(
field_id
)
self
.
wait_for_element_presence
(
field_css
,
'Field {} is present in the DOM'
.
format
(
field_id
))
def
mode_for_field
(
self
,
field_id
):
"""
...
...
@@ -39,8 +46,8 @@ class FieldsMixin(object):
query
=
self
.
q
(
css
=
'.u-field-{}'
.
format
(
field_id
))
if
not
query
.
present
:
return
None
#
if not query.present:
#
return None
field_classes
=
query
.
attrs
(
'class'
)[
0
]
.
split
()
...
...
@@ -124,19 +131,18 @@ class FieldsMixin(object):
"""
Make a field editable.
"""
query
=
self
.
q
(
css
=
'.u-field-{}'
.
format
(
field_id
))
if
not
query
.
present
:
return
None
field_classes
=
query
.
attrs
(
'class'
)[
0
]
.
split
()
self
.
wait_for_field
(
field_id
)
field_mode
=
self
.
mode_for_field
(
field_id
)
if
'mode-placeholder'
in
field_classes
or
'mode-display'
in
field_classes
:
if
field_mode
in
[
'placeholder'
,
'display'
]
:
if
field_id
==
'bio'
:
self
.
q
(
css
=
'.u-field-bio > .wrapper-u-field'
)
.
first
.
click
()
else
:
self
.
q
(
css
=
'.u-field-{}'
.
format
(
field_id
))
.
first
.
click
()
# Verify that the class changed to mode-edit
self
.
wait_for
(
lambda
:
self
.
mode_for_field
(
field_id
)
==
'edit'
,
'Field {} is editable'
.
format
(
field_id
))
def
value_for_readonly_field
(
self
,
field_id
):
"""
Return the value in a readonly field.
...
...
@@ -155,10 +161,8 @@ class FieldsMixin(object):
"""
self
.
wait_for_field
(
field_id
)
query
=
self
.
q
(
css
=
'.u-field-{} input'
.
format
(
field_id
))
if
not
query
.
present
:
return
None
field_css
=
'.u-field-{} input'
.
format
(
field_id
)
query
=
self
.
q
(
css
=
field_css
)
if
value
is
not
None
:
current_value
=
query
.
attrs
(
'value'
)[
0
]
query
.
results
[
0
]
.
send_keys
(
u'
\ue003
'
*
len
(
current_value
))
# Delete existing value.
...
...
@@ -171,13 +175,15 @@ class FieldsMixin(object):
"""
Set the value of a textarea field.
"""
assert
False
,
"Cannot set value for textarea"
self
.
wait_for_field
(
field_id
)
self
.
make_field_editable
(
field_id
)
field_selector
=
'.u-field-{} textarea'
.
format
(
field_id
)
self
.
wait_for_element_presence
(
field_selector
,
'Editable textarea is present.'
)
query
=
self
.
q
(
css
=
field_selector
)
query
=
self
.
q
(
css
=
field_selector
)
.
first
query
.
click
()
query
.
fill
(
value
)
query
.
results
[
0
]
.
send_keys
(
u'
\ue004
'
)
# Focus Out using TAB
...
...
@@ -186,8 +192,6 @@ class FieldsMixin(object):
Return value of field in `display` or `placeholder` mode.
"""
self
.
wait_for_field
(
field_id
)
self
.
wait_for_ajax
()
return
self
.
q
(
css
=
'.u-field-{} .u-field-value .u-field-value-readonly'
.
format
(
field_id
))
.
text
[
0
]
def
value_for_dropdown_field
(
self
,
field_id
,
value
=
None
):
...
...
@@ -197,12 +201,10 @@ class FieldsMixin(object):
assert
False
,
"This test uses value_for_dropdown_field"
self
.
wait_for_field
(
field_id
)
self
.
make_field_editable
(
field_id
)
query
=
self
.
q
(
css
=
'.u-field-{} select'
.
format
(
field_id
))
if
not
query
.
present
:
return
None
field_css
=
'.u-field-{} select'
.
format
(
field_id
)
query
=
self
.
q
(
css
=
field_css
)
if
value
is
not
None
:
select_option_by_text
(
query
,
value
)
...
...
common/test/acceptance/tests/helpers.py
View file @
4ddb9a01
...
...
@@ -21,6 +21,7 @@ from pymongo import MongoClient, ASCENDING
from
openedx.core.lib.tests.assertions.events
import
assert_event_matches
,
is_matching_event
,
EventMatchTolerates
from
xmodule.partitions.partitions
import
UserPartition
from
xmodule.partitions.tests.test_partitions
import
MockUserPartitionScheme
from
selenium.common.exceptions
import
StaleElementReferenceException
from
selenium.webdriver.support.select
import
Select
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
EC
...
...
@@ -201,18 +202,36 @@ def enable_css_animations(page):
def
select_option_by_text
(
select_browser_query
,
option_text
):
"""
Chooses an option within a select by text (helper method for Select's select_by_visible_text method).
Wrap this in a Promise to prevent a StaleElementReferenceException
from being raised while the DOM is still being rewritten
"""
select
=
Select
(
select_browser_query
.
first
.
results
[
0
])
select
.
select_by_visible_text
(
option_text
)
def
select_option
(
query
,
value
):
try
:
select
=
Select
(
query
.
first
.
results
[
0
])
select
.
select_by_visible_text
(
value
)
return
True
except
StaleElementReferenceException
:
return
False
EmptyPromise
(
lambda
:
select_option
(
select_browser_query
,
option_text
),
'Selected option {}'
.
format
(
option_text
))
.
fulfill
()
def
get_selected_option_text
(
select_browser_query
):
"""
Returns the text value for the first selected option within a select.
Wrap this in a Promise to prevent a StaleElementReferenceException
from being raised while the DOM is still being rewritten
"""
select
=
Select
(
select_browser_query
.
first
.
results
[
0
])
return
select
.
first_selected_option
.
text
def
get_option
(
query
):
try
:
select
=
Select
(
select_browser_query
.
first
.
results
[
0
])
return
(
True
,
select
.
first_selected_option
.
text
)
except
StaleElementReferenceException
:
return
(
False
,
None
)
text
=
Promise
(
lambda
:
get_option
(
select_browser_query
),
'Retrieved selected option text'
)
.
fulfill
()
return
text
def
get_options
(
select_browser_query
):
"""
...
...
common/test/acceptance/tests/lms/test_learner_profile.py
View file @
4ddb9a01
...
...
@@ -328,18 +328,18 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, WebAppTest):
self
.
assertEqual
(
profile_page
.
get_non_editable_mode_value
(
field_id
),
displayed_value
)
self
.
assertTrue
(
profile_page
.
mode_for_field
(
field_id
),
mode
)
def
_test_textarea_field
(
self
,
profile_page
,
field_id
,
new_value
,
display
ed_value
,
mode
):
def
_test_textarea_field
(
self
,
profile_page
,
field_id
,
new_value
,
expect
ed_value
,
mode
):
"""
Test behaviour of a textarea field.
"""
profile_page
.
set_value_for_textarea_field
(
field_id
,
new_value
)
self
.
assertEqual
(
profile_page
.
get_non_editable_mode_value
(
field_id
),
display
ed_value
)
self
.
assertEqual
(
profile_page
.
get_non_editable_mode_value
(
field_id
),
expect
ed_value
)
self
.
assertTrue
(
profile_page
.
mode_for_field
(
field_id
),
mode
)
self
.
browser
.
refresh
()
profile_page
.
wait_for_page
()
self
.
assertEqual
(
profile_page
.
get_non_editable_mode_value
(
field_id
),
display
ed_value
)
self
.
assertEqual
(
profile_page
.
get_non_editable_mode_value
(
field_id
),
expect
ed_value
)
self
.
assertTrue
(
profile_page
.
mode_for_field
(
field_id
),
mode
)
def
test_country_field
(
self
):
...
...
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