@@ -32,6 +32,10 @@ class Utilities:
32
32
Methods that may be useful, that have nothing to do with Selenium.
33
33
"""
34
34
35
+ # COUNTRY_CODES = {
36
+ # "US": "1", "CA": "1", "FR": "33", "DE": "49", "UK": "44", "JP": "81"
37
+ # }
38
+
35
39
def __init__ (self ):
36
40
self .state_province_abbr = {
37
41
# US States
@@ -469,6 +473,59 @@ def get_state_province_abbreviation(self, full_name: str) -> str:
469
473
"""
470
474
return self .state_province_abbr .get (full_name , "Not Found" )
471
475
476
+ def normalize_regional_phone_numbers (self , phone : str , region : str ) -> str :
477
+ """
478
+ Normalizes a phone number by separating the country prefix and verifying the rest of the number as an integer.
479
+ This is used for localization (l10n) regional tests.
480
+ Parameters:
481
+ -----------
482
+ phone : str
483
+ The phone number to be normalized.
484
+ region : str
485
+ The region (country) code to determine the correct country prefix.
486
+ Returns:
487
+ --------
488
+ str
489
+ The normalized phone number in the format <country-code><number>.
490
+ """
491
+
492
+ # Country code mapping for different regions
493
+ country_codes = {
494
+ "US" : "1" ,
495
+ "CA" : "1" ,
496
+ "FR" : "33" ,
497
+ "DE" : "49" ,
498
+ }
499
+
500
+ # Remove phone number extensions (e.g., "x555" or "ext 555")
501
+ phone = re .sub (r"\s*(?:x|ext)\s*\d*$" , "" , phone , flags = re .IGNORECASE )
502
+
503
+ # Remove all non-numeric characters
504
+ digits = re .sub (r"\D" , "" , phone )
505
+
506
+ # Determine country code
507
+ country_code = country_codes .get (region , "1" ) # Default to "1" (US/CA) if region is unknown
508
+ local_number = digits
509
+
510
+ # Check if phone already contains a valid country code
511
+ for code in country_codes .values ():
512
+ if digits .startswith (code ):
513
+ country_code = code
514
+ local_number = digits [len (code ):] # Remove country code from local number
515
+ break
516
+
517
+ # Handle leading zero in local numbers (France & Germany)
518
+ if region in ["FR" , "DE" ] and local_number .startswith ("0" ):
519
+ local_number = local_number [1 :] # Remove the leading zero
520
+
521
+ # Validate local number length
522
+ if len (local_number ) < 6 : # Too short to be valid
523
+ logging .warning (f"Invalid phone number format: { phone } " )
524
+ return ""
525
+
526
+ # Return formatted phone number with correct country code
527
+ return f"{ country_code } { local_number } "
528
+
472
529
473
530
class BrowserActions :
474
531
"""
0 commit comments