def __init__(self, owner, locatordict={}):
        super(ResourcesNewAuthorsForm,self).__init__(owner,locatordict)

        # load hub's classes
        ResourcesNewAuthorsForm_Locators = self.load_class('ResourcesNewAuthorsForm_Locators')
        ResourcesNewAuthorsAuthorsForm = self.load_class('ResourcesNewAuthorsAuthorsForm')
        ResourcesNewAuthorsAuthorsList = self.load_class('ResourcesNewAuthorsAuthorsList')

        # update this object's locator
        self.locators.update(ResourcesNewAuthorsForm_Locators.locators)

        # update the locators with those from the owner
        self.update_locators_from_owner()

        # setup page object's components
        self.group      = Select(self,{'base':'group'})
        self.access     = Select(self,{'base':'access'})

        self.authorform = IframeWrap(
                            ResourcesNewAuthorsAuthorsForm(
                                self,{'base':'authorsform'}),
                            ['authorsframe'])

        self.authorlist = IframeWrap(
                            ResourcesNewAuthorsAuthorsList(
                                self,{'base':'authorslist'}),
                            ['authorsframe'])

        self.submit     = Button(self,{'base':'submit'})

        self.fields = ['group','access']

        # update the component's locators with this objects overrides
        self._updateLocators()
Example #2
0
    def __init__(self, owner, locatordict, row_class, row_class_loc_dict):
        super(Upload3,self).__init__(owner,locatordict)

        # load hub's classes
        Upload3_Locators = self.load_class('Upload3_Locators')
        UploadListRow = self.load_class('UploadListRow')
        ItemList = self.load_class('ItemList')

        # update this object's locator
        self.locators.update(Upload3_Locators.locators)

        # update the locators with those from the owner
        self.update_locators_from_owner()

        # setup page object's components
        self.browse = IframeWrap(
                        Text(self,{'base':'browse'},click_focus=False),
                        ['uploadframe'])
        self.upload = IframeWrap(
                        Button(self,{'base':'upload'}),
                        ['uploadframe'])
        self.filelist = IframeWrap(
                            ItemList(self,
                                     {'base':'uploadlist',
                                      'row':'uploadlistrow'},
                                     row_class, row_class_loc_dict),
                            ['fileframe', 'uploadframe'])

        # update the component's locators with this objects overrides
        self._updateLocators()
class ResourcesNewAuthorsForm(BasePageWidget):
    def __init__(self, owner, locatordict={}):
        super(ResourcesNewAuthorsForm,self).__init__(owner,locatordict)

        # load hub's classes
        ResourcesNewAuthorsForm_Locators = self.load_class('ResourcesNewAuthorsForm_Locators')
        ResourcesNewAuthorsAuthorsForm = self.load_class('ResourcesNewAuthorsAuthorsForm')
        ResourcesNewAuthorsAuthorsList = self.load_class('ResourcesNewAuthorsAuthorsList')

        # update this object's locator
        self.locators.update(ResourcesNewAuthorsForm_Locators.locators)

        # update the locators with those from the owner
        self.update_locators_from_owner()

        # setup page object's components
        self.group      = Select(self,{'base':'group'})
        self.access     = Select(self,{'base':'access'})

        self.authorform = IframeWrap(
                            ResourcesNewAuthorsAuthorsForm(
                                self,{'base':'authorsform'}),
                            ['authorsframe'])

        self.authorlist = IframeWrap(
                            ResourcesNewAuthorsAuthorsList(
                                self,{'base':'authorslist'}),
                            ['authorsframe'])

        self.submit     = Button(self,{'base':'submit'})

        self.fields = ['group','access']

        # update the component's locators with this objects overrides
        self._updateLocators()


    def get_groups(self):

        return self.group.options()


    def get_access_levels(self):

        return self.access.options()


    def populate_form(self, data):

        for k,v in data.items():
            if v is None:
                continue
            if not k in self.fields:
                # bail, the key is not a field
                raise ValueError("invalid form field: %s" % (k))
            # find the widget in the object's dictionary and set its value
            widget = getattr(self,k)
            widget.value = v


    def submit_form(self,data):

        self.populate_form(data)
        return self.submit.click()

    def populate_authors_form(self,data):

        return self.authorform.populate_form(data)


    def submit_authors_form(self,data):

        return self.authorform.submit_form(data)


    def get_authors(self):
        """return a list of authors"""

        return self.authorlist.get_authors()


    def author_role(self,author,role=None):
        """adjust an author's role"""

        return self.authorlist.author_role(author,role)


    def move_author_up(self,author):
        """increase an author's position"""

        return self.authorlist.move_author_up(author)


    def move_author_down(self,author):
        """decrease an author's position"""

        return self.authorlist.move_author_down(author)


    def delete_author(self,author):
        """remove an author from the list"""

        return self.authorlist.delete_author(author)


    def author_organization(self,author,org=None):
        """set an author's organization"""

        return self.authorlist.author_organization(author,org)
