Skip to content

Commit 37f44a4

Browse files
add fix for cc tests in l10n
1 parent 7e184d7 commit 37f44a4

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

modules/page_object_prefs.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,35 @@ def fill_and_save_cc_panel_information(
236236
credit_card_fill_information: The object containing all the sample data
237237
"""
238238
fields = {
239-
"card_number": credit_card_fill_information.card_number,
240-
"expiration_month": credit_card_fill_information.expiration_month,
241-
"expiration_year": f"20{credit_card_fill_information.expiration_year}",
242-
"name": credit_card_fill_information.name,
239+
"cc-number": credit_card_fill_information.card_number,
240+
"cc-exp-month": int(credit_card_fill_information.expiration_month),
241+
"cc-exp-year": f"20{credit_card_fill_information.expiration_year}",
242+
"cc-name": credit_card_fill_information.name,
243243
}
244244

245-
for field in fields:
246-
self.actions.send_keys(fields[field] + Keys.TAB).perform()
245+
# for field in fields:
246+
# self.actions.send_keys(fields[field] + Keys.TAB).perform()
247+
#
248+
# # Press tab again to navigate to the next field (this accounts for the second tab after the name field)
249+
# self.actions.send_keys(Keys.TAB).perform()
250+
# # Finally, press enter
251+
# self.actions.send_keys(Keys.ENTER).perform()
247252

248-
# Press tab again to navigate to the next field (this accounts for the second tab after the name field)
249-
self.actions.send_keys(Keys.TAB).perform()
250-
# Finally, press enter
251-
self.actions.send_keys(Keys.ENTER).perform()
253+
form_element = self.get_element("form-container")
254+
children = [
255+
x.get_attribute("id")
256+
for x in form_element.find_elements(By.CSS_SELECTOR, "*")
257+
]
258+
259+
for key, val in fields.items():
260+
if key in children:
261+
form_field = form_element.find_element(By.ID, key)
262+
if form_field.tag_name == "select":
263+
self.set_select_field(key, val)
264+
else:
265+
form_field.send_keys(val)
266+
self.get_element("save-button").click()
267+
return self
252268

253269
def add_entry_to_saved_payments(self, cc_data: CreditCardBase):
254270
"""
@@ -259,7 +275,7 @@ def add_entry_to_saved_payments(self, cc_data: CreditCardBase):
259275
Arguments:
260276
cc_data: The object containing all the sample data
261277
"""
262-
self.switch_to_saved_payments_popup_iframe()
278+
self.switch_to_edit_saved_payments_popup_iframe()
263279
self.fill_and_save_cc_panel_information(cc_data)
264280
self.switch_to_default_frame()
265281
self.close_dialog_box()
@@ -458,10 +474,18 @@ def get_password_exceptions_popup_iframe(self) -> WebElement:
458474
return iframe
459475

460476
# Data Extraction and Processing
461-
def set_country_autofill_panel(self, country: str) -> BasePage:
462-
"""Sets the country value in the autofill view"""
463-
select_country = Select(self.driver.find_element(By.ID, "country"))
464-
select_country.select_by_value(country)
477+
def set_select_field(self, field_selector: str, value: str | int) -> BasePage:
478+
"""Sets the select field to the correct value."""
479+
select_element = Select(self.driver.find_element(By.ID, field_selector))
480+
if field_selector == "cc-exp-month" or field_selector == "cc-exp-year":
481+
if field_selector == "cc-exp-year":
482+
available_options = [
483+
x.get_attribute("value") for x in select_element.options
484+
]
485+
value = available_options.index(value)
486+
select_element.select_by_index(value)
487+
else:
488+
select_element.select_by_value(value)
465489
return self
466490

467491
def fill_and_save_address_panel_information(
@@ -485,7 +509,7 @@ def fill_and_save_address_panel_information(
485509
"email": address_data.email,
486510
}
487511

488-
self.set_country_autofill_panel(address_data.country_code)
512+
self.set_select_field("country", address_data.country_code)
489513
form_element = self.get_element("form-container")
490514
children = [
491515
x.get_attribute("id")

0 commit comments

Comments
 (0)