def set_recurrence(self, recurrence): """ Selects requested recurrence of budget :param recurrence: str """ self.ew.wait_and_tap_element(self.RECURRENCE, 5) self.ew.wait_till_element_is_visible(self.RECURRENCE_PICKER, 5) if recurrence == "random": recurrence = random.choice(vs.budget_recurrences) res = self.rs.get_resolution() if PLATFORM == "Android": item_visible = self.ew.is_element_present(recurrence) while item_visible is False: self.action.long_press(None, self.rs.all_resolutions[f"{res}"]["x"], self.rs.all_resolutions[f"{res}"]["default_picker_up_y_start"]) \ .move_to(None, self.rs.all_resolutions[f"{res}"]["x"], self.rs.all_resolutions[f"{res}"]["default_picker_up_y_end"]) \ .release().perform() item_visible = self.ew.is_element_present(recurrence) self.ew.wait_and_tap_element(recurrence, 5) else: item_visible = self.ew.get_attribute(recurrence, "visible") while item_visible == "false": self.driver.execute_script("mobile: dragFromToForDuration", {"duration": "0.1", "fromX": self.rs.all_resolutions[f"{res}"]["x"], "fromY": self.rs.all_resolutions[f"{res}"]["default_picker_up_y_start"], "toX": self.rs.all_resolutions[f"{res}"]["x"], "toY": self.rs.all_resolutions[f"{res}"]["default_picker_up_y_end"]}) item_visible = self.ew.get_attribute(recurrence, "visible") self.driver.execute_script("mobile: tap", {"x": 100, "y": 50, "element": self.ew.get_element(recurrence)}) vr.validate_input_against_output(recurrence, self.get_recurrence())
def set_start_date(self, start_date): """ Sets start date :param start_date: str """ if start_date == "random": start_date = str( datetime.date(int(datetime.date.today().year), random.randint(1, 12), random.randint(1, 28))) elif start_date == "past": start_date = str(datetime.date.today() - datetime.timedelta(days=random.randint(1, 30))) elif start_date == "future": start_date = str(datetime.date.today() + datetime.timedelta(days=random.randint(1, 30))) elif start_date == "today": start_date = str(datetime.date.today()) elif start_date == "yesterday": start_date = str(datetime.date.today() - datetime.timedelta(days=1)) elif start_date == "tomorrow": start_date = str(datetime.date.today() + datetime.timedelta(days=1)) self.ew.wait_and_tap_element(self.START_DATE, 5) self.ew.wait_till_element_is_visible(self.CALENDAR_PICKER, 5) self.set_calendar_month_year(start_date) self.set_calendar_day(start_date) vr.validate_input_against_output(start_date, self.get_date("start"))
def set_type_of_transaction(self, transaction_type): """ Selects type of transaction :param transaction_type: str """ if transaction_type == "random": transaction_type = random.choice( [self.EXPENSES_PICKER, self.INCOME_PICKER]) elif transaction_type == "opposite": actual_type = self.get_type_of_transaction() if actual_type == "Expenses": transaction_type = self.INCOME_PICKER else: transaction_type = self.EXPENSES_PICKER elif transaction_type == "expenses": transaction_type = self.EXPENSES_PICKER elif transaction_type == "income": transaction_type = self.INCOME_PICKER if transaction_type == self.EXPENSES_PICKER: v_input = "Expenses" else: v_input = "Income" self.ew.wait_and_tap_element(transaction_type, 5) if PLATFORM == "Android": time.sleep(0.5) vr.validate_input_against_output(v_input, self.get_type_of_transaction())
def set_end_date(self, end_date): """ Selects end date of budget :param end_date: str """ start_date = self.transaction_detail.get_date("start") year_start, month_start, day_start = (int(x) for x in start_date.split('-')) start_date = datetime.date(year_start, month_start, day_start) if end_date == "random": end_date = str(start_date + datetime.timedelta(days=random.randint(1, 30))) elif end_date == "day_after_start_date": end_date = str(start_date + datetime.timedelta(days=1)) else: year_end, month_end, day_end = (int(x) for x in end_date.split('-')) end_date = datetime.date(year_end, month_end, day_end) if start_date < end_date: end_date = str(end_date) else: raise ValueError(f"endDate {end_date} is not older than start_date {str(start_date)}") self.ew.wait_and_tap_element(self.END_DATE, 5) self.ew.wait_till_element_is_visible(self.CALENDAR_PICKER, 5) self.transaction_detail.set_calendar_month_year(end_date) self.transaction_detail.set_calendar_day(end_date) vr.validate_input_against_output(end_date, self.transaction_detail.get_date("end"))
def set_type_to_transfer(self): """Will select type as transfer""" self.ew.wait_and_tap_element(self.TRANSFER_PICKER, 5) self.ew.wait_till_element_is_not_visible(self.TRANSFER_PICKER, 5) if self.ew.is_element_present(self.NUMPAD_BACKDROP): pass else: vr.validate_input_against_output("Transfer", self.get_category())
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 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 set_name(self, name): """ Insert 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 set_photo(self): """Selects photo""" self.ew.wait_and_tap_element(self.PHOTO, 5) self.ew.wait_and_tap_element(self.CHOOSE_PHOTO, 5) if self.ew.is_element_present(self.ALLOW_PHOTO_ACCESS_ANDROID): self.ew.tap_element(self.ALLOW_PHOTO_ACCESS_ANDROID) if PLATFORM == "Android": self.ew.wait_and_tap_element(self.PHOTO_FOLDER, 5) self.ew.wait_and_tap_element(self.PHOTO_ITEM, 5) vr.validate_input_against_output(True, self.get_photo())
def set_currency(self, currency): """ Selects currency :param currency: str """ if currency == "random": currency = random.choice(vs.accessible_currencies) self.ew.wait_and_tap_element(self.CURRENCY, 5) self.ew.wait_and_tap_element(f"Currency {currency}", 10) self.set_exchange_rate() vr.validate_input_against_output(currency, self.get_currency())
def set_currency(self, currency): """ Selects currency of budget :param currency: str """ if currency == "random": currency = random.choice(vs.accessible_currencies) self.ew.wait_and_tap_element(self.CURRENCY, 5) self.ew.wait_till_element_is_visible(self.CURRENCY_PICKER, 10) self.ew.wait_and_tap_element(f"Currency {currency}", 10) self.ew.wait_till_element_is_not_visible(self.CURRENCY_PICKER, 10) vr.validate_input_against_output(currency, self.get_currency())
def set_note(self, note): """ Insert note into note input :param note: str """ if note == "random": note = ''.join([ random.choice(string.ascii_lowercase + string.digits) for n in range(0, 8) ]) self.ew.wait_till_element_is_visible(self.NOTE_ELEMENT, 5) self.ew.get_element(self.NOTE).send_keys(note) if self.driver.is_keyboard_shown(): self.ew.tap_element(self.NOTE_ELEMENT) vr.validate_input_against_output(note, self.get_note())
def set_amount(self, amount): """ Insert amount into amount input :param amount: str """ if amount == "random": amount = str(random.randint(1, 99)) self.ew.wait_and_tap_element(self.AMOUNT_INPUT, 5) self.ew.wait_till_element_is_visible(self.KEYBOARD["1"], 10) amount_list = list(amount) for i in amount_list: self.ew.wait_and_tap_element(self.KEYBOARD[i], 5) self.ew.wait_and_tap_element(self.NUMPAD_BACKDROP, 5) vr.validate_input_against_output(amount, self.get_amount())
def set_amount(self, amount): """ Insert amount into amount input :param amount: str """ if amount == "random": amount = str(random.randint(1, 99)) self.ew.wait_till_element_is_visible(self.KEYBOARD["1"], 10) amount_list = list(amount) for i in amount_list: self.ew.wait_and_tap_element(self.KEYBOARD[i], 5) self.ew.wait_and_tap_element(self.NUMPAD_BACKDROP, 5) v_output = self.get_amount() if v_output.startswith("-"): v_output = v_output[1:] vr.validate_input_against_output(''.join(str(i) for i in amount_list), v_output)
def set_categories(self, categories): """ Selects requested number of categories :param categories: str """ self.ew.wait_and_tap_element(self.CATEGORIES, 5) self.ew.wait_till_element_is_visible(self.HEADER_BUDGET_FOR, 5) all_visible_categories = self.count_categories()[0] if categories == "random": categories = random.randrange(0, len(all_visible_categories)) if categories == "all_selected": if self.ew.is_element_present(self.SELECT_ALL_UNCHECKED): self.ew.tap_element(self.SELECT_ALL_UNCHECKED) elif self.ew.is_element_present(self.SELECT_ALL_PART): self.ew.tap_element(self.SELECT_ALL_PART) self.ew.tap_element(self.SELECT_ALL_UNCHECKED) elif categories == "all_unselected": if self.ew.is_element_present(self.SELECT_ALL_CHECKED): self.ew.tap_element(self.SELECT_ALL_CHECKED) elif self.ew.is_element_present(self.SELECT_ALL_PART): self.ew.tap_element(self.SELECT_ALL_PART) elif isinstance(categories, int): if self.ew.is_element_present(self.SELECT_ALL_CHECKED): self.ew.tap_element(self.SELECT_ALL_CHECKED) elif self.ew.is_element_present(self.SELECT_ALL_PART): self.ew.tap_element(self.SELECT_ALL_PART) x = 0 all_visible_categories = self.count_categories()[0] for i in all_visible_categories: x = x + 1 if x <= categories: self.ew.tap_element(i) if self.ew.is_element_present(self.SELECT_ALL_CHECKED): v_input = "All Expenses" else: v_input = str(len(self.count_categories()[1])) self.ew.tap_element(self.BACK_BUTTON) vr.validate_input_against_output(v_input, self.get_categories())
def set_category(self, category): """ Selects category from category picker :param category: str """ self.ew.wait_till_element_is_visible(self.TRANSACTION_PICKER, 5) if category == "random": category_visible = False timeout = time.time() + 15 while category_visible is False: category = random.choice(vs.default_set_of_categories) category_visible = self.ew.is_element_present( f"Category {category}") if time.time() > timeout: break self.ew.tap_element(f"Category {category}") self.ew.wait_till_element_is_not_visible(self.TRANSACTION_PICKER, 5) if self.ew.is_element_present(self.NUMPAD_BACKDROP): pass else: vr.validate_input_against_output(category, self.get_category())
def set_categories(self, categories): """ Selecting visible categories of wallet :param categories: "random" or int """ if PLATFORM == "Android": v_input = self.get_categories() self.ew.wait_and_tap_element(self.CATEGORIES, 5) self.ew.wait_till_element_is_visible(self.CATEGORIES_HEADER, 5) if categories == "random": categories = random.randint(1, 5) visible_categories = self.ew.get_elements(self.EYE_ICON) x = 0 for i in visible_categories: x = x + 1 if x <= categories: i.click() self.ew.wait_and_tap_element(self.BACK_BUTTON, 5) vr.validate_input_against_output( int(v_input) - categories, int(self.get_categories()))
def set_wallets(self, wallets): """ Selects wallets from wallets picker :param wallets: str or int """ self.ew.wait_and_tap_element(self.WALLETS, 5) self.ew.wait_till_element_is_visible(self.WALLET_PICKER, 5) all_visible_wallets = self.count_wallets()[0] selected_wallets = self.count_wallets()[1] non_selected_wallets = self.count_wallets()[2] total_wallets = len(all_visible_wallets) total_selected_wallets = len(selected_wallets) total_non_selected_wallets = len(non_selected_wallets) if wallets == "random": wallets_to_select = random.sample(all_visible_wallets, random.randrange(0, len(all_visible_wallets))) for i in wallets_to_select: if PLATFORM == "Android": self.ew.tap_element(i) else: self.ew.tap_element(f'label == "{i}"') elif wallets == "all_selected": if total_wallets != total_selected_wallets: for i in non_selected_wallets: if PLATFORM == "Android": self.ew.tap_element(i) else: self.ew.tap_element(f'label == "{i}"') elif wallets == "all_unselected": if total_wallets != total_non_selected_wallets: for i in selected_wallets: if PLATFORM == "Android": self.ew.tap_element(i) else: self.ew.tap_element(f'label == "{i}"') elif isinstance(wallets, int): x = 0 actual_selected_wallets = self.count_wallets()[1] for i in all_visible_wallets: x = x + 1 if x <= wallets and len(actual_selected_wallets) > 1: if PLATFORM == "Android": self.ew.tap_element(i) else: self.ew.tap_element(f'label == "{i}"') actual_selected_wallets = self.count_wallets()[1] selected_wallets = self.count_wallets()[1] total_wallets = len(self.count_wallets()[0]) total_selected_wallets = len(selected_wallets) if total_wallets == total_selected_wallets: v_input = "All Wallets" elif total_selected_wallets == 1: v_input = selected_wallets[0].split('-')[0] else: v_input = str(total_selected_wallets) self.ew.tap_element('Backdrop') vr.validate_input_against_output(v_input, self.get_wallets())
def set_wallet(self, wallet, type_of_wallet): """ Selects requested wallet from requested wallet picker :param wallet: str :param type_of_wallet: str """ selected_wallet = self.get_wallet(type_of_wallet) if type_of_wallet == "transaction": self.ew.wait_and_tap_element(self.WALLET, 5) elif type_of_wallet == "transfer_outgoing": self.ew.wait_and_tap_element(self.OUTGOING_WALLET, 5) elif type_of_wallet == "transfer_incoming": self.ew.wait_and_tap_element(self.INCOMING_WALLET, 5) self.ew.wait_till_element_is_visible(self.WALLET_PICKER, 5) wallets_in_picker = self.get_wallets_in_picker() if wallet == "random": wallet = random.choice(wallets_in_picker) if PLATFORM == "Android": self.ew.tap_element(wallet) else: self.ew.tap_element(f'label == "{wallet}"') elif wallet == "different": wallets_in_picker.remove(selected_wallet) wallet = random.choice(wallets_in_picker) if PLATFORM == "Android": self.ew.tap_element(wallet) else: self.ew.tap_element(f'label == "{wallet}"') elif wallet == "oos": for i in wallets_in_picker: if i.startswith('Out of Spendee'): postfix_oos = i.split('-')[1] wallet = f"Out of Spendee-{postfix_oos}" if PLATFORM == "Android": self.ew.tap_element(wallet) else: self.ew.tap_element(f'label == "{wallet}"') elif wallet == "not_oos": if self.ew.is_element_present("Out of Spendee-false"): wallets_in_picker.remove("Out of Spendee-false") elif self.ew.is_element_present("Out of Spendee-true"): wallets_in_picker.remove("Out of Spendee-true") wallet = random.choice(wallets_in_picker) if PLATFORM == "Android": self.ew.tap_element(wallet) else: self.ew.tap_element(f'label == "{wallet}"') else: if PLATFORM == "Android": self.ew.tap_element(wallet) else: self.ew.tap_element(f'label == "{wallet}"') self.ew.wait_till_element_is_not_visible(self.WALLET_PICKER, 5) if self.ew.is_element_present(self.CONFIRM_BUTTON): self.set_exchange_rate() v_input = wallet.split('-')[0] vr.validate_input_against_output(v_input, self.get_wallet(type_of_wallet))