4
4
5
5
import httpx
6
6
from playwright .sync_api import sync_playwright
7
- from pydantic import BaseModel , Field
7
+ from pydantic import BaseModel , Field , TypeAdapter
8
8
9
9
BrowserType = Literal ["chrome" , "firefox" , "edge" , "safari" ]
10
10
DeviceType = Literal ["desktop" , "mobile" ]
@@ -148,7 +148,7 @@ def list_sessions(self) -> list[Session]:
148
148
149
149
response .raise_for_status ()
150
150
data = response .json ()
151
- return [Session ( ** item ) for item in data ]
151
+ return TypeAdapter ( list [Session ]). validate_python ( data )
152
152
153
153
def create_session (self , options : Optional [CreateSessionOptions ] = None ) -> Session :
154
154
payload = {"projectId" : self .project_id }
@@ -170,7 +170,7 @@ def create_session(self, options: Optional[CreateSessionOptions] = None) -> Sess
170
170
)
171
171
172
172
response .raise_for_status ()
173
- return Session ( ** response .json ())
173
+ return TypeAdapter ( Session ). validate_python ( response .json ())
174
174
175
175
def complete_session (self , session_id : str ) -> Session :
176
176
if not session_id or session_id == "" :
@@ -194,7 +194,7 @@ def complete_session(self, session_id: str) -> Session:
194
194
)
195
195
196
196
response .raise_for_status ()
197
- return Session ( ** response .json ())
197
+ return TypeAdapter ( Session ). validate_python ( response .json ())
198
198
199
199
def get_session (self , session_id : str ) -> Session :
200
200
response = httpx .get (
@@ -206,7 +206,7 @@ def get_session(self, session_id: str) -> Session:
206
206
)
207
207
208
208
response .raise_for_status ()
209
- return Session ( ** response .json ())
209
+ return TypeAdapter ( Session ). validate_python ( response .json ())
210
210
211
211
def get_session_recording (self , session_id : str ) -> list [SessionRecording ]:
212
212
response = httpx .get (
@@ -219,7 +219,7 @@ def get_session_recording(self, session_id: str) -> list[SessionRecording]:
219
219
220
220
response .raise_for_status ()
221
221
data = response .json ()
222
- return [SessionRecording ( ** item ) for item in data ]
222
+ return TypeAdapter ( list [SessionRecording ]). validate_python ( data )
223
223
224
224
def get_session_downloads (
225
225
self , session_id : str , retry_interval : int = 2000 , retry_count : int = 2
@@ -255,7 +255,7 @@ def get_debug_connection_urls(self, session_id: str) -> DebugConnectionURLs:
255
255
)
256
256
257
257
response .raise_for_status ()
258
- return DebugConnectionURLs ( ** response .json ())
258
+ return TypeAdapter ( DebugConnectionURLs ). validate_python ( response .json ())
259
259
260
260
def get_session_logs (self , session_id : str ) -> list [SessionLog ]:
261
261
response = httpx .get (
@@ -268,7 +268,7 @@ def get_session_logs(self, session_id: str) -> list[SessionLog]:
268
268
269
269
response .raise_for_status ()
270
270
data = response .json ()
271
- return [SessionLog ( ** item ) for item in data ]
271
+ return TypeAdapter ( list [SessionLog ]). validate_python ( data )
272
272
273
273
def load (self , url : Union [str , Sequence [str ]], ** args ):
274
274
if isinstance (url , str ):
0 commit comments