25
25
26
26
class AssertionsBase :
27
27
def __init__ (
28
- self , locator : Locator , is_not : bool = False , message : Optional [str ] = None
28
+ self ,
29
+ locator : Locator ,
30
+ timeout : float = None ,
31
+ is_not : bool = False ,
32
+ message : Optional [str ] = None ,
29
33
) -> None :
30
34
self ._actual_locator = locator
31
35
self ._loop = locator ._loop
32
36
self ._dispatcher_fiber = locator ._dispatcher_fiber
37
+ self ._timeout = timeout
33
38
self ._is_not = is_not
34
39
self ._custom_message = message
35
40
@@ -43,7 +48,7 @@ async def _expect_impl(
43
48
__tracebackhide__ = True
44
49
expect_options ["isNot" ] = self ._is_not
45
50
if expect_options .get ("timeout" ) is None :
46
- expect_options ["timeout" ] = 5_000
51
+ expect_options ["timeout" ] = self . _timeout or 5_000
47
52
if expect_options ["isNot" ]:
48
53
message = message .replace ("expected to" , "expected not to" )
49
54
if "useInnerText" in expect_options and expect_options ["useInnerText" ] is None :
@@ -67,14 +72,20 @@ async def _expect_impl(
67
72
68
73
class PageAssertions (AssertionsBase ):
69
74
def __init__ (
70
- self , page : Page , is_not : bool = False , message : Optional [str ] = None
75
+ self ,
76
+ page : Page ,
77
+ timeout : float = None ,
78
+ is_not : bool = False ,
79
+ message : Optional [str ] = None ,
71
80
) -> None :
72
- super ().__init__ (page .locator (":root" ), is_not , message )
81
+ super ().__init__ (page .locator (":root" ), timeout , is_not , message )
73
82
self ._actual_page = page
74
83
75
84
@property
76
85
def _not (self ) -> "PageAssertions" :
77
- return PageAssertions (self ._actual_page , not self ._is_not , self ._custom_message )
86
+ return PageAssertions (
87
+ self ._actual_page , self ._timeout , not self ._is_not , self ._custom_message
88
+ )
78
89
79
90
async def to_have_title (
80
91
self , title_or_reg_exp : Union [Pattern [str ], str ], timeout : float = None
@@ -120,15 +131,19 @@ async def not_to_have_url(
120
131
121
132
class LocatorAssertions (AssertionsBase ):
122
133
def __init__ (
123
- self , locator : Locator , is_not : bool = False , message : Optional [str ] = None
134
+ self ,
135
+ locator : Locator ,
136
+ timeout : float = None ,
137
+ is_not : bool = False ,
138
+ message : Optional [str ] = None ,
124
139
) -> None :
125
- super ().__init__ (locator , is_not , message )
140
+ super ().__init__ (locator , timeout , is_not , message )
126
141
self ._actual_locator = locator
127
142
128
143
@property
129
144
def _not (self ) -> "LocatorAssertions" :
130
145
return LocatorAssertions (
131
- self ._actual_locator , not self ._is_not , self ._custom_message
146
+ self ._actual_locator , self . _timeout , not self ._is_not , self ._custom_message
132
147
)
133
148
134
149
async def to_contain_text (
@@ -676,18 +691,23 @@ async def not_to_be_in_viewport(
676
691
677
692
class APIResponseAssertions :
678
693
def __init__ (
679
- self , response : APIResponse , is_not : bool = False , message : Optional [str ] = None
694
+ self ,
695
+ response : APIResponse ,
696
+ timeout : float = None ,
697
+ is_not : bool = False ,
698
+ message : Optional [str ] = None ,
680
699
) -> None :
681
700
self ._loop = response ._loop
682
701
self ._dispatcher_fiber = response ._dispatcher_fiber
702
+ self ._timeout = timeout
683
703
self ._is_not = is_not
684
704
self ._actual = response
685
705
self ._custom_message = message
686
706
687
707
@property
688
708
def _not (self ) -> "APIResponseAssertions" :
689
709
return APIResponseAssertions (
690
- self ._actual , not self ._is_not , self ._custom_message
710
+ self ._actual , self . _timeout , not self ._is_not , self ._custom_message
691
711
)
692
712
693
713
async def to_be_ok (
0 commit comments