class DataTabSidebar(PageObject): _space_selector = WebElement('.data-spaces-select') _root_dir = ItemListWebElement('.data-files-tree ul li') def __init__(self, *args, **kwargs): self._resize_handler = kwargs.pop('resize_handler') super(DataTabSidebar, self).__init__(*args, **kwargs) def __str__(self): return 'sidebar in {}'.format(self.parent) @property def space_selector(self): return SpaceSelector(self.driver, self._space_selector, self) @property def width(self): return self._resize_handler.location['x'] @width.setter def width(self, value): offset = value - self.width action = ActionChains(self.driver) action.drag_and_drop_by_offset(self._resize_handler, offset, 0) action.perform() @property def root_dir(self): root, root_content = self._root_dir[:2] return DirectoryTree(self.driver, root, self, children=root_content) @property def cwd(self): cwd = self._cwd(self.root_dir) if cwd: return cwd else: raise RuntimeError('no working directory found') def _cwd(self, curr_dir): if curr_dir.is_active(): return curr_dir for directory in curr_dir: cwd = self._cwd(directory) if cwd: return cwd
class FileUploader(PageObject): heading = TextLabelWebElement('.panel-heading') _progress = WebElement('.resumable-progress') _rows = ItemListWebElement('ul.resumable-list li') @property def progress(self): return ProgressBar(self.driver, self._progress, self) def is_visible(self): return 'visible' in self.web_elem.get_attribute('class') def __str__(self): return 'file uploader in {}'.format(self.parent) def __iter__(self): return (FileUploadRow(self.driver, item, self) for item in self._rows) def __getitem__(self, selector): if isinstance(selector, int): items_count = self.items_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._rows, 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 items_count(self): return len(self._rows) def scroll_to_bottom(self): self.driver.execute_script('arguments[0].scrollIntoView();', self._rows[-1])
class DataTab(PageObject): toolbar = WebItem('header nav.navbar ul.data-files-list-toolbar', cls=DataTopToolBar) breadcrumbs = WebItem('.secondary-top-bar .file-breadcrumbs-list', cls=Breadcrumbs) file_browser = WebItem('.lower-main-content .data-files-list', cls=FileBrowser) file_uploader = WebItem('#main-content + .file-upload .file-upload', cls=FileUploader) _sidebar = ItemListWebElement('.lower-main-content nav.secondary-sidebar, ' '#data-sidebar-resize-handler') def __str__(self): return 'DATA tab in {}'.format(self.parent) @property def sidebar(self): sidebar, resize_handler = self._sidebar return DataTabSidebar(self.web_elem, sidebar, self, resize_handler=resize_handler)
class Breadcrumbs(PageObject): _breadcrumbs = ItemListWebElement('a.file-breadcrumb-item-link') def __str__(self): return 'Breadcrumbs({path}) in {parent}'.format(path=self.pwd(), parent=self.parent) def pwd(self): return '/'.join(directory.text for directory in self._breadcrumbs) def chdir(self, path): breadcrumbs = self._breadcrumbs i, dir1, dir2 = None, None, None err_msg = '{dir} not found on {idx}th position in {item}' for i, (dir1, dir2) in enumerate(izip(path.split('/'), breadcrumbs)): assert dir1 == dir2.text, err_msg.format(dir=dir1, idx=i, item=self) click_on_web_elem(self.driver, dir2, lambda: 'cannot click on {idx}th element in ' '{item}'.format(idx=i, item=self))
class OZLoggedIn(object): _atlas = WebElement('.onezone-atlas') _manage_account = HeaderWebElement('header.onezone-top-bar') _panels = ItemListWebElement('.main-accordion-group') panels = { 'data space management': DataSpaceManagementPanel, 'group management': GroupManagementPanel, 'go to your files': GoToYourFilesPanel, 'access tokens': AccessTokensPanel, 'user alias': UserAliasPanel } def __init__(self, driver): self.web_elem = driver def __str__(self): return 'Onezone page' def __getitem__(self, item): item = item.lower() cls = self.panels.get(item, None) if cls: item = item.replace('_', ' ').lower() for panel in (OZPanel(self.web_elem, panel, self) for panel in self._panels): if item == panel.name.lower(): panel.__class__ = cls return panel elif item == 'manage account': return ManageAccount(self.web_elem, self._manage_account, self) elif item == 'world map': return WorldMap(self.web_elem, self._atlas, self) else: raise RuntimeError('no "{}" on {} found'.format(item, str(self)))
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()