Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.page_element import PageElement
class InputText(PageElement):
@property
def text(self):
"""Get the element text value
:returns: element text value
"""
return self.web_element.get_attribute("value")
@text.setter
def text(self, value):
"""Set value on the element
:param value: value to be set
"""
if self.driver_wrapper.is_ios_test() and not self.driver_wrapper.is_web_test():
self.web_element.set_value(value)
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.
"""
import logging
from toolium.driver_wrapper import DriverWrappersPool
from toolium.pageelements.page_element import PageElement
from toolium.pageobjects.page_object import PageObject
class Group(PageObject, PageElement):
def __init__(self, by, value, parent=None, driver_wrapper=None, order=None, wait=False):
"""Initialize the Group object with the given locator components.
If parent is not None, find_elements will be performed over it, instead of
using the driver's method, so it can find nested elements.
:param by: locator type
:param value: locator value
:param parent: parent element (WebElement, PageElement or locator tuple)
:param driver_wrapper: driver wrapper instance
:param order: index value if the locator returns more than one element
:param wait: True if the page element must be loaded in wait_until_loaded method of the container page object
:param shadowroot: CSS SELECTOR of JS element where shadowroot tag appears
"""
self.logger = logging.getLogger(__name__) #: logger instance
self.locator = (by, value) #: tuple with locator type and locator value
def get_web_element(self, element):
"""Return the web element from a page element or its locator
:param element: either a WebElement, PageElement or element locator as a tuple (locator_type, locator_value)
:returns: WebElement object
"""
from toolium.pageelements.page_element import PageElement
if isinstance(element, WebElement):
web_element = element
elif isinstance(element, PageElement):
web_element = element.web_element
elif isinstance(element, tuple):
web_element = self.driver_wrapper.driver.find_element(*element)
else:
web_element = None
return web_element
def __init__(self, by, value, parent=None, order=None, wait=False, shadowroot=None):
"""Initialize the PageElement object with the given locator components.
If parent is not None, find_element will be performed over it, instead of
using the driver's method, so it can find nested elements.
:param by: locator type
:param value: locator value
:param parent: parent element (WebElement, PageElement or locator tuple)
:param order: index value if the locator returns more than one element
:param wait: True if the page element must be loaded in wait_until_loaded method of the container page object
:param shadowroot: CSS SELECTOR of JS element where shadowroot tag appears
"""
super(PageElement, self).__init__()
self.locator = (by, value) #: tuple with locator type and locator value
self.parent = parent #: element from which to find actual elements
self.order = order #: index value if the locator returns more than one element
self.wait = wait #: True if it must be loaded in wait_until_loaded method of the container page object
self.shadowroot = shadowroot #: CSS SELECTOR of the shadowroot for encapsulated element
self.driver_wrapper = DriverWrappersPool.get_default_wrapper() #: driver wrapper instance
self.reset_object(self.driver_wrapper)
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.page_element import PageElement
class Text(PageElement):
@property
def text(self):
return self.web_element.text
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.webdriver.support.ui import Select as SeleniumSelect
from toolium.pageelements.page_element import PageElement
class Select(PageElement):
@property
def option(self):
return self.selenium_select.first_selected_option.text
@option.setter
def option(self, value):
self.selenium_select.select_by_visible_text(value)
@property
def selenium_select(self):
return SeleniumSelect(self.web_element)
def wait_until_loaded(self, timeout=None):
"""Wait until page object is loaded
Search all page elements configured with wait=True
:param timeout: max time to wait
:returns: this page object instance
"""
for element in self._get_page_elements():
if hasattr(element, 'wait') and element.wait:
from toolium.pageelements.page_element import PageElement
if isinstance(element, PageElement):
# Pageelement and Group
element.wait_until_visible(timeout)
if isinstance(element, PageObject):
# PageObject and Group
element.wait_until_loaded(timeout)
return self
def _expected_condition_find_first_element(self, elements):
"""Try to find sequentially the elements of the list and return the first element found
:param elements: list of PageElements or element locators as a tuple (locator_type, locator_value) to be found
sequentially
:returns: first element found or None
:rtype: toolium.pageelements.PageElement or tuple
"""
from toolium.pageelements.page_element import PageElement
element_found = None
for element in elements:
try:
if isinstance(element, PageElement):
element._web_element = None
element._find_web_element()
else:
self.driver_wrapper.driver.find_element(*element)
element_found = element
break
except (NoSuchElementException, TypeError):
pass
return element_found
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 StaleElementReferenceException
from toolium.pageelements.page_element import PageElement
class Button(PageElement):
@property
def text(self):
"""Get the element text value
:returns: element text value
"""
try:
return self.web_element.text
except StaleElementReferenceException:
# Retry if element has changed
return self.web_element.text
def click(self):
"""Click the element
:returns: page element instance