-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reuse toolium driver and pageobjects for playwright tests
- Loading branch information
Showing
7 changed files
with
225 additions
and
30 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Copyright 2024 Telefónica Innovación Digital, S.L. | ||
This file is part of Toolium. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from toolium.pageelements.playwright.button_page_element import Button | ||
from toolium.pageelements.playwright.input_text_page_element import InputText | ||
from toolium.pageelements.playwright.text_page_element import Text | ||
|
||
__all__ = ['Text', 'InputText', 'Button'] |
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,36 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Copyright 2024 Telefónica Innovación Digital, S.L. | ||
This file is part of Toolium. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from toolium.pageelements.playwright.page_element import PageElement | ||
|
||
|
||
class Button(PageElement): | ||
async def get_text(self): | ||
"""Get the element text value | ||
:returns: element text value | ||
""" | ||
return await (await self.web_element).get_text() | ||
|
||
async def click(self): | ||
"""Click the element | ||
:returns: page element instance | ||
""" | ||
await (await self.web_element).click() | ||
return self |
69 changes: 69 additions & 0 deletions
69
toolium/pageelements/playwright/input_text_page_element.py
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,69 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Copyright 2024 Telefónica Innovación Digital, S.L. | ||
This file is part of Toolium. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from toolium.pageelements.playwright.page_element import PageElement | ||
|
||
|
||
class InputText(PageElement): | ||
# TODO: convert to async get_text | ||
@property | ||
def text(self): | ||
"""Get the element text value | ||
:returns: element text value | ||
""" | ||
if self.driver_wrapper.is_web_test() or self.webview: | ||
return self.web_element.get_attribute("value") | ||
elif self.driver_wrapper.is_ios_test(): | ||
return self.web_element.get_attribute("label") | ||
elif self.driver_wrapper.is_android_test(): | ||
return self.web_element.get_attribute("text") | ||
|
||
async def fill(self, value): | ||
"""Set value on the element | ||
:param value: value to be set | ||
""" | ||
await (await self.web_element).fill(value) | ||
|
||
# TODO: convert to async method | ||
def clear(self): | ||
"""Clear the element value | ||
:returns: page element instance | ||
""" | ||
self.web_element.clear() | ||
return self | ||
|
||
async def click(self): | ||
"""Click the element | ||
:returns: page element instance | ||
""" | ||
await (await self.web_element).click() | ||
return self | ||
|
||
# TODO: convert to async method | ||
def set_focus(self): | ||
""" | ||
Set the focus over the element and click on the InputField | ||
:returns: page element instance | ||
""" | ||
self.utils.focus_element(self.web_element, click=True) | ||
return self |
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,65 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Copyright 2024 Telefónica Innovación Digital, S.L. | ||
This file is part of Toolium. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from selenium.common.exceptions import NoSuchElementException | ||
from selenium.webdriver.common.by import By | ||
|
||
from toolium.pageelements import PageElement as BasePageElement | ||
|
||
|
||
class PageElement(BasePageElement): | ||
@property | ||
async def web_element(self): | ||
"""Find WebElement using element locator | ||
:returns: web element object | ||
:rtype: selenium.webdriver.remote.webelement.WebElement or appium.webdriver.webelement.WebElement | ||
""" | ||
try: | ||
await self._find_web_element() | ||
except NoSuchElementException as exception: | ||
parent_msg = f" and parent locator {self.parent_locator_str()}" if self.parent else '' | ||
msg = "Page element of type '%s' with locator %s%s not found" | ||
self.logger.error(msg, type(self).__name__, self.locator, parent_msg) | ||
exception.msg += "\n {}".format(msg % (type(self).__name__, self.locator, parent_msg)) | ||
raise exception | ||
return self._web_element | ||
|
||
async def _find_web_element(self): | ||
"""Find WebElement using element locator and save it in _web_element attribute""" | ||
if not self._web_element or not self.driver_wrapper.config.getboolean_optional('Driver', 'save_web_element'): | ||
# Element will be searched from parent element or from driver | ||
# TODO: search from parent element | ||
# base = self.utils.get_web_element(self.parent) if self.parent else self.driver | ||
self._web_element = self.driver.locator(self.playwright_locator) | ||
|
||
@property | ||
def playwright_locator(self): | ||
"""Return playwright locator converted from toolium/selenium locator | ||
:returns: playwright locator | ||
""" | ||
# TODO: Implement playwright locator conversion | ||
if self.locator[0] == By.ID: | ||
prefix = '#' | ||
elif self.locator[0] == By.XPATH: | ||
prefix = 'xpath=' | ||
else: | ||
raise ValueError(f'Locator type not supported to be converted to playwright: {self.locator[0]}') | ||
playwright_locator = f'{prefix}{self.locator[1]}' | ||
return playwright_locator |
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