-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce shared component for interacting with "Add ..." dropdown
When testing locally, occasionally we encounter the issue that clicking "Add ..." button does not open dropdown (or dropdown disappears before we can interact with it - impossible to tell). We need to wrap "click add button and select item from dropdown" sequence in a loop, to retry it. Since this is a component used in two places, we extract it to shared component instead of repeating the loop.
- Loading branch information
1 parent
8f6a99f
commit 915059c
Showing
3 changed files
with
84 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from playwright.sync_api import TimeoutError | ||
|
||
from camayoc.exceptions import MisconfiguredWidgetException | ||
from camayoc.types.ui import UIPage | ||
|
||
|
||
class AddNewDropdown(UIPage): | ||
def open_create_new_modal(self, type_ouiaid): | ||
default_timeout = 5000 # 5s | ||
add_button_locator = getattr(self, "ADD_BUTTON_LOCATOR") | ||
if not add_button_locator: | ||
msg = "{} requires class property 'ADD_BUTTON_LOCATOR' to be set [object={}]" | ||
raise MisconfiguredWidgetException(msg.format(type(self).__name__, self)) | ||
|
||
dropdown_item_locator = ( | ||
f"{add_button_locator} ~ div ul li[data-ouia-component-id={type_ouiaid}]" | ||
) | ||
|
||
exp_msg = ( | ||
"Could not open modal using dropdown menu [button locator={} ;" | ||
"dropdown item locator={}]" | ||
).format(add_button_locator, dropdown_item_locator) | ||
exp = TimeoutError(exp_msg) | ||
for _ in range(5): | ||
try: | ||
self._driver.locator(add_button_locator).click(timeout=default_timeout) | ||
self._driver.locator(dropdown_item_locator).click(timeout=default_timeout) | ||
return | ||
except TimeoutError as e: | ||
exp = e | ||
continue | ||
raise exp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters