Skip to content

Commit 4df6e7d

Browse files
reworked create_address_profile to fix error
1 parent db7e677 commit 4df6e7d

10 files changed

+103
-55
lines changed

SELECTOR_INFO.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,20 @@ Location: about:preferences#search
459459
Path to .json: modules/data/about_prefs.components.json
460460
```
461461
```
462+
Selector Name: form-container
463+
Selector Data: "form"
464+
Description: Form to to fill in saved addresses data
465+
Location: about:preferences#privacy
466+
Path to .json: modules/data/about_prefs.components.json
467+
```
468+
```
469+
Selector Name: save-button
470+
Selector Data: "save"
471+
Description: Button to save filled in address form.
472+
Location: about:preferences#privacy
473+
Path to .json: modules/data/about_prefs.components.json
474+
```
475+
```
462476
Selector Name: find-in-settings
463477
Selector Data: "searchInput"
464478
Description: Find in Settings input field (is a shadow root)

l10n_CM/Unified/test_demo_ad_address_data_captured_in_doorhanger_and_stored.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_demo_ad_address_data_captured_in_doorhanger_and_stored(
5656
autofill_popup.element_has_text(zip_selector, expected_zip)
5757

5858
# Containing Country field
59-
expected_country = address_autofill_data.country
59+
expected_country = address_autofill_data.country_code
6060

6161
autofill_popup.element_has_text("address-doorhanger-country", expected_country)
6262

l10n_CM/Unified/test_demo_ad_autofill_dropdown_present_for_email_and_phone.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ def test_case():
1111
return "2888567"
1212

1313

14+
@pytest.fixture()
15+
def region():
16+
return "CA"
17+
18+
1419
def test_dropdown_presence_email_phone_field(
15-
driver: Firefox,
16-
region: str,
17-
address_autofill: AddressFill,
18-
util: Utilities,
19-
autofill_popup: AutofillPopup,
20+
driver: Firefox,
21+
region: str,
22+
address_autofill: AddressFill,
23+
util: Utilities,
24+
autofill_popup: AutofillPopup,
2025
):
2126
"""
2227
C2888567 - Verify that the autofill dropdown is displayed for the email and phone fields

l10n_CM/Unified/test_demo_ad_verify_new_address_added.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ def test_verify_new_address_is_added(
3333

3434
# open saved addresses and add entry
3535
about_prefs_privacy.open()
36+
about_prefs_privacy.get_saved_addresses_popup().click()
3637
about_prefs_privacy.add_entry_to_saved_addresses(address_autofill_data)
37-
driver.switch_to.frame(1)
38+
about_prefs_privacy.switch_to_saved_addresses_popup_iframe()
3839

3940
# verify that the address saved is the same.
4041
# The address saved in step 2 is listed in the "Saved addresses" modal: name and organization

l10n_CM/region/US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"region": "US",
3-
"tests": ["test_demo_ad_autofill_dropdown_present_for_email_and_phone.py"]
3+
"tests": []
44
}

l10n_CM/region/Unified.json

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
22
"tests": [
3-
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
4-
"test_demo_ad_autofill_name_org.py",
5-
"test_demo_ad_autofill_phone_email.py",
6-
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
7-
"test_demo_ad_email_phone_captured_in_doorhanger_and_stored.py",
8-
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
9-
"test_demo_ad_verify_new_address_added.py",
10-
"test_demo_cc_add_new_credit_card.py",
11-
"test_demo_cc_clear_form.py",
12-
"test_demo_cc_doorhanger_data_is_stored_in_about_prefs.py",
13-
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
14-
"test_demo_cc_dropdown_presence.py",
15-
"test_demo_cc_autofill_from_dropdown.py",
16-
"test_demo_cc_yellow_highlight.py",
17-
"test_demo_ad_autofill_address_fields.py",
18-
"test_demo_ad_yellow_highlight_name_org.py",
19-
"test_demo_ad_yellow_highlight_address.py",
20-
"test_demo_ad_yellow_highlight_phone_email.py",
21-
"test_demo_ad_dropdown_presence_address.py",
22-
"test_demo_ad_clear_name_org.py",
23-
"test_demo_ad_clear_address_fields.py",
24-
"test_demo_ad_clear_tel_email.py"
3+
"test_demo_ad_address_data_captured_in_doorhanger_and_stored.py",
4+
"test_demo_ad_autofill_name_org.py",
5+
"test_demo_ad_autofill_phone_email.py",
6+
"test_demo_ad_doorhanger_shown_on_valid_address_submission.py",
7+
"test_demo_ad_email_phone_captured_in_doorhanger_and_stored.py",
8+
"test_demo_ad_name_org_captured_in_doorhanger_and_stored.py",
9+
"test_demo_ad_verify_new_address_added.py",
10+
"test_demo_cc_add_new_credit_card.py",
11+
"test_demo_cc_clear_form.py",
12+
"test_demo_cc_doorhanger_data_is_stored_in_about_prefs.py",
13+
"test_demo_cc_doorhanger_shown_on_valid_credit_card_submission.py",
14+
"test_demo_cc_dropdown_presence.py",
15+
"test_demo_cc_autofill_from_dropdown.py",
16+
"test_demo_cc_yellow_highlight.py",
17+
"test_demo_ad_autofill_address_fields.py",
18+
"test_demo_ad_yellow_highlight_name_org.py",
19+
"test_demo_ad_yellow_highlight_address.py",
20+
"test_demo_ad_yellow_highlight_phone_email.py",
21+
"test_demo_ad_dropdown_presence_address.py",
22+
"test_demo_ad_clear_name_org.py",
23+
"test_demo_ad_clear_address_fields.py",
24+
"test_demo_ad_clear_tel_email.py",
25+
"test_demo_ad_autofill_dropdown_present_for_email_and_phone.py"
2526
]
2627
}

modules/page_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,11 @@ def wait_for_num_tabs(self, num_tabs: int) -> Page:
679679
)
680680
return self
681681

682+
def switch_to_default_frame(self) -> Page:
683+
"""Switch to default content frame"""
684+
self.driver.switch_to.default_content()
685+
return self
686+
682687
def switch_to_new_tab(self) -> Page:
683688
"""Get list of all window handles, switch to the newly opened tab"""
684689
with self.driver.context(self.driver.CONTEXT_CONTENT):

modules/page_object_autofill.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,11 @@ def verify_autofill_dropdown_addresses(
597597
)
598598

599599
def autofill_and_verify(
600-
self, address_autofill_popup, field_label, address_autofill_data, util
600+
self,
601+
address_autofill_popup,
602+
field_label,
603+
address_autofill_data: AutofillAddressBase,
604+
util,
601605
):
602606
"""
603607
Autofills a form field, verifies the data, and clears it if necessary.
@@ -609,13 +613,13 @@ def autofill_and_verify(
609613
The popup handler for autofill suggestions.
610614
field_label : str
611615
The label of the field being autofilled.
612-
address_autofill_data : dict
616+
address_autofill_data : AutofillAddressBase
613617
The generated autofill data for verification.
614618
region : str
615619
The region code to handle localization.
616620
"""
617621
# Skip address-level1 (State) selection for DE and FR
618-
if field_label == "address-level1" and address_autofill_data.country in [
622+
if field_label == "address-level1" and address_autofill_data.country_code in [
619623
"DE",
620624
"FR",
621625
]:
@@ -628,7 +632,7 @@ def autofill_and_verify(
628632

629633
# Verify autofill data
630634
self.verify_autofill_data(
631-
address_autofill_data, address_autofill_data.country, util
635+
address_autofill_data, address_autofill_data.country_code, util
632636
)
633637

634638
# Clear form autofill
@@ -662,7 +666,10 @@ def verify_all_fields_cleared(self):
662666
assert not value, f"Field '{field}' is not empty: Found '{value}'"
663667

664668
def clear_and_verify(
665-
self, address_autofill_popup, field_label, address_autofill_data
669+
self,
670+
address_autofill_popup,
671+
field_label,
672+
address_autofill_data: AutofillAddressBase,
666673
):
667674
"""
668675
Autofills a form field, clears it, and verifies that it is empty.
@@ -680,7 +687,7 @@ def clear_and_verify(
680687
The region code to handle localization.
681688
"""
682689
# Skip address-level1 (State) selection for DE and FR
683-
if field_label == "address-level1" and address_autofill_data.country in [
690+
if field_label == "address-level1" and address_autofill_data.country_code in [
684691
"DE",
685692
"FR",
686693
]:

modules/page_object_prefs.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,24 @@ def organize_data_into_obj(self, observed_text: List[str]) -> AutofillAddressBas
144144
address_level_2 = observed_text[2]
145145
organization = observed_text[3]
146146
address_level_1 = observed_text[4]
147-
country = observed_text[5]
147+
country_code = observed_text[5]
148148
postal_code = observed_text[6]
149149
telephone = observed_text[7]
150150
email = observed_text[8]
151151

152152
return AutofillAddressBase(
153-
name,
154-
organization,
155-
address,
156-
address_level_2,
157-
address_level_1,
158-
postal_code,
159-
country,
160-
email,
161-
telephone,
153+
name=name,
154+
organization=organization,
155+
street_address=address,
156+
address_level_2=address_level_2,
157+
address_level_1=address_level_1,
158+
postal_code=postal_code,
159+
country_code=country_code,
160+
email=email,
161+
telephone=telephone,
162162
)
163163

164-
def fill_autofill_panel_information(
164+
def fill_and_save_autofill_panel_information(
165165
self, autofill_info: AutofillAddressBase
166166
) -> BasePage:
167167
"""
@@ -269,16 +269,30 @@ def get_saved_addresses_popup_iframe(self) -> WebElement:
269269
"""
270270
Returns the iframe object for the dialog panel in the popup
271271
"""
272-
self.get_element("prefs-button", labels=["Saved addresses"]).click()
272+
self.get_saved_addresses_popup().click()
273273
iframe = self.get_element("browser-popup")
274274
return iframe
275275

276+
def get_saved_addresses_popup(self) -> WebElement:
277+
"""
278+
Returns saved addresses button element
279+
"""
280+
return self.get_element("prefs-button", labels=["Saved addresses"])
281+
276282
def switch_to_saved_addresses_popup_iframe(self) -> BasePage:
277283
"""
278284
switch to save addresses popup frame.
279285
"""
280-
save_addresses = self.get_saved_addresses_popup_iframe()
281-
self.driver.switch_to.frame(save_addresses)
286+
self.switch_to_default_frame()
287+
self.driver.switch_to.frame(1)
288+
return self
289+
290+
def switch_to_edit_saved_addresses_popup_iframe(self) -> BasePage:
291+
"""
292+
Switch to form iframe to edit saved addresses.
293+
"""
294+
self.switch_to_default_frame()
295+
self.driver.switch_to.frame(2)
282296
return self
283297

284298
def add_entry_to_saved_addresses(self, address_data: AutofillAddressBase):
@@ -290,10 +304,9 @@ def add_entry_to_saved_addresses(self, address_data: AutofillAddressBase):
290304
"""
291305
self.switch_to_saved_addresses_popup_iframe()
292306
self.get_element("add-address").click()
293-
self.driver.switch_to.default_content()
294-
self.driver.switch_to.frame(2)
295-
self.fill_autofill_panel_information(address_data)
296-
self.driver.switch_to.default_content()
307+
self.switch_to_edit_saved_addresses_popup_iframe()
308+
self.fill_and_save_autofill_panel_information(address_data)
309+
self.switch_to_default_frame()
297310
return self
298311

299312
def get_password_exceptions_popup_iframe(self) -> WebElement:

tests/form_autofill/test_create_profile_autofill.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def test_create_address_profile(driver: Firefox):
3333
).click()
3434

3535
# fill in the data and clean it up
36-
about_prefs_obj.fill_autofill_panel_information(autofill_sample_data)
36+
about_prefs_obj.add_entry_to_saved_addresses(autofill_sample_data)
37+
about_prefs_obj.switch_to_saved_addresses_popup_iframe()
3738
saved_address_option = about_prefs_obj.get_element("saved-addresses")
3839
inner_content = saved_address_option.get_attribute("innerHTML")
3940
cleaned_data = about_prefs_obj.extract_content_from_html(inner_content)
@@ -47,6 +48,7 @@ def test_create_address_profile(driver: Firefox):
4748

4849
# currently ignoring the address level 1 field
4950
observed_data.telephone = util.normalize_phone_number(observed_data.telephone)
51+
observed_data.country = autofill_sample_data.country
5052
observed_data.address_level_1 = autofill_sample_data.address_level_1
5153

5254
# ensure that the objects have the same fields

0 commit comments

Comments
 (0)