diff --git a/Examples/element-properties-demo.robot b/Examples/element-properties-demo.robot index 07d044a..ea089d8 100644 --- a/Examples/element-properties-demo.robot +++ b/Examples/element-properties-demo.robot @@ -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} diff --git a/PuppeteerLibrary/keywords/waiting.py b/PuppeteerLibrary/keywords/waiting.py index 44dd4bb..f5bca8d 100644 --- a/PuppeteerLibrary/keywords/waiting.py +++ b/PuppeteerLibrary/keywords/waiting.py @@ -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)) diff --git a/PuppeteerLibrary/keywords/waiting_async.py b/PuppeteerLibrary/keywords/waiting_async.py index 022c309..af8c9c3 100644 --- a/PuppeteerLibrary/keywords/waiting_async.py +++ b/PuppeteerLibrary/keywords/waiting_async.py @@ -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 @@ -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 diff --git a/demoapp/html/index.html b/demoapp/html/index.html index d8e0a6b..7352cd7 100644 --- a/demoapp/html/index.html +++ b/demoapp/html/index.html @@ -3,6 +3,7 @@