Example #1
0
class TransferRecord(PageObject):
    name = TextLabelWebElement('td:first-of-type')
    username = TextLabelWebElement('td:nth-of-type(2)')
    destination = TextLabelWebElement('td:nth-of-type(3)')
    status_icon = IconWebElement('.cell-status')
    type_icon = IconWebElement('.cell-type')
    icon = IconWebElement('.transfer-file-icon')

    def __init__(self, driver, web_elem, parent, **kwargs):
        super(TransferRecord, self).__init__(driver, web_elem, parent,
                                             **kwargs)
        status_class = self.status_icon.get_attribute('class').split()
        type_class = self.type_icon.get_attribute('class').split()
        self.status = [x for x in status_class if x in TransferStatusList][0]
        self.type = [x for x in type_class if x in TransferTypeList][0]

    def get_chart(self):
        if not 'expanded-row' in self.web_elem.get_attribute('class'):
            raise RuntimeError(
                "Transfer record for file {} is not expanded".format(
                    self.name))
        return TransferChart(
            self.driver,
            self.web_elem.find_element_by_xpath(' .//following-sibling::tr'),
            self.web_elem)

    def is_expanded(self):
        return "expanded-row" in self.web_elem.get_attribute('class')

    def expand(self):
        if not self.is_expanded():
            self.web_elem.click()

    def collapse(self):
        if self.is_expanded():
            self.web_elem.click()

    def is_file(self):
        return "oneicon-file" in self.icon.get_attribute('class')

    def is_directory(self):
        return "oneicon-folder" in self.icon.get_attribute("class")

    def __str__(self):
        return 'Transfer row {} in {}'.format(self.name, self.parent)
Example #2
0
class _SpaceRecord(PageObject):
    name = id = TextLabelWebElement('.item-label',
                                    parent_name='given space record')
    _icon = IconWebElement('.item-icon .one-icon')

    def __str__(self):
        return '{name} in {parent}'.format(name=self.name, parent=self.parent)

    def is_home(self):
        return 'oneicon-space-home' in self._icon.get_attribute('class')
Example #3
0
class SpaceSelector(PageObject, ExpandableMixin):
    selected_space_name = TextLabelWebElement('.item-label')
    spaces = WebItemsSequence('ul.dropdown-menu-list li', cls=_SpaceRecord)
    _icon = IconWebElement('.item-icon .one-icon')
    _toggle = ToggleWebElement('a.dropdown-toggle')

    def __str__(self):
        return 'space selector in {}'.format(self.parent)

    def is_selected_space_home(self):
        return 'oneicon-space-home' in self._icon.get_attribute('class')
Example #4
0
class _SpaceRecord(PageObject):
    name = id = TextLabelWebElement('.one-label.truncate',
                                    parent_name='provider popup')
    size = TextLabelWebElement('.space-header-size')
    _space_icon = IconWebElement('.oneicon')

    def __str__(self):
        return '"{}" space record in {}'.format(self.name, self.parent)

    def is_home(self):
        return 'default' in self._space_icon.get_attribute('class')
Example #5
0
class FileRow(PageObject):
    name = TextLabelWebElement('.file-label', parent_name='given file row')
    size = TextLabelWebElement('.file-list-col-size')
    modification_date = TextLabelWebElement('.file-list-col-modification')

    _icon = IconWebElement('.file-icon .one-icon')
    _metadata_tool = IconWebElement('.file-tool-metadata')
    _share_tool = IconWebElement('.file-tool-share')

    def __str__(self):
        return '{item} in {parent}'.format(item=self.name,
                                           parent=str(self.parent))

    def is_selected(self):
        return 'active' in self.web_elem.get_attribute('class')

    def is_file(self):
        return 'file' in self._icon.get_attribute('class')

    def is_directory(self):
        return 'folder' in self._icon.get_attribute('class')

    def is_shared(self):
        return 'share' in self._icon.get_attribute('class')

    def is_tool_visible(self, name):
        tool = getattr(self, '_{tool}_tool'.format(tool=name))
        return '25p' in tool.get_attribute('class')

    def click_on_tool(self, name):
        tool = getattr(self, '_{tool}_tool'.format(tool=name))
        tool_icon = tool.find_element_by_css_selector('.oneicon')
        click_on_web_elem(self.driver, tool_icon,
                          lambda: 'cannot click on "{}" in '
                                  '{}'.format(name, self))

    def double_click(self):
        ActionChains(self.driver).double_click(self.web_elem).perform()
