Spaces:
Build error
Build error
Update critical_functionality.py
Browse files- critical_functionality.py +41 -19
critical_functionality.py
CHANGED
|
@@ -1,31 +1,53 @@
|
|
| 1 |
def test_critical_functionality(url):
|
| 2 |
"""
|
| 3 |
-
|
| 4 |
Args:
|
| 5 |
-
url (str): The URL to
|
| 6 |
Returns:
|
| 7 |
-
|
| 8 |
"""
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
driver.get(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
return {"status": "Pass", "details": "Critical functionalities passed."}
|
| 28 |
|
| 29 |
-
except Exception as e:
|
| 30 |
-
return {"status": "Fail", "details": str(e)}
|
| 31 |
|
|
|
|
| 1 |
def test_critical_functionality(url):
|
| 2 |
"""
|
| 3 |
+
Generate Selenium test code snippets for a given URL.
|
| 4 |
Args:
|
| 5 |
+
url (str): The URL to be tested.
|
| 6 |
Returns:
|
| 7 |
+
str: The generated test code as a string.
|
| 8 |
"""
|
| 9 |
+
site_name = url.split("//")[-1].split("/")[0] # Extract the domain name
|
| 10 |
+
test_code = f"""
|
| 11 |
+
import unittest
|
| 12 |
+
from selenium import webdriver
|
| 13 |
+
|
| 14 |
+
class {site_name.capitalize()}Test(unittest.TestCase):
|
| 15 |
+
|
| 16 |
+
def setUp(self):
|
| 17 |
+
self.driver = webdriver.Chrome()
|
| 18 |
|
| 19 |
+
def test_search_product(self):
|
| 20 |
+
self.driver.get('{url}')
|
| 21 |
+
search_box = self.driver.find_element_by_id('twotabsearchtextbox')
|
| 22 |
+
search_box.send_keys('Python programming')
|
| 23 |
+
search_box.submit()
|
| 24 |
+
search_results = self.driver.find_elements_by_class_name('a-link-normal')
|
| 25 |
+
self.assertGreater(len(search_results), 0)
|
| 26 |
|
| 27 |
+
def test_add_to_cart(self):
|
| 28 |
+
self.driver.get('{url}/dp/B08N6Z2L2D')
|
| 29 |
+
add_to_cart_button = self.driver.find_element_by_class_name('a-button-text')
|
| 30 |
+
add_to_cart_button.click()
|
| 31 |
+
cart_count = self.driver.find_element_by_class_name('nav-cart-count').text
|
| 32 |
+
self.assertEqual(cart_count, '1')
|
| 33 |
|
| 34 |
+
def tearDown(self):
|
| 35 |
+
self.driver.close()
|
| 36 |
|
| 37 |
+
if __name__ == '__main__':
|
| 38 |
+
unittest.main()
|
| 39 |
+
"""
|
| 40 |
+
return test_code
|
| 41 |
+
|
| 42 |
+
def test_critical_functionality(url):
|
| 43 |
+
"""
|
| 44 |
+
Function to generate and display the critical functionality test snippet for the given URL.
|
| 45 |
+
Args:
|
| 46 |
+
url (str): The URL to test.
|
| 47 |
+
"""
|
| 48 |
+
st.subheader("Generated Critical Functionality Test Code")
|
| 49 |
+
test_code = generate_test_snippet(url)
|
| 50 |
+
st.code(test_code, language='python')
|
| 51 |
|
|
|
|
| 52 |
|
|
|
|
|
|
|
| 53 |
|