Spaces:
Build error
Build error
Update performance_testing.py
Browse files- 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 |
-
#
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
snippet = f"""
|
| 15 |
import unittest
|
| 16 |
from selenium import webdriver
|
| 17 |
-
from locust import
|
| 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(
|
| 37 |
-
|
| 38 |
-
|
| 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
|