class UserProfile: # More About You CONTINUE_BUTTON = "Continue Button" MORE_ABOUT_YOU_HEADER = "More About You Header" # Profile if PLATFORM == "Android": USER_PROFILE = "User Profile" else: USER_PROFILE = 'label == "User Profile"' BACK_BUTTON = "Back Button" if PLATFORM == "Android": FIRST_NAME = "First Name Input" LAST_NAME = "Last Name Input" else: FIRST_NAME = "(//XCUIElementTypeTextField[@name='RNE__Input__text-input'])[1]" LAST_NAME = "(//XCUIElementTypeTextField[@name='RNE__Input__text-input'])[2]" def __init__(self, driver): self.driver = driver self.ew = ElementWrapper(self.driver) self.more_general = MoreGeneral(self.driver) def set_first_name(self, first_name): """ Inserts first name into name input :param first_name: str """ self.ew.wait_till_element_is_visible(self.FIRST_NAME, 5) self.ew.get_element(self.FIRST_NAME).send_keys(first_name) def set_last_name(self, last_name): """ Inserts last name into name input :param last_name: str """ self.ew.wait_till_element_is_visible(self.LAST_NAME, 5) self.ew.get_element(self.LAST_NAME).send_keys(last_name) def clear_first_name(self): """Deletes first name""" self.ew.get_element(self.FIRST_NAME).clear() def clear_last_name(self): """Deletes last name""" self.ew.get_element(self.LAST_NAME).clear() def get_full_name(self): """ Gets first and last name as full name :return: str """ first_name = self.ew.get_text_of_element(self.FIRST_NAME) last_name = self.ew.get_text_of_element(self.LAST_NAME) return f"{first_name} {last_name}" def save_user_profile(self): """Goes back to More section""" self.ew.tap_element(self.BACK_BUTTON) self.ew.wait_till_element_is_visible(self.more_general.MORE_HEADER, 10)
class PeriodFilter: if PLATFORM == "Android": PERIOD_FILTER_BUTTON = "Period Filter Button" else: PERIOD_FILTER_BUTTON = 'label == "Period Filter Button"' # PERIODS WEEK_PERIOD = "Week" MONTH_PERIOD = "Month" YEAR_PERIOD = "Year" ALL_TIME_PERIOD = "All Time" def __init__(self, driver): self.driver = driver self.ew = ElementWrapper(self.driver) def open_period_filter(self): """Opens period filter picker""" self.ew.wait_and_tap_element(self.PERIOD_FILTER_BUTTON, 20) def set_filter_period(self, period): """ Selects requested period on picker :param period: str """ self.open_period_filter() self.ew.wait_till_element_is_visible(period, 10) if PLATFORM == "Android": self.ew.tap_element(period) else: self.driver.execute_script("mobile: tap", { "x": 100, "y": 50, "element": self.ew.get_element(period) }) periods = { self.WEEK_PERIOD: "By weeks", self.MONTH_PERIOD: "By months", self.YEAR_PERIOD: "By years", self.ALL_TIME_PERIOD: "All time" } if PLATFORM == "Android": self.ew.wait_till_element_is_visible(periods[period], 10) else: actual_period = self.ew.get_attribute(self.PERIOD_FILTER_BUTTON, "name") while actual_period != periods[period]: time.sleep(0.5) actual_period = self.ew.get_attribute( self.PERIOD_FILTER_BUTTON, "name")
class CategoryDetail: CATEGORY_HEADER = "Category Header" SELECTED_ATTRIBUTES = '//android.view.ViewGroup[@content-desc="Category Icon"]/android.view.ViewGroup' SAVE_CATEGORY_BUTTON = "Save Category Button" TRASH_ICON = "Trash Icon" DELETE_BUTTON = "Delete" # NAME NAME_INPUT = "Name Input" SELECTED_NAME_IOS = '**/XCUIElementTypeTextField[`label == "Name Input"`]' def __init__(self, driver): self.driver = driver self.ew = ElementWrapper(self.driver) def set_name(self, name): """ Insets name into name input :param name: str """ if name == "random": name = ''.join([ random.choice(string.ascii_lowercase + string.digits) for n in range(0, 8) ]) self.ew.wait_till_element_is_visible(self.NAME_INPUT, 5) self.ew.get_element(self.NAME_INPUT).send_keys(name) vr.validate_input_against_output(name, self.get_name()) def get_name(self): """ Gets name from name input :return: str """ self.ew.wait_till_element_is_visible(self.NAME_INPUT, 5) if PLATFORM == "Android": return self.ew.get_text_of_element(self.NAME_INPUT) else: return self.ew.get_text_of_element(self.SELECTED_NAME_IOS) def set_color(self, color): """ Selects color from visible colors :param color: str """ if color == "random": color = random.choice(vs.accessible_colors) self.ew.wait_and_tap_element(color, 5) vr.validate_input_against_output(color, self.get_color()) def get_color(self): """ Gets #rgb of selected color :return: str """ self.ew.wait_till_element_is_visible(self.SELECTED_ATTRIBUTES, 5) name, color, image = self.ew.get_attribute(self.SELECTED_ATTRIBUTES, 'content-desc').split('/') return color def set_image(self, image): """ Sets image from visible images :param image: str or int """ if image == "random": image = random.randrange(1, 20) self.ew.wait_and_tap_element(image, 5) vr.validate_input_against_output(str(image), self.get_image()) def get_image(self): """ Gets id of selected image :return: str """ self.ew.wait_till_element_is_visible(self.SELECTED_ATTRIBUTES, 5) name, color, image = self.ew.get_attribute(self.SELECTED_ATTRIBUTES, 'content-desc').split('/') return image
class TransactionActions: EXISTING_TRANSACTION = "Existing Item: regular-undefined" EXISTING_TRANSACTION_TEMPLATES = [ "Existing Item: regular-every day", "Existing Item: regular-every 2 days", "Existing Item: regular-every working day", "Existing Item: regular-every week", "Existing Item: regular-every 2 weeks", "Existing Item: regular-every 4 weeks", "Existing Item: regular-every month", "Existing Item: regular-every 2 months", "Existing Item: regular-every 3 months", "Existing Item: regular-every 6 months", "Existing Item: regular-every year" ] def __init__(self, driver): self.driver = driver self.ew = ElementWrapper(self.driver) self.timeline_general = TimelineGeneral(self.driver) self.transaction_detail = TransactionDetail(self.driver) self.transfer_destination_modal = TransferDestinationModal(self.driver) def create_transaction(self, transaction_type, category, amount, currency, wallet, start_date, note, label, photo, recurrence, end_date, reminder): """ Opens create transaction screen and sets requested attributes :param transaction_type: str or None :param category: str or None :param amount: str or None :param currency: str or None :param wallet: str or None :param start_date: str or None :param note: str or None :param label: str or None :param photo: bool :param recurrence: str or None :param end_date: str or None :param reminder: str or None """ self.timeline_general.open_transaction_create_screen() if transaction_type is not None: self.transaction_detail.set_type_of_transaction(transaction_type) self.transaction_detail.set_category(category) self.transaction_detail.set_amount(amount) if currency is not None: self.transaction_detail.set_currency(currency) if wallet is not None: self.transaction_detail.set_wallet(wallet, "transaction") if start_date is not None: self.transaction_detail.set_start_date(start_date) if note is not None: self.transaction_detail.set_note(note) if label is not None: self.transaction_detail.set_label(label) if photo is not None: self.transaction_detail.set_photo() if recurrence is not None: self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) self.ew.swipe_if_element_not_present( self.transaction_detail.RECURRENCE) self.transaction_detail.set_recurrence(recurrence) if end_date is not None: self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) self.ew.swipe_if_element_not_present( self.transaction_detail.END_DATE) self.transaction_detail.set_end_date(end_date) if reminder is not None: self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) self.ew.swipe_if_element_not_present( self.transaction_detail.REMINDER) self.transaction_detail.set_reminder(reminder) self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) def save_transaction(self): """Clicks on save transaction button""" self.ew.wait_and_tap_element( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) if self.transfer_destination_modal.is_destination_modal_present( ) or self.transfer_destination_modal.is_origination_modal_present(): self.transfer_destination_modal.create_as_new_transaction() def open_transaction(self): """Opens existing transaction, if there is no one, it creates transaction""" self.ew.wait_till_element_is_visible( self.timeline_general.OVERVIEW_BUTTON, 30) self.timeline_general.go_to_timeline() if self.ew.is_element_present(self.EXISTING_TRANSACTION) is False: self.create_transaction(transaction_type="random", category="random", amount="random", currency=None, wallet=None, start_date=None, note=None, label=None, photo=None, recurrence=None, end_date=None, reminder=None) self.save_transaction() self.ew.wait_till_element_is_visible( self.timeline_general.NAVIGATION_TIMELINE, 30) self.ew.wait_and_tap_element(self.EXISTING_TRANSACTION, 15) self.ew.wait_till_element_is_visible( self.transaction_detail.TRANSACTION_HEADER_TITLE, 15) def open_transaction_template(self): """Opens existing transaction template, if there is no one, it creates transaction""" self.ew.wait_till_element_is_visible( self.timeline_general.TRANSACTION_SECTION, 60) if self.ew.is_element_present(self.timeline_general.SCHEDULED) is True: self.timeline_general.open_scheduled_section() for i in self.EXISTING_TRANSACTION_TEMPLATES: if self.ew.is_element_present(i): self.ew.tap_element(i) break elif i == "Existing Item: regular-every year": self.create_transaction(transaction_type="random", category="random", amount="random", currency=None, wallet=None, start_date=None, note=None, label=None, photo=None, recurrence="random", end_date=None, reminder=None) self.save_transaction() self.timeline_general.open_scheduled_section() for i in self.EXISTING_TRANSACTION_TEMPLATES: if self.ew.is_element_present(i): self.ew.tap_element(i) else: self.create_transaction(transaction_type="random", category="random", amount="random", currency=None, wallet=None, start_date=None, note=None, label=None, photo=None, recurrence="random", end_date=None, reminder=None) self.save_transaction() self.timeline_general.open_scheduled_section() for i in self.EXISTING_TRANSACTION_TEMPLATES: if self.ew.is_element_present(i): self.ew.tap_element(i) def edit_transaction(self, transaction_type, category, amount, wallet, start_date, note, label, photo, recurrence, end_date, reminder): """Edits requested attributes on transaction detail screen :param transaction_type: str or None :param category: str or None :param amount: str or None :param wallet: str or None :param start_date: str or None :param note: str or None :param label: str or None :param photo: bool :param recurrence: str or None :param end_date: str or None :param reminder: str or None """ if transaction_type is not None: self.ew.wait_and_tap_element(self.transaction_detail.CATEGORY_ICON, 10) if transaction_type == "transfer": self.transaction_detail.set_type_to_transfer() else: self.transaction_detail.set_type_of_transaction( transaction_type) self.transaction_detail.set_category("random") if category is not None: self.ew.wait_and_tap_element(self.transaction_detail.CATEGORY_ICON, 10) self.transaction_detail.set_category(category) if amount is not None: self.ew.wait_and_tap_element(self.transaction_detail.AMOUNT_INPUT, 10) self.ew.wait_till_element_is_visible( self.transaction_detail.NUMPAD_CLEAR, 10) for i in range(6): self.ew.tap_element(self.transaction_detail.NUMPAD_CLEAR) self.transaction_detail.set_amount(amount) if wallet is not None: self.transaction_detail.set_wallet(wallet, "transaction") if start_date is not None: self.transaction_detail.set_start_date(start_date) if note is not None: try: self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) self.ew.get_element( self.transaction_detail.EXISTING_NOTE).clear() except NoSuchElementException: pass self.transaction_detail.set_note(note) if label is not None: self.transaction_detail.set_label(label) if photo is not None: self.transaction_detail.set_photo() if recurrence is not None: self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) self.ew.swipe_if_element_not_present( self.transaction_detail.RECURRENCE) self.transaction_detail.set_recurrence(recurrence) if end_date is not None: self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) self.ew.swipe_if_element_not_present( self.transaction_detail.END_DATE) self.transaction_detail.set_end_date(end_date) if reminder is not None: self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) self.ew.swipe_if_element_not_present( self.transaction_detail.REMINDER) self.transaction_detail.set_reminder(reminder) self.ew.wait_till_element_is_visible( self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) def delete_transaction(self): """Deletes transaction from transaction detail screen""" self.ew.wait_and_tap_element(self.transaction_detail.TRASH_ICON, 10) self.ew.wait_and_tap_element(self.transaction_detail.DELETE_BUTTON, 10)
class TransferActions(): EXISTING_TRANSFER = "Existing Item: transfer-undefined" EXISTING_TRANSFER_TEMPLATES = ["Existing Item: transfer-every day", "Existing Item: transfer-every 2 days", "Existing Item: transfer-every working day", "Existing Item: transfer-every week", "Existing Item: transfer-every 2 weeks", "Existing Item: transfer-every 4 weeks", "Existing Item: transfer-every month", "Existing Item: transfer-every 2 months", "Existing Item: transfer-every 3 months", "Existing Item: transfer-every 6 months", "Existing Item: transfer-every year"] def __init__(self, driver): self.driver = driver self.ew = ElementWrapper(self.driver) self.timeline_general = TimelineGeneral(self.driver) self.transaction_actions = TransactionActions(self.driver) self.transaction_detail = TransactionDetail(self.driver) def create_transfer(self, amount, outgoing_wallet, incoming_wallet, start_date, note, recurrence, end_date, reminder): """ Opens create transfer screen and sets requested attributes :param amount: str or None :param outgoing_wallet: str or None :param incoming_wallet: str or None :param start_date: str or None :param note: str or None :param recurrence: str or None :param end_date: str or None :param reminder: str or None """ self.timeline_general.open_transaction_create_screen() self.transaction_detail.set_type_to_transfer() self.transaction_detail.set_amount(amount) if outgoing_wallet is not None: self.transaction_detail.set_wallet(outgoing_wallet, "transfer_outgoing") if incoming_wallet is not None: self.transaction_detail.set_wallet(incoming_wallet, "transfer_incoming") if start_date is not None: self.transaction_detail.set_start_date(start_date) if note is not None: self.transaction_detail.set_note(note) if recurrence is not None: self.transaction_detail.set_recurrence(recurrence) if end_date is not None: self.transaction_detail.set_end_date(end_date) if reminder is not None: self.transaction_detail.set_reminder(reminder) def open_transfer(self): """Opens existing transfer, if there is no one, it creates transfer""" self.timeline_general.go_to_timeline() self.ew.wait_till_element_is_visible(self.timeline_general.ADD_TRANSACTION_BUTTON, 30) print(self.ew.is_element_present(self.EXISTING_TRANSFER)) if self.ew.is_element_present(self.EXISTING_TRANSFER) is False: self.create_transfer(amount="random", outgoing_wallet=None, incoming_wallet=None, start_date=None, note=None, recurrence=None, end_date=None, reminder=None) self.transaction_actions.save_transaction() self.ew.wait_till_element_is_visible(self.timeline_general.NAVIGATION_TIMELINE, 30) self.ew.wait_and_tap_element(self.EXISTING_TRANSFER, 15) self.ew.wait_till_element_is_visible(self.transaction_detail.TRANSACTION_HEADER_TITLE, 15) def open_transfer_template(self): """Opens existing transfer template""" self.ew.wait_till_element_is_visible(self.timeline_general.TRANSACTION_SECTION, 60) if self.ew.is_element_present(self.timeline_general.SCHEDULED) is True: self.timeline_general.open_scheduled_section() for i in self.EXISTING_TRANSFER_TEMPLATES: if self.ew.is_element_present(i): self.ew.tap_element(i) break elif i == "Existing Item: transfer-every year": self.create_transfer(amount="random", outgoing_wallet=None, incoming_wallet=None, start_date=None, note=None, recurrence="random", end_date=None, reminder=None) self.transaction_actions.save_transaction() self.timeline_general.open_scheduled_section() for i in self.EXISTING_TRANSFER_TEMPLATES: if self.ew.is_element_present(i): self.ew.tap_element(i) else: self.create_transfer(amount="random", outgoing_wallet=None, incoming_wallet=None, start_date=None, note=None, recurrence="random", end_date=None, reminder=None) self.transaction_actions.save_transaction() self.timeline_general.open_scheduled_section() for i in self.EXISTING_TRANSFER_TEMPLATES: if self.ew.is_element_present(i): self.ew.tap_element(i) def edit_transfer(self, transaction_type, amount, outgoing_wallet, incoming_wallet, start_date, note, recurrence, end_date, reminder): """ Edits requested attributes on transfer detail screen :param transaction_type: str or None :param amount: str or None :param outgoing_wallet: str or None :param incoming_wallet: str or None :param start_date: str or None :param note: str or None :param recurrence: str or None :param end_date: str or None :param reminder: str or None """ if transaction_type is not None: self.ew.tap_element(self.transaction_detail.CATEGORY_ICON) if transaction_type == "transfer": self.transaction_detail.set_type_to_transfer() else: self.transaction_detail.set_type_of_transaction(transaction_type) self.transaction_detail.set_category("random") if amount is not None: self.ew.tap_element(self.transaction_detail.AMOUNT_INPUT) self.ew.wait_till_element_is_visible(self.transaction_detail.NUMPAD_CLEAR, 10) for i in range(6): self.ew.wait_and_tap_element(self.transaction_detail.NUMPAD_CLEAR, 5) self.transaction_detail.set_amount(amount) if outgoing_wallet is not None: if self.transaction_detail.get_wallet("transfer_outgoing") == "Out of Spendee": self.transaction_detail.set_wallet(outgoing_wallet, "transfer_outgoing") if incoming_wallet is not None: if self.transaction_detail.get_wallet("transfer_incoming") == "Out of Spendee": self.transaction_detail.set_wallet(incoming_wallet, "transfer_incoming") if start_date is not None: self.transaction_detail.set_start_date(start_date) if note is not None: try: self.ew.get_element(self.transaction_detail.EXISTING_NOTE).clear() except NoSuchElementException: pass self.transaction_detail.set_note(note) if recurrence is not None: self.transaction_detail.set_recurrence(recurrence) if end_date is not None: self.transaction_detail.set_end_date(end_date) if reminder is not None: self.ew.wait_till_element_is_visible(self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5) self.ew.swipe_if_element_not_present(self.transaction_detail.REMINDER) self.transaction_detail.set_reminder(reminder) self.ew.wait_till_element_is_visible(self.transaction_detail.SAVE_TRANSACTION_BUTTON, 5)