Skip to content

Commit

Permalink
Add wait for element animation finished (#43)
Browse files Browse the repository at this point in the history
* Add support wait for element animation
  • Loading branch information
atthaboon authored Aug 29, 2020
1 parent d7a5730 commit 34091ff
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Examples/element-properties-demo.robot
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ Element should not contain text
Element text should be
Element Text Should Be id=get_ajax Change Content ${True}

Element test should not be
Element text should not be
Element Text Should Not Be id=get_ajax Change ${True}

Element wait for animation
Click Button id=popup_modal
Wait Until Element Finished Animating id:close_modal
Click Element id:close_modal
Wait Until Element Is Hidden id:close_modal

*** Keywords ***
Open browser to test page
${HEADLESS} Get variable value ${HEADLESS} ${False}
Expand Down
10 changes: 10 additions & 0 deletions PuppeteerLibrary/keywords/waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,13 @@ def wait_until_element_is_enabled(self, selenium_locator, timeout=None):
"""
return self.loop.run_until_complete(
self.async_func.wait_until_element_is_enabled_async(selenium_locator, timeout))

@keyword
def wait_until_element_finished_animating(self, selenium_locator, timeout=None):
"""
Waits until the specific element is finished animating.
Check by check element position.
"""
return self.loop.run_until_complete(
self.async_func.wait_until_element_finished_animating_async(selenium_locator, timeout))
21 changes: 20 additions & 1 deletion PuppeteerLibrary/keywords/waiting_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import time
import re
from robot.utils import timestr_to_secs
from PuppeteerLibrary.base.librarycomponent import LibraryComponent
from PuppeteerLibrary.base.robotlibcore import keyword

Expand Down Expand Up @@ -120,6 +119,26 @@ async def validate_is_enabled():
self.timestr_to_secs_for_default_timeout(timeout),
'Element '+selenium_locator+' was not enabled.')

@keyword
async def wait_until_element_finished_animating_async(self, selenium_locator, timeout=None):
prev_rect_tmp = { 'value': None }
async def check_finished_animating():
element = await self.ctx.get_current_page().querySelector_with_selenium_locator(selenium_locator)
if prev_rect_tmp['value'] is None:
prev_rect_tmp['value'] = await element.boundingBox()
return False
prev_rect = prev_rect_tmp['value']
next_rect = await element.boundingBox()
if next_rect['x'] == prev_rect['x'] and next_rect['y'] == prev_rect['y']:
return True
else:
prev_rect_tmp['value'] = next_rect
return False
return await self._wait_until_worker(
check_finished_animating,
self.timestr_to_secs_for_default_timeout(timeout),
'Element '+selenium_locator+' was not enabled.')

async def _wait_until_worker(self, condition, timeout, error=None):
max_time = time.time() + timeout
not_found = None
Expand Down
29 changes: 29 additions & 0 deletions demoapp/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>Login Page</title>
<link href="demo.css" media="all" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script type="text/javascript">
function alertConfirm() {
alert('Test alert');
Expand Down Expand Up @@ -71,7 +72,35 @@ <h3>Element property</h3>
<button id="disabled-button" disabled>disable button</button>
<button id="not-visible-button" style="display:None;">in visible button</button>
</div>

<div style="margin-top: 30px;">
<button id="popup_modal" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
</div>
</div>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button id="close_modal" type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>

0 comments on commit 34091ff

Please sign in to comment.