Skip to content

Commit fd4e5a3

Browse files
authored
Refactor logging to use print statements
Updated logging to use print statements instead of logger. Removed unnecessary comments and adjusted error handling.
1 parent d90aee4 commit fd4e5a3

1 file changed

Lines changed: 54 additions & 55 deletions

File tree

  • py-scripts/real_application_tests/teams_automation/teams_client_side_files

py-scripts/real_application_tests/teams_automation/teams_client_side_files/teams_client.py

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,10 @@
1515
import traceback
1616
import pyautogui
1717

18-
pyautogui.FAILSAFE = False
19-
20-
# 1. Configure the logging system
2118
logging.basicConfig(
22-
level=logging.INFO,
23-
format="%(asctime)s - %(levelname)s - %(message)s",
24-
handlers=[
25-
logging.FileHandler(
26-
"teams_client.log",
27-
mode="w",
28-
), # Writes to file
29-
logging.StreamHandler(sys.stdout), # Writes to terminal
30-
],
19+
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
3120
)
3221

33-
# 2. Create the logger instance
34-
logger = logging.getLogger(__name__)
35-
3622

3723
class TeamsClient:
3824

@@ -83,6 +69,8 @@ def login(
8369
nextButton = self.wait_for_element('//*[@id="idSIButton9"]')
8470
nextButton.click()
8571

72+
# print(self.passwd)
73+
8674
# wait for password field
8775
passElement = WebDriverWait(self.driver, 60).until(
8876
EC.visibility_of_element_located((By.ID, "i0118"))
@@ -103,7 +91,7 @@ def login(
10391

10492
except Exception as e:
10593
self.driver.quit()
106-
logger.error(f"An error occurred while log in: {e}")
94+
logging.error(f"An error occurred: {e}")
10795
traceback.print_exc()
10896
sys.exit(1)
10997

@@ -120,23 +108,21 @@ def check_stop_signal(self):
120108
# Only update if the server's stop signal is True
121109
if stop_signal_from_server:
122110
self.stop_signal = True
123-
logger.info(
124-
"Stop signal received from the server. Exiting the loop."
125-
)
111+
print("Stop signal received from the server. Exiting the loop.")
126112
else:
127113

128-
logger.info("No stop signal received from the server. Continuing.")
114+
print("No stop signal received from the server. Continuing.")
129115
return self.stop_signal
130116
except Exception as e:
131-
logger.error(f"Error checking stop signal from server: {e}")
117+
print(f"Error checking stop signal: {e}")
132118

133119
def wait_for_element(self, xpathvalue):
134120
try:
135121
return WebDriverWait(self.driver, 60).until(
136122
EC.visibility_of_element_located((By.XPATH, xpathvalue))
137123
)
138124
except Exception as e:
139-
logger.error(f"Element not found: {xpathvalue}. Error: {e}")
125+
print(f"Element not found: {xpathvalue}. Error: {e}")
140126
return None
141127

142128
def get_meeting_link(self):
@@ -146,17 +132,15 @@ def get_meeting_link(self):
146132
data = response.json()
147133
self.meeting_link = data.get("meet_link")
148134
if not self.meeting_link:
149-
logger.error(
150-
"Meeting link not found in the response. Error fetching meet link"
151-
)
135+
logging.error("Meeting link not found in the response.")
152136
sys.exit(1)
153137
else:
154-
logger.error(
138+
logging.error(
155139
f"Failed to fetch meeting link. Status code: {response.status_code}"
156140
)
157141
sys.exit(1)
158142
except requests.RequestException as e:
159-
logger.error(f"Request error while getting meet link: {e}")
143+
logging.error(f"Request error: {e}")
160144
sys.exit(1)
161145

162146
def wait_for_element_with_time(self, xpathvalue, timeout=60):
@@ -165,7 +149,7 @@ def wait_for_element_with_time(self, xpathvalue, timeout=60):
165149
EC.visibility_of_element_located((By.XPATH, xpathvalue))
166150
)
167151
except Exception as e:
168-
logger.error(f"Element not found: {xpathvalue}. Error: {e}")
152+
print(f"Element not found: {xpathvalue}. Error: {e}")
169153
return None
170154

171155
def enterMetting(
@@ -216,7 +200,7 @@ def enterMetting(
216200

217201
except Exception as e:
218202
self.driver.quit()
219-
logger.error(f"An error occurred while entering the meeting: {e}")
203+
logging.error(f"An error occurred: {e}")
220204
traceback.print_exc()
221205
sys.exit(1)
222206

@@ -234,6 +218,9 @@ def network_stats(
234218
"//span[@data-tid='network-sent-bw-estimate']"
235219
).text
236220

221+
# print("=====================")
222+
# print(Teams_send_limit_value)
223+
237224
self.nw_recevie_limit = self.wait_for_element(
238225
"//span[@data-tid='network-received-bw-estimate']"
239226
).text
@@ -258,13 +245,13 @@ def network_stats(
258245
self.nw_rtt,
259246
self.nw_recevied_pkt_loss,
260247
]
261-
logger.debug(f"len of netstats data: {len(self.netstat_data)}")
248+
# print("len of netstats data",len(self.netstat_data))
262249

263250
return self.netstat_data
264251

265252
except Exception as e:
266253
self.driver.quit()
267-
logger.error(f"An error occurred while fetching network stats: {e}")
254+
logging.error(f"An error occurred: {e}")
268255
traceback.print_exc()
269256
sys.exit(1)
270257

@@ -273,6 +260,7 @@ def audio_stats(
273260
):
274261

275262
try:
263+
# print("audio")
276264
view_more = self.wait_for_element(
277265
"//button[@data-tid='call-health-category-Audio']"
278266
)
@@ -371,11 +359,14 @@ def audio_stats(
371359
"au_recv_codec": self.au_recv_codec,
372360
}
373361

362+
# print(audio_stats_data)
363+
print("checking au_recevied jitter")
364+
print(self.au_recv_jitter)
374365
return audio_stats_data
375366

376367
except Exception as e:
377368
self.driver.quit()
378-
logger.error(f"An error occurred while fetching audio stats: {e}")
369+
logging.error(f"An error occurred: {e}")
379370
traceback.print_exc()
380371
sys.exit(1)
381372

@@ -481,6 +472,8 @@ def video_stats(
481472
self.vi_sent_codec,
482473
self.vi_processing,
483474
]
475+
print("video stats data")
476+
print(video_stats_data)
484477

485478
video_stats_data = {
486479
"vi_sent_bitrate": self.vi_sent_bitrate,
@@ -496,7 +489,7 @@ def video_stats(
496489

497490
except Exception as e:
498491
self.driver.quit()
499-
logger.error(f"An error occurred while fetching video stats: {e}")
492+
logging.error(f"An error occurred: {e}")
500493
traceback.print_exc()
501494
sys.exit(1)
502495

@@ -509,11 +502,11 @@ def get_stats_flags(self):
509502
self.audio = data.get("audio_stats")
510503
self.video = data.get("video_stats")
511504
else:
512-
logger.error(
505+
print(
513506
f"Failed to fetch stats flag. Status code: {response.status_code}"
514507
)
515508
except requests.RequestException as e:
516-
logger.error(f"Request error while fetching stats flag: {e}")
509+
print(f"Request error: {e}")
517510
return None
518511

519512
def get_credentials(self):
@@ -526,11 +519,13 @@ def get_credentials(self):
526519
self.email = data["email"].strip()
527520
self.passwd = data["password"].strip()
528521
else:
529-
logger.error(f"❌ Failed to get credentials: {response.status_code}")
522+
logging.error(
523+
f"❌ Failed to get credentials: {response.json().get('log')}"
524+
)
530525
self.email = None
531526
self.passwd = None
532527
except requests.exceptions.RequestException as e:
533-
logger.error(f"❌ Error during credential request: {e}")
528+
logging.error(f"❌ Error during credential request: {e}")
534529
self.email = None
535530
self.passwd = None
536531

@@ -543,11 +538,11 @@ def get_start_and_end_time(self):
543538
self.start_time = data.get("start_time")
544539
self.end_time = data.get("end_time")
545540
else:
546-
logger.error(
547-
f"Failed to fetch Start and End time. Status code: {response.status_code}"
541+
print(
542+
f"Failed to fetch new login URL. Status code: {response.status_code}"
548543
)
549544
except requests.RequestException as e:
550-
logger.error(f"Request error while fetching Start and End time: {e}")
545+
print(f"Request error: {e}")
551546
return None
552547

553548
def send_stats_to_server(self, hostname, audio_stats, video_stats):
@@ -577,35 +572,38 @@ def send_stats_to_server(self, hostname, audio_stats, video_stats):
577572
try:
578573
response = requests.post(f"{self.base_url}/upload_stats", json=payload)
579574
if response.status_code == 200:
580-
logger.debug(f"Stats uploaded for {hostname}")
575+
print(f"Stats uploaded for {hostname}")
581576
else:
582-
logger.error(
577+
print(
583578
f"Failed to upload stats: {response.status_code} - {response.text}"
584579
)
585580
except Exception as e:
586-
logger.error(f"Exception during upload stats: {e}")
587-
581+
print(f"Exception during upload: {e}")
582+
588583
def update_participation(self):
589584

590585
endpoint_url = f"{self.base_url}/set_participants_joined"
591586
try:
592587
response = requests.get(endpoint_url)
593588
if response.status_code == 200:
594-
logger.info("Device participation status updated successfully.")
589+
print("Device participation status updated successfully.")
595590
else:
596-
logger.error(
591+
print(
597592
f"Failed to update device participation status. Status code: {response.status_code}"
598593
)
599594
except requests.RequestException as e:
600-
logger.error(f"Request error while updating participation: {e}")
595+
print(f"Request error: {e}")
601596

602597

603598
def main():
604-
team = None
605599

606600
try:
607601

608602
hostname = socket.gethostname()
603+
604+
# netstats_header=['Teams Network Send Limit(Mbps)','Teams Network Receive Limit(Mbps)','Network Received Round Trip Time(ms)','Network Received Packet Loss(%)']
605+
# print("leng of netstat header",len(netstats_header))
606+
609607
parser = argparse.ArgumentParser(description="Teams Automation")
610608
parser.add_argument("--ip", required=True, help="Server endpoint ip")
611609
parser.add_argument("--env", action="extend", nargs="+", default=[])
@@ -614,6 +612,7 @@ def main():
614612
for argument in args.env:
615613
arg = argument.split("=")
616614
os.environ[arg[0]] = arg[1]
615+
print(os.environ)
617616

618617
team = TeamsClient(server_ip=args.ip)
619618
team.get_meeting_link()
@@ -628,13 +627,13 @@ def main():
628627
time.sleep(2)
629628
while team.start_time > datetime.now(team.tz).isoformat():
630629
time.sleep(2)
631-
logger.info("waiting for the start time of the test")
630+
print("waiting for the start time")
632631

633632
while team.end_time > datetime.now(team.tz).isoformat():
634-
logger.info("monitoring the test")
633+
print("monitoring the test")
635634
team.check_stop_signal()
636635
if team.stop_signal:
637-
logger.info("Stop signal received from server. Exiting the loop.")
636+
print("Stop signal received. Exiting the loop.")
638637
break
639638
if team.audio:
640639
audio_stats = team.audio_stats()
@@ -648,13 +647,13 @@ def main():
648647
team.send_stats_to_server(hostname, None, video_stats)
649648
time.sleep(1)
650649

650+
team.driver.quit()
651+
651652
except Exception as e:
652-
logger.error(f"An error occurred: {e}")
653+
team.driver.quit()
654+
logging.error(f"An error occurred: {e}")
653655
traceback.print_exc()
654656
sys.exit(1)
655-
finally:
656-
if team and team.driver:
657-
team.driver.quit()
658657

659658

660659
if __name__ == "__main__":

0 commit comments

Comments
 (0)