示例#1
0
class InvitePage(Page):
    url_tail = "/i/"  # i.e. https://ppay11.herokuapp.com/i/9acb52f3/934464476
    dynamic = True

    def load(self):
        try:
            self.nav = NavigationFunctions(self.driver)
            self.header = header.PubHeader(self.driver)
            self.h2 = self.driver.find_element_by_tag_name('h2')
            # load continue button if normal, signin button if link is expired
            if self.h2.text == 'Oops!':
                self.load_expired_link()
            else:
                self.load_body()
            return True
        except (NoSuchElementException, StaleElementReferenceException,
                WebDriverException) as e:
            return False

    def load_expired_link(self):
        """Invite has expired. Or error"""
        self.signin_button = self.driver.find_element_by_id('signin_button')

    def load_body(self):
        self.form = self.driver.find_element_by_tag_name('form')
        self.email_input = self.form.find_element_by_tag_name('input')
        self.continue_button = (
            self.form.find_element_by_class_name('primaryButton'))
        self.why_button = self.form.find_element_by_tag_name('a')

    def set_email(self, email):
        self.nav.set_input(self.email_input, email)

    def enter_email(self, email):
        self.set_email(email)
        self.click_continue()

    def get_email(self):
        return self.email_input.get_attribute('value')

    def click_why(self):
        self.nav.move_to_el(self.why_button)

    def click_continue(self):
        if self.h2.text == 'Oops!':  # (expired link)
            self.nav.move_to_el(self.signin_button)
        else:  # (normal link)
            self.nav.move_to_el(self.continue_button)

    def is_expired(self):
        """Return True if signin_button visible"""
        try:
            return self.signin_button.is_displayed()
        except Exception:
            return False
示例#2
0
class BusinessDetailsPage(Page):
    url_tail = 'add-business/detail'
    dynamic = False

    def load(self):
        try:
            self.nav = NavigationFunctions(self.driver)
            self.load_body()
            self.menu = menu.SideMenu(self.driver)
            self.header = header.PrivateHeader(self.driver)
            return True
        except (NoSuchElementException, StaleElementReferenceException) as e:
            return False

    def load_body(self):
        self.form = self.driver.find_element_by_class_name('form-horizontal')
        find_by = self.form.find_elements_by_tag_name
        find_by_id = self.form.find_element_by_id
        self.ein_input = find_by('input')[0]
        self.hr_email_input = find_by('input')[1]
        self.business_name_input = find_by('input')[2]
        self.dba_input = find_by('input')[3]

        self.line1_input = find_by_id('recipient_line1')
        self.line2_input = find_by_id('recipient_line2')
        self.city_input = find_by_id('recipient_city')

        # not sure which el we need to click
        self.state_cont = self.form.find_element_by_class_name(
            'state_dropdown')
        self.state_dd = self.state_cont.find_elements_by_tag_name('div')[3]
        self.postal_code_input = find_by_id('recipient_code')
        self.phone_input = find_by('input')[9]
        self.website_input = find_by('input')[10]
        self.continue_button = self.form.find_element_by_class_name(
            'primaryButton')

        self.load_agree_checkbox()

    def load_agree_checkbox(self):
        # cont = self.form.find_element_by_id('agreed')
        # self.agree_checkbox = cont.find_element_by_tag_name('input')
        self.agree_checkbox = self.form.find_element_by_id('agreed')

    # def toggle_agree(self):
    # 	self.scroll_to_bottom()
    # 	self.agree_checkbox.click()
    # 	time.sleep(.4)
    # 	self.load_body()

    def toggle_agree(self):
        # agree_checkbox is touchy.
        # Think you need to reload form after clicking checkbox or submitting form
        # (only need to reload form after submission if you toggle checkbox afterwards)
        self.nav.dismiss_keyboard()
        self.scroll_to_bottom()
        selected = self.agreed()
        if main.get_browser() == 'safari':
            self.nav.click_el(self.agree_cont)
        else:
            self.nav.click_el(self.agree_checkbox)
        if selected is self.agreed():
            print('checkbox not altered!')
        time.sleep(.4)

    def agreed(self):
        try:
            return self.agree_checkbox.is_selected()
        except (StaleElementReferenceException, WebDriverException) as e:
            self.load()
            return self.agree_checkbox.is_selected()

    def get_el(self, name):
        """Return input element given name. None if invalid name"""
        if name == 'business_name':
            return self.business_name_input
        elif name == 'dba':
            return self.dba_input
        elif name == 'ein':
            return self.ein_input
        elif name == 'hr_email':
            return self.hr_email_input
        elif name == 'line1':
            return self.line1_input
        elif name == 'line2':
            return self.line2_input
        elif name == 'city':
            return self.city_input
        elif name == 'postal_code':
            return self.postal_code_input
        elif name == 'phone':
            return self.phone_input
        elif name == 'website':
            return self.website_input
        elif name == 'state':
            if main.is_ios():  # click doesn't regester on self.state_cont
                return self.state_dd
            return self.state_cont
        else:
            return None

    def get(self, name):
        """Return the text of the element with the given name"""
        el = self.get_el(name)
        if el is not None:
            if name == 'state':
                # ignore text in label
                if not main.is_ios():  # ios: el is already the child
                    el = el.find_elements_by_tag_name('div')[0]
                return el.text
            return el.get_attribute('value')
        return None

    def set(self, name, value):
        """Pass in name of el and desired value. Don't use for setting state"""
        el = self.get_el(name)
        if el is not None:
            if name == 'state':
                time.sleep(.4)
                self.nav.dismiss_keyboard()
                self.nav.move_to_el(el)
                self.set_state(value)
            else:
                self.nav.set_input(el, value)

                # ios: Inputs dont seem to update unless you click after setting value
                # i.e. 'Required' errors won't show up just for sending keys.
                # if main.is_ios():
                # 	self.nav.click_el(el)

    def set_state(self, state_text):
        WDW(self.driver, 10).until(
            EC.presence_of_element_located(
                (By.CLASS_NAME, 'sm-state-menuitem')))
        try:
            self.states = self.driver.find_elements_by_class_name(
                'sm-state-menuitem')
            for i, state in enumerate(self.states):
                text = self.states[i].text
                if text == state_text:
                    self.nav.click_el(self.states[i])
                    break
        except NoSuchElementException:
            # couldn't find state. De-select dropdown
            AC(self.driver).send_keys(Keys.ESC).perform()
        WDW(self.driver, 10).until_not(
            EC.presence_of_element_located(
                (By.CLASS_NAME, 'sm-state-menuitem')))

    # select state by typing keys, then selecting state by pressing enter
    # Not used, doesn't work. Issues using AC functions. Use nav functions
    def type_state(self, state):
        self.move_to_el(self.state_dd)
        time.sleep(1.4)  # need decent wait before sending keys
        AC(self.driver).send_keys(state).perform()
        time.sleep(.4)
        AC(self.driver).send_keys(Keys.ENTER).perform()
        time.sleep(.4)

    def click_continue(self):
        self.scroll_to_bottom()
        time.sleep(.2)
        self.continue_button.click()

        try:
            WDW(self.driver,
                2).until_not(EC.presence_of_element_located((By.ID, 'agreed')))
            # not on details page anymore
        except TimeoutException:
            # still on page. Need to reload
            self.load()
