11import os
2+ import re
23
34from libs import CurrentExecution
45from libs .constants import (
78 object_properties ,
89 playwright_roles ,
910 screenshot_types ,
11+ wait_time ,
1012)
1113from libs .wrappers import *
1214
@@ -26,37 +28,55 @@ def capture_screenshot(self, identifier: str, action: str) -> None:
2628 # self.ce.page.set_viewport_size({"width": 1500, "height": 1500})
2729 self .ce .page .screenshot (path = _ss_path , type = screenshot_types .JPEG )
2830
29- def verify (self , locator : str , property : str , value : str , exact : bool = False , by_test_id : bool = False ) -> None :
31+ def verify (
32+ self ,
33+ locator : str ,
34+ property : str ,
35+ value : str ,
36+ exact : bool = False ,
37+ by_test_id : bool = False ,
38+ chain_locator : bool = False ,
39+ ) -> None :
40+ current_value = self .get_object_property (
41+ locator = locator , property = property , by_test_id = by_test_id , chain_locator = chain_locator
42+ )
3043 match property .lower ():
3144 case object_properties .TEXT :
32- text = self .get_object_property (locator = locator , property = property , by_test_id = by_test_id )
3345 if exact :
34- if value == text :
46+ if value == current_value :
3547 self .capture_screenshot (identifier = locator , action = "verify_text_passed" )
3648 else :
3749 self .capture_screenshot (identifier = locator , action = "verify_text_failed" )
38- assert value == text , f"Exact match failed. Expected: '{ value } ' but actual: '{ text } '."
50+ assert (
51+ value == current_value
52+ ), f"Exact match failed. Expected: '{ value } ' but actual: '{ current_value } '."
3953 else :
40- if clean_text (text = value ) in clean_text (text = text ):
54+ if clean_text (text = value ) in clean_text (text = current_value ):
4155 self .capture_screenshot (identifier = locator , action = "verify_text_passed" )
4256 else :
4357 self .capture_screenshot (identifier = locator , action = "verify_text_failed" )
44- assert clean_text (text = value ) in clean_text (text = text ), f"Text '{ value } ' not found in '{ text } '."
58+ assert clean_text (text = value ) in clean_text (
59+ text = current_value
60+ ), f"Text '{ value } ' not found in '{ current_value } '."
4561 case object_properties .VISIBILITY :
46- current_state = self .get_object_property (locator = locator , property = property , by_test_id = by_test_id )
47- if current_state == value :
62+ if current_value == value :
4863 self .capture_screenshot (identifier = locator , action = "verify_visibility_passed" )
4964 else :
5065 self .capture_screenshot (identifier = locator , action = "verify_visibility_failed" )
51- assert value == current_state , f"{ locator } is not visible."
66+ assert value == current_value , f"{ locator } is not visible."
5267
53- def get_object_property (self , locator : str , property : str , by_test_id : bool = False ) -> str :
68+ def get_object_property (
69+ self , locator : str , property : str , by_test_id : bool = False , chain_locator : bool = False
70+ ) -> str :
5471 match property :
5572 case object_properties .TEXT :
5673 if by_test_id :
5774 elem = self .ce .page .get_by_test_id (locator )
5875 else :
59- elem = self .ce .page .get_by_role (locator ).nth (0 )
76+ if chain_locator :
77+ elem = eval (f"self.ce.page.{ locator } " )
78+ else :
79+ elem = self .ce .page .get_by_role (locator ).nth (0 )
6080 elem .scroll_into_view_if_needed ()
6181 return "" .join (elem .all_text_contents ()).strip ()
6282 case object_properties .VISIBILITY :
@@ -65,10 +85,17 @@ def get_object_property(self, locator: str, property: str, by_test_id: bool = Fa
6585 _locator = locator .split (escape_characters .SEPARATOR )[1 ]
6686 elem = self .ce .page .get_by_role (_location , name = _locator ).nth (0 )
6787 else :
68- elem = self .ce .page .get_by_role (locator ).nth (0 )
88+ if chain_locator :
89+ wait (timeout = wait_time .MIN )
90+ elem = eval (f"self.ce.page.{ locator } " )
91+ else :
92+ elem = self .ce .page .get_by_role (locator ).nth (0 )
6993 return elem .is_visible ()
7094 case object_properties .HREF :
71- elem = self .ce .page .get_by_role ("link" , name = locator ).nth (0 )
95+ if chain_locator :
96+ elem = eval (f"self.ce.page.{ locator } " )
97+ else :
98+ elem = self .ce .page .get_by_role ("link" , name = locator ).nth (0 )
7299 return elem .get_attribute (object_properties .HREF )
73100
74101 def perform_action (self , locator , action , value = None , exact : bool = False ) -> None :
0 commit comments