forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoke_test.py
132 lines (113 loc) · 5.51 KB
/
smoke_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest
import re
import os
import sys
class DojoTests(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome('chromedriver')
self.driver.implicitly_wait(30)
self.base_url = "http://localhost:8000/"
self.verificationErrors = []
self.accept_next_alert = True
def login_page(self):
driver = self.driver
driver.get(self.base_url + "login")
driver.find_element_by_id("id_username").clear()
driver.find_element_by_id("id_username").send_keys(os.environ['DD_ADMIN_USER'])
driver.find_element_by_id("id_password").clear()
driver.find_element_by_id("id_password").send_keys(os.environ['DD_ADMIN_PASSWORD'])
driver.find_element_by_css_selector("button.btn.btn-success").click()
return driver
def test_login(self):
driver = self.login_page()
loginTxt = driver.find_element_by_tag_name("BODY").text
self.assertTrue(re.search(r'Active Engagements', loginTxt))
def test_create_product(self):
driver = self.login_page()
driver.get(self.base_url + "product")
driver.find_element_by_id("dropdownMenu1").click()
driver.find_element_by_link_text("Add Product").click()
driver.find_element_by_id("id_name").clear()
driver.find_element_by_id("id_name").send_keys("QA Test")
driver.find_element_by_id("id_description").clear()
driver.find_element_by_id("id_description").send_keys("QA Test 1 Description")
Select(driver.find_element_by_id("id_prod_type")).select_by_visible_text("Research and Development")
driver.find_element_by_css_selector("input.btn.btn-primary").click()
productTxt = driver.find_element_by_tag_name("BODY").text
self.assertTrue(re.search(r'Product added successfully', productTxt))
def test_engagement(self):
driver = self.login_page()
driver = self.driver
driver.get(self.base_url + "product")
driver.find_element_by_link_text("Product List").click()
driver.find_element_by_xpath("//table[@id='products']/tbody/tr[1]/td[5]/a").click()
driver.find_element_by_id("id_pen_test").click()
driver.find_element_by_id("id_check_list").click()
driver.find_element_by_id("id_name").clear()
driver.find_element_by_id("id_name").send_keys("New QA Engagement")
driver.find_element_by_id("id_target_start").clear()
driver.find_element_by_id("id_target_start").send_keys("2016-09-01")
driver.find_element_by_id("id_name").click()
driver.find_element_by_id("id_target_end").click()
driver.find_element_by_id("id_target_end").send_keys("2016-09-02")
driver.find_element_by_link_text("15").click()
Select(driver.find_element_by_id("id_lead")).select_by_value("1")
driver.find_element_by_css_selector("input[name=\"_Add Tests\"]").click()
Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Pen Test")
driver.find_element_by_id("id_target_start").clear()
driver.find_element_by_id("id_target_start").send_keys("2016-09-01")
driver.find_element_by_id("id_target_end").click()
driver.find_element_by_link_text("22").click()
Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")
driver.find_element_by_id("id_percent_complete").clear()
driver.find_element_by_id("id_percent_complete").send_keys("50")
driver.find_element_by_css_selector("input[name=\"_Add Findings\"]").click()
driver.find_element_by_id("id_title").clear()
driver.find_element_by_id("id_title").send_keys("Test Finding")
driver.find_element_by_id("id_description").clear()
driver.find_element_by_id("id_description").send_keys("Description")
driver.find_element_by_id("id_mitigation").clear()
driver.find_element_by_id("id_mitigation").send_keys("Mitigation")
driver.find_element_by_id("id_impact").clear()
driver.find_element_by_id("id_impact").send_keys("Impact")
driver.find_element_by_name("_Finished").click()
findingTxt = driver.find_element_by_tag_name("BODY").text
self.assertTrue(re.search(r'Finding added successfully', findingTxt))
def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what)
except NoSuchElementException as e:
return False
return True
def is_alert_present(self):
try:
self.driver.switch_to_alert()
except NoAlertPresentException as e:
return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally:
self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
def suite():
suite = unittest.TestSuite()
suite.addTest(DojoTests('test_login'))
return suite
if __name__ == "__main__":
runner = unittest.TextTestRunner(descriptions=True, failfast=True)
ret = not runner.run(suite()).wasSuccessful()
sys.exit(ret)