示例#3
0
class DOBPage(Page):
    url_tail = "/i/"
    dynamic = True

    def load(self):
        try:
            self.nav = NavigationFunctions(self.driver)
            self.h1 = self.try_load_expired_header()
            # load continue button if normal, signin button if link is expired
            if self.h1 and self.h1.text == 'Oops!':
                self.load_expired_link()
            else:
                self.header = header.PubHeader(self.driver)
                self.load_body()

            return True
        except (NoSuchElementException, StaleElementReferenceException,
                IndexError) as e:
            return False

    def try_load_expired_header(self):
        # expired link has <h1> element w/ text 'Oops!'
        try:
            return self.driver.find_element_by_tag_name('h1')
        except NoSuchElementException:
            return None

    def load_expired_link(self):
        """Invite has expired. Or error"""
        self.signin_button = self.driver.find_element_by_id('signin_button')

    def load_body(self):
        self.form = self.driver.find_element_by_tag_name('form')
        self.dob_input = self.form.find_element_by_id('dob')
        self.zip_input = self.form.find_element_by_id('zip')
        self.continue_button = (
            self.form.find_element_by_class_name('primaryButton'))

    def set_dob(self, dob):
        self.nav.set_input(self.dob_input, dob)

    def set_zip(self, zipcode):
        self.nav.set_input(self.zip_input, zipcode)

    def get_dob(self):
        return self.dob_input.get_attribute('value')

    def get_zip(self):
        return self.zip_input.get_attribute('value')

    def click_continue(self):
        if self.is_expired():  # (expired link)
            self.nav.move_to_el(self.signin_button)
        else:  # (normal link)
            self.nav.move_to_el(self.continue_button)

    def is_expired(self):
        """Return True if signin_button visible"""
        try:
            return self.signin_button.is_displayed()
        except Exception:
            return False