Source code for portal_web.tests.integration.pageobjects.elements

# For copyright and license terms, see COPYRIGHT.rst (top level of repository)
# Repository: https://github.com/C3S/portal_web

import re
import warnings

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

from .base import BasePageElement


[docs] class TextInputWidgetElement(BasePageElement): """ Deform TextInputWidget """ def __call__(self): return self.browser.find_element(By.ID, self.locator)
[docs] def get(self): return self().get_attribute("value")
[docs] def getRo(self): return self().text
[docs] def set(self, val): tf = self() tf.clear() tf.send_keys(val)
[docs] class TextAreaWidgetElement(TextInputWidgetElement): """ Deform TextAreaWidget """ pass
[docs] class HiddenWidgetElement(TextInputWidgetElement): """ Deform HiddenWidget """
[docs] def getRo(self): return self.get()
[docs] class PasswordWidgetElement(TextInputWidgetElement): """ Deform TextAreaWidget """ pass
[docs] class CheckedPasswordWidgetElement(TextInputWidgetElement): """ Deform TextAreaWidget """
[docs] def set(self, val): password = self() password.clear() password.send_keys(val) confirm = self.browser.find_element(By.ID, self.locator + '-confirm') confirm.clear() confirm.send_keys(val)
[docs] class RadioChoiceWidgetElement(BasePageElement): """ Deform RadioChoiceWidget """ def __call__(self): """returns radiobuttons""" rb = self.browser.find_elements(By.NAME, self.locator) if not rb: raise NoSuchElementException() return rb
[docs] def get(self): for rb in self(): if rb.is_selected(): return rb.get_attribute("value")
[docs] def getRo(self): """returns iterator of option""" option = self.browser.find_elements( By.XPATH, "//div[@id='item-"+self.locator+"']/div/p" ) if len(option) == 1: return re.sub( self.locator+'-', '', option[0].get_attribute("id") ) return False
[docs] def set(self, val): """val: iterator of option""" for rb in self(): if rb.get_attribute("value") == val: rb.click()
[docs] class CheckboxWidgetElement(BasePageElement): """ Deform CheckboxWidget """ def __call__(self): return self.browser.find_element(By.ID, self.locator)
[docs] def get(self): return self().is_selected()
[docs] def set(self, val): if val is not self.get(): self().click()
[docs] class CheckboxChoiceWidgetElement(BasePageElement): """ Deform CheckboxChoiceWidget """ def __call__(self): return self.browser.find_element(By.ID, self.locator)
[docs] def get(self): return self().is_selected()
[docs] def getRo(self): try: self() return True except: # noqa: E722 return False
[docs] def set(self, val): if val is not self.get(): self().click()
[docs] class DateInputWidgetElement(TextInputWidgetElement): """ Deform DateInputWidget """ pass
[docs] class FileUploadWidgetElement(BasePageElement): """ Deform FileUploadWidget """ def __init__(self, *args, **kwargs): '''to display not implemented warning''' super().__init__(*args, **kwargs) warnings.warn("PageObject element 'FileUploadWidgetElement' " "not implemented yet")
[docs] class DatatableSequenceWidgetElement(BasePageElement): """ Deform FileUploadWidget """ def __init__(self, *args, **kwargs): '''to display not implemented warning''' super().__init__(*args, **kwargs) warnings.warn("PageObject element 'DatatableSequenceWidgetElement' " "not implemented yet")
[docs] class ButtonElement(BasePageElement): """ Deform Button """ def __init__(self, browser, locator, name=None, formid=None): '''sets button name''' super().__init__(browser, locator) self.name = name self.formid = formid name = ''.join(word.title() for word in self.name.split('_')) self.postfix = "-".join(filter(None, [self.formid, name])) def __call__(self, timeout=30): self.browser.screenshot("REQUEST-%s" % self.postfix) with self.wait_for_page_load(timeout): self.browser.find_element(By.ID, self.locator).click() self.browser.screenshot("RESPONSE-%s" % self.postfix)