1
+ import sys
2
+
3
+ sys .path .append (sys .path [0 ] + "/../../" )
4
+
5
+ from pageobject .locators import locators
6
+ from pageobject .locators import *
7
+
8
+ from pageobject .helpers import helpers
9
+ from pageobject .helpers import *
10
+ from dotenv import load_dotenv
11
+
12
+ load_dotenv ()
13
+
14
+ # user_name = os.getenv('LT_USERNAME')
15
+ # api_key = os.getenv('LT_ACCESS_KEY')
16
+
17
+ user_name = "ankurn"
18
+ api_key = "6Skayj4MMR4483tOhhdnHsJjLvozmyBI9D2ELd0pABI6m9oZut"
19
+
20
+ start_time = time .time ()
21
+
22
+ def get_lambdatest_all_builds ():
23
+ url = f"https://{ user_name } :{ api_key } @api.lambdatest.com/automation/api/v1/builds?limit=1000"
24
+ headers = {"accept" : "application/json" }
25
+
26
+ # SSL context for HTTPS request
27
+ ssl_context = ssl .create_default_context (cafile = certifi .where ())
28
+ response = requests .get (url , headers = headers )
29
+
30
+ if (response .status_code == 200 ):
31
+ builds_data = response .json ()
32
+ return builds_data
33
+ else :
34
+ print ("Failed to fetch builds. Status code:" , response .status_code )
35
+ print ("Error Message:" , response .text )
36
+ return None
37
+
38
+ def get_lambdatest_all_sessions ():
39
+ url = f"https://{ user_name } :{ api_key } @api.lambdatest.com/automation/api/v1/sessions"
40
+ headers = {"accept" : "application/json" }
41
+
42
+ # SSL context for HTTPS request
43
+ ssl_context = ssl .create_default_context (cafile = certifi .where ())
44
+ response = requests .get (url , headers = headers )
45
+
46
+ if (response .status_code == 200 ):
47
+ builds_data = response .json ()
48
+ return builds_data
49
+ else :
50
+ print ("Failed to fetch builds. Status code:" , response .status_code )
51
+ print ("Error Message:" , response .text )
52
+ return None
53
+
54
+ def main ():
55
+ print ("********* Getting Build Details *********\n " )
56
+ builds_data = get_lambdatest_all_builds ()
57
+ if builds_data is not None :
58
+ # Extract dashboard URLs from each build object
59
+ dashboard_urls = [build ['dashboard_url' ] for build in builds_data ['data' ]]
60
+
61
+ for dashboard_url in dashboard_urls :
62
+ print ("Dashboard URL:" , dashboard_url )
63
+
64
+ print ("\n ********* Getting Session Details *********\n " )
65
+ sessions_data = get_lambdatest_all_sessions ()
66
+ # print(sessions_data)
67
+ if sessions_data is not None :
68
+ # Extract dashboard URLs from each build object
69
+ session_name_urls = [session ['build_name' ] for session in sessions_data ['data' ]]
70
+
71
+ # Print the respective build names
72
+ for session_name_url in session_name_urls :
73
+ print ("Session Name:" , str (session_name_url ))
74
+
75
+ main ()
76
+ print ("\n Time elapsed is " + str ((time .time () - start_time )) + " seconds" )
0 commit comments