Ashar086 commited on
Commit
c7d9b8d
·
verified ·
1 Parent(s): f9d310d

Update performance_testing.py

Browse files
Files changed (1) hide show
  1. performance_testing.py +15 -9
performance_testing.py CHANGED
@@ -8,13 +8,20 @@ def perform_performance_test(url):
8
  Returns:
9
  str: Performance test code snippet.
10
  """
11
- # Extract base domain from URL (you may need a more robust method)
12
- base_domain = url.split('/')[2]
13
-
 
 
 
 
 
 
 
14
  snippet = f"""
15
  import unittest
16
  from selenium import webdriver
17
- from locust import HttpLocust, TaskSet, task
18
 
19
  class PerformanceTests(TaskSet):
20
 
@@ -33,9 +40,8 @@ class PerformanceTests(TaskSet):
33
  cart_count = self.client.find_element_by_class_name('cart-count-class').text # Update with actual class
34
  self.assertEqual(cart_count, '1')
35
 
36
- class LocustTest(HttpLocust):
37
- task_set = PerformanceTests
38
- min_wait = 5000
39
- max_wait = 15000
40
  """
41
- return snippet
 
8
  Returns:
9
  str: Performance test code snippet.
10
  """
11
+ # Ensure URL is properly formatted
12
+ if not url.startswith("http://") and not url.startswith("https://"):
13
+ raise ValueError("Invalid URL format. URL must start with 'http://' or 'https://'.")
14
+
15
+ # Extract base domain from URL
16
+ try:
17
+ base_domain = url.split('/')[2]
18
+ except IndexError:
19
+ raise ValueError("URL does not contain enough segments to extract base domain.")
20
+
21
  snippet = f"""
22
  import unittest
23
  from selenium import webdriver
24
+ from locust import HttpUser, TaskSet, task
25
 
26
  class PerformanceTests(TaskSet):
27
 
 
40
  cart_count = self.client.find_element_by_class_name('cart-count-class').text # Update with actual class
41
  self.assertEqual(cart_count, '1')
42
 
43
+ class LocustTest(HttpUser):
44
+ tasks = [PerformanceTests]
45
+ wait_time = between(5, 15)
 
46
  """
47
+ return snippet