def fork(self, split_driver=False): """Create a fork of the node. If split_driver is True, then reset self.driver to the original URL and return a new object. Otherwise, return a ``ProjectPage`` or ``ComponentPage`` as appropriate. """ if split_driver: page = self._clone() else: page = self # Get the body element, so we know then the page has unloaded #body = self.driver.find_element_by_css_selector('body') with WaitForPageReload(self.driver): # click the fork icon page.driver.find_element_by_css_selector( '#overview div.btn-group:nth-of-type(2) a:nth-of-type(2)' ).click() # Wait at least until the page has unloaded to continue. # TODO: I think this is where the 2-3 second delay is. Fix that. #WebDriverWait(self.driver, 1).until(EC.staleness_of(body)) return page
def log_in(self, user): with WaitForPageReload(self.driver): form = self.driver.find_element_by_name('signin') form.find_element_by_id('username').send_keys(user.email) form.find_element_by_id('password').send_keys(user.password) form.find_element_by_css_selector('button[type=submit]').click() return UserDashboardPage(driver=self.driver)
def title(self, value): self.driver.find_element_by_id('node-title-editable').click() textbox = self.driver.find_element_by_css_selector( 'div.editable-popover input[type="text"]') textbox.clear() textbox.send_keys(value) with WaitForPageReload(self.driver): self.driver.find_element_by_css_selector( 'div.editable-popover button[type="submit"]').click()
def public(self, value): if self.public == value: return # If public, the "Make private" element will be the only <a>. # If private, the opposite is true. self.driver.find_element_by_css_selector( '#overview div.btn-group:nth-of-type(1) > a').click() confirm_button = self.driver.find_element_by_css_selector( 'div.modal.fade.in button.btn-primary') WebDriverWait(self.driver, 1).until(EC.visibility_of(confirm_button)) with WaitForPageReload(self.driver): confirm_button.click()
def add_registration(self, registration_type=None, meta=None): """Add a component to the project. :param registration_type: :param meta: An iterable containing metadata for the registration, in the order it appears in the registration's form. :returns ProjectRegistrationPage: """ # Go to the registrations page self.driver.find_element_by_css_selector( 'div.subnav').find_element_by_link_text('Registrations').click() # Click "New Registration" self.driver.find_element_by_link_text('New Registration').click() # Select the registration type self.driver.find_element_by_css_selector( '.container select').send_keys(registration_type + "\n") # Fill the registration template fields = self.driver.find_elements_by_css_selector( '#registration_template textarea, ' '#registration_template select') # make sure we have the right number of strings in meta if len(fields) != len(meta): raise ValueError( 'Length of meta argument ({}) must equal the number of form' 'fields in the registration template ({})'.format( len(meta), len(fields))) # fill the form (arbitrary length) for field, value in zip(fields, meta): field.send_keys(value) # Enter "continue" self.driver.find_elements_by_css_selector( '.container form input')[-1].send_keys('continue') with WaitForPageReload(self.driver): # click "Register" self.driver.find_element_by_css_selector( '.container form button').click() return ProjectRegistrationPage(driver=self.driver)
def add_api_key(self, description=None): self.driver.get('{}/settings'.format(config.osf_home)) form = self.driver.find_element_by_id('create_key') form.find_element_by_css_selector('input[name="label"]').send_keys( description or "Automatically generated key") with WaitForPageReload(self.driver): form.find_element_by_css_selector('button[type="submit"]').click() cred = self.driver.find_elements_by_css_selector( 'div.api-credential')[-1] return ApiKey( label=cred.find_element_by_css_selector('span.api-label').text, key=cred.find_element_by_css_selector('span.api-key').text, )
def add_contributor(self, user): with WaitForPageReload(self.driver): # click the "add" link self.driver.find_element_by_css_selector( '#contributors a[href="#addContributors"]').click() # enter the user's email address self.driver.find_element_by_css_selector( 'div#addContributors input[type=text]').send_keys(user.email) # click the search button self.driver.find_element_by_css_selector( '#addContributors button').click() # click the radio button for the first result self.driver.find_element_by_css_selector( '#addContributors input[type=radio]').click() # click the "Add" button self.driver.find_element_by_css_selector( '#addContributors button.btn.primary').click()