Example #6
0
class _ProviderRecord(PageObject, ExpandableMixin):
    name = id = TextLabelWebElement('.provider-header.truncate',
                                    parent_name='given provider record')
    spaces_count = TextLabelWebElement('.spaces-count')
    spaces = WebItemsSequence('ul.tertiary-list li.sidebar-provider-space',
                              cls=_SpaceRecord)
    _provider_icon = IconWebElement('.provider-icon .oneicon')
    _toggle = ToggleWebElement('.spaces-count')
    _click_area = WebElement('.secondary-item-container')
    _set_home_btn = ButtonWebElement('.secondary-item-element.star-toggle '
                                     '.oneicon-home-outline')
    _home_icon = WebElement('.secondary-item-element.star-toggle '
                            '.oneicon-home')

    def __str__(self):
        return 'provider record named: "{}" in {}'.format(
            self.name, self.parent)

    def is_home(self):
        home1 = 'provider-home' in self._provider_icon.get_attribute('class')
        try:
            _ = self._home_icon
        except RuntimeError:
            return False
        else:
            return True and home1

    def set_as_home(self):
        if not self.is_home():
            self._click_on_btn('set_home')

    def unset_from_home(self):
        if self.is_home():
            click_on_web_elem(
                self.driver, self._home_icon,
                'cannot click on home icon for {item} in '
                '{parent}'.format(item=self, parent=self.parent))

    def is_working(self):
        return 'color-provider-online' \
               in self._provider_icon.get_attribute('class')

    def is_not_working(self):
        return 'color-provider-offline' \
               in self._provider_icon.get_attribute('class')
Example #7
0
class FileBrowser(PageObject):
    empty_dir_msg = TextLabelWebElement('.empty-model-container')
    _empty_dir_icon = IconWebElement('.empty-dir-image')
    _files = ItemListWebElement('tbody tr.file-row')
    _files_with_metadata = ItemListWebElement('tbody tr.first-level')
    _bottom = WebElement('.file-row-load-more')

    def __str__(self):
        return 'file browser in {}'.format(self.parent)

    def __iter__(self):
        return (FileRow(self.driver, item, self) for item in self._files)

    def __getitem__(self, selector):
        if isinstance(selector, int):
            items_count = self.files_count
            if selector >= items_count:
                raise RuntimeError('requested index {index} out of bound '
                                   '{limit}'.format(index=selector,
                                                    limit=items_count))
            else:
                return FileRow(self.driver, nth(self._files, selector), self)
        elif isinstance(selector, (str, unicode)):
            for item in self:
                if item.name == selector:
                    return item
            else:
                raise RuntimeError('unable to find "{name}" in '
                                   '{item}'.format(name=selector, item=self))

    @property
    def files_count(self):
        return len(self._files)

    def is_empty(self):
        try:
            self._empty_dir_icon
        except RuntimeError:
            return False
        else:
            return True

    def get_metadata_for(self, name):
        for item1, item2 in iter_ahead(self._files_with_metadata):
            if 'file-row' in item1.get_attribute('class'):
                if 'file-row' not in item2.get_attribute('class'):
                    if FileRow(self.driver, item1, self).name == name:
                        return MetadataRow(self.driver, item2, self)
        else:
            raise RuntimeError('no metadata row for "{name}" in {item} '
                               'found'.format(name=name, item=self))

    def scroll_to_bottom(self):
        self.driver.execute_script('arguments[0].scrollIntoView();',
                                   self._bottom)

    @contextmanager
    def select_files(self):
        from platform import system as get_system
        
        ctrl_or_cmd_key = \
            Keys.COMMAND if get_system() == 'Darwin' else Keys.LEFT_CONTROL
        
        action = ActionChains(self.driver)

        action.shift_down = lambda: action.key_down(Keys.LEFT_SHIFT)
        action.shift_up = lambda: action.key_up(Keys.LEFT_SHIFT)
        action.ctrl_or_cmd_down = lambda: action.key_down(ctrl_or_cmd_key)
        action.ctrl_or_cmd_up = lambda: action.key_up(ctrl_or_cmd_key)
        action.select = lambda item: action.click(item.web_elem)

        yield action

        action.perform()