class fields(ParametrizedView): # noqa PARAMETERS = ("key", ) input = Input(id=Parameter("key")) param_input = Input(id=ParametrizedString("param_{key}")) dropdown = VersionPick({ Version.lowest(): BootstrapSelect(Parameter("key")), "5.9": DialogFieldDropDownList( ParametrizedLocator(".//div[@input-id={key|quote}]")) }) param_dropdown = VersionPick({ Version.lowest(): BootstrapSelect(ParametrizedString("param_{key}")), "5.9": DialogFieldDropDownList( ParametrizedLocator(".//div[@input-id='param_{key}']")) }) @property def visible_widget(self): if self.input.is_displayed: return self.input elif self.dropdown.is_displayed: return self.dropdown elif self.param_input.is_displayed: return self.param_input elif self.param_dropdown.is_displayed: return self.param_dropdown def read(self): return self.visible_widget.read() def fill(self, value): return self.visible_widget.fill(value)
class CatalogsMultiBoxSelect(MultiBoxSelect): available_options = Select(locator=ParametrizedLocator( ".//div[contains(text(), {@available_items|quote})]/select")) chosen_options = Select(locator=ParametrizedLocator( ".//div[contains(text(), {@chosen_items|quote})]/select")) move_into_button = Button(title=Parameter("@move_into")) move_from_button = Button(title=Parameter("@move_from"))
class fields(ParametrizedView): # noqa PARAMETERS = ("key", ) input = Input(id=Parameter("key")) select = Select(id=Parameter("key")) param_input = Input(id=ParametrizedString("param_{key}")) dropdown = BootstrapSelect(locator=ParametrizedLocator( ".//div[contains(@class, 'bootstrap-select')]/select[@id={key|quote}]/.." )) param_dropdown = BootstrapSelect(locator=ParametrizedLocator( ".//div[contains(@class, 'bootstrap-select')]/select[@id='param_{key}']/.." )) @property def visible_widget(self): for widget in (self.input, self.dropdown, self.param_input, self.param_dropdown, self.select): try: widget.wait_displayed('2s') return widget except TimedOutError: pass else: raise ItemNotFound("Visible widget is not found") def read(self): return self.visible_widget.read() def fill(self, value): return self.visible_widget.fill(value)
class fields(ParametrizedView): # noqa PARAMETERS = ("key", ) input = Input(id=Parameter("key")) select = Select(id=Parameter("key")) param_input = Input(id=ParametrizedString("param_{key}")) dropdown = VersionPick({ Version.lowest(): BootstrapSelect(Parameter("key")), "5.9": BootstrapSelect(locator=ParametrizedLocator( './/div[contains(@class, "bootstrap-select")]/select[@id={key|quote}]/..' )) }) param_dropdown = VersionPick({ Version.lowest(): BootstrapSelect(ParametrizedString("param_{key}")), "5.9": BootstrapSelect(locator=ParametrizedLocator( ".//div[contains(@class, 'bootstrap-select')]/select[@id='param_{key}']/.." )) }) @property def visible_widget(self): if self.browser.wait_for_element(self.input.locator, exception=False): return self.input elif self.browser.wait_for_element(self.dropdown.locator, exception=False): return self.dropdown elif self.browser.wait_for_element(self.param_input.locator, exception=False): return self.param_input elif self.browser.wait_for_element(self.param_dropdown.locator, exception=False): return self.param_dropdown elif self.browser.wait_for_element(self.select.locator, exception=False): return self.select else: raise ItemNotFound("Visible widget is not found") def read(self): return self.visible_widget.read() def fill(self, value): return self.visible_widget.fill(value)
class AnsibleExtraVariables(View): """Represents extra variables part of ansible service catalog edit form. Args: tab (str): tab name where this view is located. Can be "provisioning" or "retirement". """ variable = Input(name=ParametrizedString("{@tab}_key")) default_value = Input(name=ParametrizedString("{@tab}_value")) add = Button( **{"ng-click": ParametrizedString("vm.addKeyValue('{@tab}')")}) variables_table = Table( ".//div[@id='variables_div']//table", column_widgets={"Actions": ActionsCell(tab=Parameter("@tab"))}) def __init__(self, parent, tab, logger=None): View.__init__(self, parent, logger=logger) self.tab = tab def _values_to_remove(self, values): return list(map(tuple, set(self.all_vars) - set(values))) def _values_to_add(self, values): return list(map(tuple, set(values) - set(self.all_vars))) def fill(self, values): """ Args: values (list): [] to remove all vars or [("var", "value"), ...] to fill the view. """ if set(values) == set(self.all_vars): return False else: for value in self._values_to_remove(values): rows = list(self.variables_table) for row in rows: if row[0].text == value[0]: row["Actions"].widget.delete.click() break for value in self._values_to_add(values): self.variable.fill(value[0]) self.default_value.fill(value[1]) self.add.click() return True @property def all_vars(self): if self.variables_table.is_displayed: return [(row["Variable"].text, row["Default value"].text) for row in self.variables_table] else: return [] def read(self): return self.all_vars
class fields(ParametrizedView): # noqa PARAMETERS = ("key", ) input = Input(id=Parameter("key")) select = Select(id=Parameter("key")) param_input = Input(id=ParametrizedString("param_{key}")) dropdown = VersionPick({ Version.lowest(): BootstrapSelect(Parameter("key")), "5.9": BootstrapSelect(locator=ParametrizedString( ".//div[contains(@class, 'bootstrap-select') and " "select[@id={key|quote}]]")) }) param_dropdown = VersionPick({ Version.lowest(): BootstrapSelect(ParametrizedString("param_{key}")), "5.9": BootstrapSelect(locator=ParametrizedString( ".//div[contains(@class, 'bootstrap-select') and " "select[@id='param_{key}']]")) }) @property def visible_widget(self): if self.input.is_displayed: return self.input elif self.dropdown.is_displayed: return self.dropdown elif self.param_input.is_displayed: return self.param_input elif self.param_dropdown.is_displayed: return self.param_dropdown elif self.select.is_displayed: return self.select else: raise ItemNotFound("Visible widget is not found") def read(self): return self.visible_widget.read() def fill(self, value): return self.visible_widget.fill(value)
class fields(ParametrizedView): # noqa PARAMETERS = ("key", ) input = Input(id=Parameter("key")) select = Select(id=Parameter("key")) param_input = Input(id=ParametrizedString("param_{key}")) dropdown = BootstrapSelect(locator=ParametrizedLocator( ".//div[contains(@class, 'bootstrap-select')]/select[@id={key|quote}]/.." )) param_dropdown = BootstrapSelect(locator=ParametrizedLocator( ".//div[contains(@class, 'bootstrap-select')]/select[@id='param_{key}']/.." )) multi_drop = BootstrapSelect(locator=ParametrizedLocator( ".//div[contains(@class, 'bootstrap-select')]/select[@input-id={key|quote}]/.." )) checkbox = Checkbox(id=Parameter("key")) refresh = Text(locator=ParametrizedLocator( '//label[contains(text(), "{key}")]/following-sibling::div/button') ) radiogroup = RadioGroup(locator=( '//div[contains(@ng-switch-when, "DialogFieldRadioButton")]/span[contains(@class, ' '"ng-scope")]')) @property def visible_widget(self): for widget in (self.input, self.dropdown, self.param_input, self.param_dropdown, self.select): try: widget.wait_displayed('15s') return widget except TimedOutError: pass else: raise ItemNotFound("Visible widget is not found") def read(self): return self.visible_widget.read() def fill(self, value): return self.visible_widget.fill(value)
class dashboards(Tab, ParametrizedView): # noqa PARAMETERS = ('title', ) ALL_LOCATOR = './/ul[contains(@class, "nav-tabs-pf")]/li/a' COLUMN_LOCATOR = '//div[@id="col{}"]//h2' tab_name = Parameter('title') @classmethod def all(cls, browser): return [(browser.text(e), ) for e in browser.elements(cls.ALL_LOCATOR)] def column_widget_names(self, column_index): """Returns names of widgets in column specified. Args: column_index: Position of the column. Numbered from 1! Returns: :py:class:`list` of :py:class:`str` """ return [ self.browser.text(e) for e in self.browser.elements( self.COLUMN_LOCATOR.format(column_index)) ] @ParametrizedView.nested class widgets(ParametrizedView): # noqa PARAMETERS = ('title', ) ALL_LOCATOR = '//div[starts-with(@id, "w_")]//h2[contains(@class, "card-pf-title")]' BLANK_SLATE = './/div[contains(@class, "blank-slate-pf")]//h1' CHART = './div/div/div[starts-with(@id, "miq_widgetchart_")]' RSS = './div/div[contains(@class, "rss_widget")]' RSS_TABLE = './div[./div[contains(@class, "rss_widget")]]/div/table' TABLE = './div/table|./div/div/table' MC = ( './/div[contains(@class, "mc")]/*[1]|.//div[starts-with(@id, "dd_w") ' 'and contains(@id, "_box")]/*[1]') ROOT = ParametrizedLocator( './/div[starts-with(@id, "w_") and .//h2[contains(@class, "card-pf-title")' ' and normalize-space(.)={title|quote}]]') title = Text('.//h2[contains(@class, "card-pf-title")]') menu = Kebab(button_id=ParametrizedString('btn_{@widget_id}')) contents = ConditionalSwitchableView(reference='content_type') # Unsupported reading yet contents.register(None, default=True, widget=Widget()) contents.register('chart', widget=Widget()) # Reading supported contents.register('table', widget=Table(TABLE)) contents.register('rss', widget=Table(RSS_TABLE)) footer = Text('.//div[contains(@class, "card-pf-footer")]') @property def column(self): """Returns the column position of this widget. Numbered from 1!""" if self.browser.product_version < "5.10": parent = self.browser.element('..') else: parent = self.browser.element('../../..') try: parent_id = self.browser.get_attribute('id', parent).strip() return int(re.sub(r'^col(\d+)$', '\\1', parent_id)) except (ValueError, TypeError, AttributeError): raise ValueError( 'Could not get the column index of widget') @property def minimized(self): return not self.browser.is_displayed(self.MC) @cached_property def widget_id(self): id_attr = self.browser.get_attribute('id', self) return int(id_attr.rsplit('_', 1)[-1]) @cached_property def content_type(self): if self.browser.elements(self.BLANK_SLATE): # No data yet return None elif self.browser.elements(self.RSS): return 'rss' elif self.browser.is_displayed(self.CHART): return 'chart' elif self.browser.is_displayed(self.TABLE): return 'table' else: return None @property def blank(self): return bool(self.browser.elements(self.BLANK_SLATE)) @classmethod def all(cls, browser): return [(browser.text(e), ) for e in browser.elements(cls.ALL_LOCATOR)]
class CatalogsMultiBoxSelect(MultiBoxSelect): move_into_button = Button(title=Parameter("@move_into")) move_from_button = Button(title=Parameter("@move_from"))
class custom_button(ParametrizedView): # noqa PARAMETERS = ("button_group", ) _dropdown = Dropdown(text=Parameter("button_group")) def item_select(self, button, handle_alert=False): self._dropdown.item_select(button, handle_alert=handle_alert)
class MyView(View): my_param = Parameter('foo')
class MyView(View): my_param = Parameter("foo")