11import time
22import typing
3+ import copy
34
45import allure
56
67from gui .elements .button import Button
78from gui .elements .object import QObject
89from gui .elements .text_edit import TextEdit
9- from .base_popup import BasePopup
10- from ..objects_map import names
10+ from gui .objects_map import names
1111
1212
1313class SocialLinksPopup (QObject ):
@@ -24,21 +24,25 @@ def _get_list_item(self, index: int) -> QObject:
2424 self ._add_social_link_list_item .real_name ['index' ] = index
2525 return self ._add_social_link_list_item
2626
27- @allure .step ('Get social link field' )
28- def _get_text_field (self , occurrence : int ) -> QObject :
29- key = 'occurrence'
30- if occurrence :
31- self ._social_link_text_field .real_name [key ] = occurrence + 1
32- else :
33- if key in self ._social_link_text_field .real_name :
34- del self ._social_link_text_field .real_name [key ]
35- return self ._social_link_text_field
27+ @allure .step ('Get social link field by index' )
28+ def _get_text_field_by_index (self , index : int ) -> TextEdit :
29+ """Get text field by index without modifying the original real_name"""
30+ # Create a copy of the real_name to avoid modifying the original
31+ text_field_real_name = copy .deepcopy (self ._social_link_text_field .real_name )
32+
33+ if index > 0 :
34+ text_field_real_name ['occurrence' ] = index + 1
35+
36+ # Create a temporary TextEdit with the modified real_name
37+ temp_text_field = TextEdit (text_field_real_name )
38+ return temp_text_field
3639
3740 @allure .step ('Add link to link field' )
3841 def add_link (self , index : int , links : typing .List [str ]):
3942 self ._get_list_item (index ).click ()
4043 time .sleep (0.5 )
41- for occurrence , link in enumerate (links ):
42- self ._get_text_field (occurrence ).text = link
44+ for field_index , link in enumerate (links ):
45+ text_field = self ._get_text_field_by_index (field_index )
46+ text_field .text = link
4347 self ._add_button .click ()
4448 self .wait_until_hidden ()
0 commit comments