browser.get('file://'+ os.path.join(installdir,'iframe_example.html'))

# create a page object to hold the widgets
po = BasePageObject(browser,None)
po.locators = { 'frame1' : 'css=#frame1' ,
                'frame2' : 'css=#frame2' ,
                't0'     : 'css=#t0' ,
                't1'     : 'css=#t1' ,
                't2'     : 'css=#t2' , }


t0 = TextArea(po,{'base':'t0'})

# t1 is a widget that represents the text area
# element inside of the first iframe
t1 = IframeWrap( TextArea(po,{'base':'t1'}),
                 ['frame1'] )

# t2 is a widget that represents the text area
# element inside of the second iframe
t2 = IframeWrap( TextArea(po,{'base':'t2'}),
                 ['frame2', 'frame1'] )


# print out the current text in the widgets
print "t0.value = %s" % (t0.value)
print "t1.value = %s" % (t1.value)
print "t2.value = %s" % (t2.value)

# update the text in the widgets
t0_new_text = 't0 text'
t1_new_text = 'new t1 text'
Example #5
0
class Upload3(BasePageWidget):
    """upload widget with browse input and upload button and file viewer.

       the browse input and upload buttons are inside of an iframe
       the file viewer is inside of two iframes
    """

    def __init__(self, owner, locatordict, row_class, row_class_loc_dict):
        super(Upload3,self).__init__(owner,locatordict)

        # load hub's classes
        Upload3_Locators = self.load_class('Upload3_Locators')
        UploadListRow = self.load_class('UploadListRow')
        ItemList = self.load_class('ItemList')

        # update this object's locator
        self.locators.update(Upload3_Locators.locators)

        # update the locators with those from the owner
        self.update_locators_from_owner()

        # setup page object's components
        self.browse = IframeWrap(
                        Text(self,{'base':'browse'},click_focus=False),
                        ['uploadframe'])
        self.upload = IframeWrap(
                        Button(self,{'base':'upload'}),
                        ['uploadframe'])
        self.filelist = IframeWrap(
                            ItemList(self,
                                     {'base':'uploadlist',
                                      'row':'uploadlistrow'},
                                     row_class, row_class_loc_dict),
                            ['fileframe', 'uploadframe'])

        # update the component's locators with this objects overrides
        self._updateLocators()


    @property
    def value(self):
        return self.get_uploaded_files()


    @value.setter
    def value(self,filenames):
        """upload list of filenames"""

        if not hasattr(filenames,'__iter__'):
            filenames = [filenames]

        for filename in filenames:
            self.browse.value = filename
            self.upload.click()

            # wait for the row to appear
            message = "row with filename %s did not appear" % (filename)

            def condition(browser):
                self.logger.debug('waiting until row with file %s appears' \
                    % (filename))
                row = self.filelist.get_row_by_property('filename',filename)
                return row is None

            ignored_exceptions = [ TimeoutException,
                                   NoSuchElementException,
                                   StaleElementReferenceException ]

            w = WebDriverWait(self._browser,10,
                    ignored_exceptions=ignored_exceptions)
            w.until(condition,message=message)


    def get_uploaded_files(self):
        """return a list of files uploaded to the wiki page"""

        fnames = []
        for row in self.filelist:
            fnames.append(row.value()['filename'])
        return fnames


    def delete_file(self,filename):
        """delete a file uploaded to the wiki page"""

        # get the row representing the file
        row = self.filelist.get_row_by_property('filename',filename)

        if row is None:
            raise NoSuchFileAttachmentError(
                "file named \"%s\" not uploaded" % (filename))

        # click the delete link
        row.delete.click()

        # wait for the row to disappear
        message = "row with filename %s did not disappear" % (filename)

        def condition(browser):
            self.logger.debug('waiting until row with file %s disappears' \
                % (filename))
            row = self.filelist.get_row_by_property('filename',filename)
            return row is None

        ignored_exceptions = [ TimeoutException,
                               NoSuchElementException,
                               StaleElementReferenceException ]

        w = WebDriverWait(self._browser,10,
                ignored_exceptions=ignored_exceptions)
        w.until_not(condition,message=message)