Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-drag-and-drop-v2
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
OpenEdx
xblock-drag-and-drop-v2
Commits
ab514ef8
Commit
ab514ef8
authored
Feb 20, 2016
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix flaky tests
parent
7b38b2e0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
10 deletions
+31
-10
tests/integration/test_interaction.py
+6
-1
tests/integration/test_sizing.py
+25
-9
No files found.
tests/integration/test_interaction.py
View file @
ab514ef8
...
@@ -122,7 +122,12 @@ class InteractionTestBase(object):
...
@@ -122,7 +122,12 @@ class InteractionTestBase(object):
def
send_input
(
self
,
item_value
,
value
):
def
send_input
(
self
,
item_value
,
value
):
element
=
self
.
_get_item_by_value
(
item_value
)
element
=
self
.
_get_item_by_value
(
item_value
)
self
.
wait_until_visible
(
element
)
self
.
wait_until_visible
(
element
)
element
.
find_element_by_class_name
(
'input'
)
.
send_keys
(
value
)
# Since virtual-dom may be updating DOM elements by replacing them completely, the
# following method must be used to wait for the input box to appear:
textbox_visible_selector
=
'.numerical-input[style*="display: block"] input'
self
.
wait_until_exists
(
textbox_visible_selector
)
textbox
=
self
.
_page
.
find_element_by_css_selector
(
textbox_visible_selector
)
textbox
.
send_keys
(
value
)
element
.
find_element_by_class_name
(
'submit-input'
)
.
click
()
element
.
find_element_by_class_name
(
'submit-input'
)
.
click
()
def
assert_grabbed_item
(
self
,
item
):
def
assert_grabbed_item
(
self
,
item
):
...
...
tests/integration/test_sizing.py
View file @
ab514ef8
...
@@ -90,7 +90,7 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
...
@@ -90,7 +90,7 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
# A 400x300 image with automatic sizing should be constrained to the maximum width
# A 400x300 image with automatic sizing should be constrained to the maximum width
Expectation
(
item_id
=
5
,
zone_id
=
ZONE_50
,
width_percent
=
AUTO_MAX_WIDTH
),
Expectation
(
item_id
=
5
,
zone_id
=
ZONE_50
,
width_percent
=
AUTO_MAX_WIDTH
),
# A 200x200 image with automatic sizing
# A 200x200 image with automatic sizing
Expectation
(
item_id
=
6
,
zone_id
=
ZONE_50
,
width_percent
=
[
25
,
30
]),
Expectation
(
item_id
=
6
,
zone_id
=
ZONE_50
,
width_percent
=
[
25
,
30
.2
]),
# A 400x300 image with a specified width of 50%
# A 400x300 image with a specified width of 50%
Expectation
(
item_id
=
7
,
zone_id
=
ZONE_50
,
fixed_width_percent
=
50
),
Expectation
(
item_id
=
7
,
zone_id
=
ZONE_50
,
fixed_width_percent
=
50
),
# A 200x200 image with a specified width of 50%
# A 200x200 image with a specified width of 50%
...
@@ -112,6 +112,17 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
...
@@ -112,6 +112,17 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
self
.
browser
.
set_window_size
(
375
,
627
)
# iPhone 6 viewport size
self
.
browser
.
set_window_size
(
375
,
627
)
# iPhone 6 viewport size
wait
=
WebDriverWait
(
self
.
browser
,
2
)
wait
=
WebDriverWait
(
self
.
browser
,
2
)
wait
.
until
(
lambda
browser
:
browser
.
get_window_size
()[
"width"
]
==
375
)
wait
.
until
(
lambda
browser
:
browser
.
get_window_size
()[
"width"
]
==
375
)
# Fix platform inconsistencies caused by scrollbar size:
self
.
browser
.
execute_script
(
'$("body").css("margin-right", "40px")'
)
scrollbar_width
=
self
.
browser
.
execute_script
(
"var $outer = $('<div>').css({visibility: 'hidden', width: 100, overflow: 'scroll'}).appendTo('body');"
"var widthWithScroll = $('<div>').css({width: '100
%
'}).appendTo($outer).outerWidth();"
"$outer.remove();"
"return 100 - widthWithScroll;"
)
self
.
browser
.
execute_script
(
'$(".wrapper-workbench").css("margin-right", "-{}px")'
.
format
(
40
+
scrollbar_width
))
# And reduce the wasted space around our XBlock in the workbench:
self
.
browser
.
execute_script
(
'return $(".workbench .preview").css("margin", "0")'
)
def
test_wide_image_mobile
(
self
):
def
test_wide_image_mobile
(
self
):
""" Test the upper, larger, wide image in a mobile-sized window """
""" Test the upper, larger, wide image in a mobile-sized window """
...
@@ -121,7 +132,7 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
...
@@ -121,7 +132,7 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
def
test_square_image_mobile
(
self
):
def
test_square_image_mobile
(
self
):
""" Test the lower, smaller, square image in a mobile-sized window """
""" Test the lower, smaller, square image in a mobile-sized window """
self
.
_size_for_mobile
()
self
.
_size_for_mobile
()
self
.
_check_sizes
(
1
,
self
.
EXPECTATIONS
,
expected_img_width
=
375
,
is_desktop
=
False
)
self
.
_check_sizes
(
1
,
self
.
EXPECTATIONS
,
is_desktop
=
False
)
def
_check_width
(
self
,
item_description
,
item
,
container_width
,
expected_percent
):
def
_check_width
(
self
,
item_description
,
item
,
container_width
,
expected_percent
):
"""
"""
...
@@ -129,19 +140,20 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
...
@@ -129,19 +140,20 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
of container_width, or if expected_percent is a pair of numbers, that it is within
of container_width, or if expected_percent is a pair of numbers, that it is within
that range.
that range.
"""
"""
width_percent
=
item
.
size
[
"width"
]
/
container_width
*
100
width_pixels
=
item
.
size
[
"width"
]
width_percent
=
width_pixels
/
container_width
*
100
if
isinstance
(
expected_percent
,
(
list
,
tuple
)):
if
isinstance
(
expected_percent
,
(
list
,
tuple
)):
min_expected
,
max_expected
=
expected_percent
min_expected
,
max_expected
=
expected_percent
msg
=
"{} should have width of {}
% -
{}
%
. Actual: {
:.2f}
%
"
.
format
(
msg
=
"{} should have width of {}
% -
{}
%
. Actual: {
}px ({:.2f}
%
of {}px)
"
.
format
(
item_description
,
min_expected
,
max_expected
,
width_p
ercent
item_description
,
min_expected
,
max_expected
,
width_p
ixels
,
width_percent
,
container_width
)
)
self
.
assertGreaterEqual
(
width_percent
,
min_expected
,
msg
)
self
.
assertGreaterEqual
(
width_percent
,
min_expected
,
msg
)
self
.
assertLessEqual
(
width_percent
,
max_expected
,
msg
)
self
.
assertLessEqual
(
width_percent
,
max_expected
,
msg
)
else
:
else
:
self
.
assertAlmostEqual
(
self
.
assertAlmostEqual
(
width_percent
,
expected_percent
,
delta
=
1
,
width_percent
,
expected_percent
,
delta
=
1
,
msg
=
"{} should have width of ~{}
%
(+/- 1
%
). Actual: {
:.2f}
%
"
.
format
(
msg
=
"{} should have width of ~{}
%
(+/- 1
%
). Actual: {
}px ({:.2f}
%
of {}px)
"
.
format
(
item_description
,
expected_percent
,
width_p
ercent
item_description
,
expected_percent
,
width_p
ixels
,
width_percent
,
container_width
)
)
)
)
...
@@ -165,7 +177,7 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
...
@@ -165,7 +177,7 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
)
)
)
)
def
_check_sizes
(
self
,
block_index
,
expectations
,
expected_img_width
=
755
,
is_desktop
=
True
):
def
_check_sizes
(
self
,
block_index
,
expectations
,
expected_img_width
=
None
,
is_desktop
=
True
):
""" Test the actual dimensions that each draggable has, in the bank and when placed """
""" Test the actual dimensions that each draggable has, in the bank and when placed """
# Check assumptions - the container wrapping this XBlock should be 770px wide
# Check assumptions - the container wrapping this XBlock should be 770px wide
self
.
_switch_to_block
(
block_index
)
self
.
_switch_to_block
(
block_index
)
...
@@ -177,8 +189,12 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
...
@@ -177,8 +189,12 @@ class SizingTests(InteractionTestBase, BaseIntegrationTest):
if
is_desktop
:
if
is_desktop
:
# If using a desktop-sized window, we can know the exact dimensions of various containers:
# If using a desktop-sized window, we can know the exact dimensions of various containers:
self
.
assertEqual
(
self
.
_page
.
size
[
"width"
],
770
)
# self._page is the .xblock--drag-and-drop div
self
.
assertEqual
(
self
.
_page
.
size
[
"width"
],
770
)
# self._page is the .xblock--drag-and-drop div
self
.
assertEqual
(
target_img_width
,
expected_img_width
)
self
.
assertEqual
(
target_img_width
,
expected_img_width
or
755
)
self
.
assertEqual
(
item_bank_width
,
755
)
self
.
assertEqual
(
item_bank_width
,
755
)
else
:
self
.
assertEqual
(
self
.
_page
.
size
[
"width"
],
335
)
# self._page is the .xblock--drag-and-drop div
self
.
assertEqual
(
target_img_width
,
expected_img_width
or
328
)
self
.
assertEqual
(
item_bank_width
,
328
)
# Test each element, before it is placed (while it is in the item bank).
# Test each element, before it is placed (while it is in the item bank).
for
expect
in
expectations
:
for
expect
in
expectations
:
...
...
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