How to use driver method in molecule

Best Python code snippet using molecule_python

dedupe_unit_test.py

Source:dedupe_unit_test.py Github

copy

Full Screen

1from selenium.webdriver.support.ui import Select2from selenium.webdriver.support.ui import WebDriverWait3from selenium.webdriver.support import expected_conditions as EC4from selenium.common.exceptions import TimeoutException5import unittest6import sys7import os8from base_test_class import BaseTestCase, on_exception_html_source_logger9from Product_unit_test import ProductTest10import time11dir_path = os.path.dirname(os.path.realpath(__file__))12class DedupeTest(BaseTestCase):13 # --------------------------------------------------------------------------------------------------------14 # Initialization15 # --------------------------------------------------------------------------------------------------------16 def setUp(self):17 super().setUp()18 self.relative_path = dir_path = os.path.dirname(os.path.realpath(__file__))19 def check_nb_duplicates(self, expected_number_of_duplicates):20 print("checking duplicates...")21 retries = 022 for i in range(0, 18):23 time.sleep(5) # wait bit for celery dedupe task which can be slow on travis24 driver = self.login_page()25 self.goto_all_findings_list(driver)26 dupe_count = 027 # iterate over the rows of the findings table and concatenates all columns into td.text28 trs = driver.find_elements_by_xpath('//*[@id="open_findings"]/tbody/tr')29 for row in trs:30 concatRow = ' '.join([td.text for td in row.find_elements_by_xpath(".//td")])31 # print(concatRow)32 if '(DUPE)' and 'Duplicate' in concatRow:33 dupe_count += 134 if (dupe_count != expected_number_of_duplicates):35 print("duplicate count mismatch, let's wait a bit for the celery dedupe task to finish and try again (5s)")36 else:37 break38 if (dupe_count != expected_number_of_duplicates):39 findings_table = driver.find_element_by_id('open_findings')40 print(findings_table.get_attribute('innerHTML'))41 self.assertEqual(dupe_count, expected_number_of_duplicates)42 @on_exception_html_source_logger43 def test_enable_deduplication(self):44 print("enabling deduplication...")45 driver = self.login_page()46 driver.get(self.base_url + 'system_settings')47 if not driver.find_element_by_id('id_enable_deduplication').is_selected():48 driver.find_element_by_xpath('//*[@id="id_enable_deduplication"]').click()49 # save settings50 driver.find_element_by_css_selector("input.btn.btn-primary").click()51 # check if it's enabled after reload52 driver.get(self.base_url + 'system_settings')53 self.assertTrue(driver.find_element_by_id('id_enable_deduplication').is_selected())54 @on_exception_html_source_logger55 def test_delete_findings(self):56 print("removing previous findings...")57 driver = self.login_page()58 driver.get(self.base_url + "finding?page=1")59 if self.element_exists_by_id("no_findings"):60 text = driver.find_element_by_id("no_findings").text61 if 'No findings found.' in text:62 return63 driver.find_element_by_id("select_all").click()64 driver.find_element_by_css_selector("i.fa.fa-trash").click()65 try:66 WebDriverWait(driver, 1).until(EC.alert_is_present(),67 'Timed out waiting for PA creation ' +68 'confirmation popup to appear.')69 driver.switch_to.alert.accept()70 except TimeoutException:71 self.fail('Confirmation dialogue not shown, cannot delete previous findings')72 text = None73 if self.element_exists_by_id("no_findings"):74 text = driver.find_element_by_id("no_findings").text75 self.assertTrue('No findings found.' in text)76 # check that user was redirect back to url where it came from based on return_url77 self.assertTrue(driver.current_url.endswith('page=1'))78# --------------------------------------------------------------------------------------------------------79# Same scanner deduplication - Deduplication on engagement80# Test deduplication for Bandit SAST scanner81# --------------------------------------------------------------------------------------------------------82 @on_exception_html_source_logger # noqa: E30183 def test_add_path_test_suite(self):84 print("Same scanner deduplication - Deduplication on engagement - static. Creating tests...")85 # Create engagement86 driver = self.login_page()87 self.goto_product_overview(driver)88 driver.find_element_by_class_name("pull-left").click()89 driver.find_element_by_link_text("Add New Engagement").click()90 driver.find_element_by_id("id_name").send_keys("Dedupe Path Test")91 driver.find_element_by_xpath('//*[@id="id_deduplication_on_engagement"]').click()92 driver.find_element_by_name("_Add Tests").click()93 self.assertTrue(self.is_success_message_present(text='Engagement added successfully.'))94 # Add the tests95 # Test 196 driver.find_element_by_id("id_title").send_keys("Path Test 1")97 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Bandit Scan")98 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")99 driver.find_element_by_name("_Add Another Test").click()100 self.assertTrue(self.is_success_message_present(text='Test added successfully'))101 # Test 2102 driver.find_element_by_id("id_title").send_keys("Path Test 2")103 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Bandit Scan")104 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")105 driver.find_element_by_css_selector("input.btn.btn-primary").click()106 self.assertTrue(self.is_success_message_present(text='Test added successfully'))107 @on_exception_html_source_logger108 def test_import_path_tests(self):109 print("importing reports...")110 # First test111 driver = self.login_page()112 self.goto_active_engagements_overview(driver)113 driver.find_element_by_partial_link_text("Dedupe Path Test").click()114 driver.find_element_by_partial_link_text("Path Test 1").click()115 driver.find_element_by_id("dropdownMenu1").click()116 driver.find_element_by_link_text("Re-Upload Scan").click()117 # active and verified:118 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()119 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()120 driver.find_element_by_id('id_file').send_keys(self.relative_path + "/dedupe_scans/dedupe_path_1.json")121 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()122 self.assertTrue(self.is_success_message_present(text='a total of 3 findings were processed'))123 # Second test124 self.goto_active_engagements_overview(driver)125 driver.find_element_by_partial_link_text("Dedupe Path Test").click()126 driver.find_element_by_partial_link_text("Path Test 2").click()127 driver.find_element_by_id("dropdownMenu1").click()128 driver.find_element_by_link_text("Re-Upload Scan").click()129 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()130 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()131 driver.find_element_by_id('id_file').send_keys(self.relative_path + "/dedupe_scans/dedupe_path_2.json")132 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()133 self.assertTrue(self.is_success_message_present(text='a total of 3 findings were processed'))134 @on_exception_html_source_logger135 def test_check_path_status(self):136 # comparing tests/dedupe_scans/dedupe_path_1.json and tests/dedupe_scans/dedupe_path_2.json137 # Counts the findings that have on the same line "(DUPE)" (in the title) and "Duplicate" (marked as duplicate by DD)138 # We have imported 3 findings twice, but one only is a duplicate because for the 2 others, we have changed either the line number or the file_path139 self.check_nb_duplicates(1)140# --------------------------------------------------------------------------------------------------------141# Same scanner deduplication - Deduplication on engagement142# Test deduplication for Immuniweb dynamic scanner143# --------------------------------------------------------------------------------------------------------144 @on_exception_html_source_logger145 def test_add_endpoint_test_suite(self):146 print("Same scanner deduplication - Deduplication on engagement - dynamic. Creating tests...")147 # Create engagement148 driver = self.login_page()149 self.goto_product_overview(driver)150 driver.find_element_by_class_name("pull-left").click()151 driver.find_element_by_link_text("Add New Engagement").click()152 driver.find_element_by_id("id_name").send_keys("Dedupe Endpoint Test")153 driver.find_element_by_xpath('//*[@id="id_deduplication_on_engagement"]').click()154 driver.find_element_by_name("_Add Tests").click()155 self.assertTrue(self.is_success_message_present(text='Engagement added successfully.'))156 # Add the tests157 # Test 1158 driver.find_element_by_id("id_title").send_keys("Endpoint Test 1")159 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Immuniweb Scan")160 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")161 driver.find_element_by_name("_Add Another Test").click()162 self.assertTrue(self.is_success_message_present(text='Test added successfully'))163 # Test 2164 driver.find_element_by_id("id_title").send_keys("Endpoint Test 2")165 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Immuniweb Scan")166 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")167 driver.find_element_by_css_selector("input.btn.btn-primary").click()168 self.assertTrue(self.is_success_message_present(text='Test added successfully'))169 @on_exception_html_source_logger170 def test_import_endpoint_tests(self):171 print("Importing reports...")172 # First test : Immuniweb Scan (dynamic)173 driver = self.login_page()174 self.goto_active_engagements_overview(driver)175 driver.find_element_by_partial_link_text("Dedupe Endpoint Test").click()176 driver.find_element_by_partial_link_text("Endpoint Test 1").click()177 driver.find_element_by_id("dropdownMenu1").click()178 driver.find_element_by_link_text("Re-Upload Scan").click()179 # active and verified180 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()181 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()182 driver.find_element_by_id('id_file').send_keys(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml")183 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()184 self.assertTrue(self.is_success_message_present(text='a total of 3 findings were processed'))185 # Second test : Immuniweb Scan (dynamic)186 self.goto_active_engagements_overview(driver)187 driver.find_element_by_partial_link_text("Dedupe Endpoint Test").click()188 driver.find_element_by_partial_link_text("Endpoint Test 2").click()189 driver.find_element_by_id("dropdownMenu1").click()190 driver.find_element_by_link_text("Re-Upload Scan").click()191 # active and verified192 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()193 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()194 driver.find_element_by_id('id_file').send_keys(self.relative_path + "/dedupe_scans/dedupe_endpoint_2.xml")195 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()196 self.assertTrue(self.is_success_message_present(text='a total of 3 findings were processed'))197 @on_exception_html_source_logger198 def test_check_endpoint_status(self):199 # comparing dedupe_endpoint_1.xml and dedupe_endpoint_2.xml200 # Counts the findings that have on the same line "(DUPE)" (in the title) and "Duplicate" (marked as duplicate by DD)201 # We have imported 3 findings twice, but one only is a duplicate because for the 2 others, we have changed either (the URL) or (the name and cwe)202 self.check_nb_duplicates(1)203 @on_exception_html_source_logger204 def test_add_same_eng_test_suite(self):205 print("Test different scanners - same engagement - dynamic; Adding tests on the same engagement...")206 # Create engagement207 driver = self.login_page()208 self.goto_product_overview(driver)209 driver.find_element_by_class_name("pull-left").click()210 driver.find_element_by_link_text("Add New Engagement").click()211 driver.find_element_by_id("id_name").send_keys("Dedupe Same Eng Test")212 driver.find_element_by_xpath('//*[@id="id_deduplication_on_engagement"]').click()213 driver.find_element_by_name("_Add Tests").click()214 self.assertTrue(self.is_success_message_present(text='Engagement added successfully.'))215 # Add the tests216 # Test 1217 driver.find_element_by_id("id_title").send_keys("Same Eng Test 1")218 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Immuniweb Scan")219 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")220 driver.find_element_by_name("_Add Another Test").click()221 self.assertTrue(self.is_success_message_present(text='Test added successfully'))222 # Test 2223 driver.find_element_by_id("id_title").send_keys("Same Eng Test 2")224 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Generic Findings Import")225 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")226 driver.find_element_by_css_selector("input.btn.btn-primary").click()227 self.assertTrue(self.is_success_message_present(text='Test added successfully'))228 @on_exception_html_source_logger229 def test_import_same_eng_tests(self):230 print("Importing reports")231 # First test : Immuniweb Scan (dynamic)232 driver = self.login_page()233 self.goto_active_engagements_overview(driver)234 driver.find_element_by_partial_link_text("Dedupe Same Eng Test").click()235 driver.find_element_by_partial_link_text("Same Eng Test 1").click()236 driver.find_element_by_id("dropdownMenu1").click()237 driver.find_element_by_link_text("Re-Upload Scan").click()238 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()239 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()240 driver.find_element_by_id('id_file').send_keys(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml")241 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()242 self.assertTrue(self.is_success_message_present(text='a total of 3 findings were processed'))243 # Second test : Generic Findings Import with Url (dynamic)244 self.goto_active_engagements_overview(driver)245 driver.find_element_by_partial_link_text("Dedupe Same Eng Test").click()246 driver.find_element_by_partial_link_text("Same Eng Test 2").click()247 driver.find_element_by_id("dropdownMenu1").click()248 driver.find_element_by_link_text("Re-Upload Scan").click()249 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()250 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()251 driver.find_element_by_id('id_file').send_keys(self.relative_path + "/dedupe_scans/dedupe_cross_1.csv")252 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()253 self.assertTrue(self.is_success_message_present(text='a total of 3 findings were processed'))254 @on_exception_html_source_logger255 def test_check_same_eng_status(self):256 # comparing dedupe_endpoint_1.xml and dedupe_endpoint_2.xml257 # Counts the findings that have on the same line "(DUPE)" (in the title) and "Duplicate" (marked as duplicate by DD)258 # We have imported 3 findings twice, but one only is a duplicate because for the 2 others, we have changed either (the URL) or (the name and cwe)259 self.check_nb_duplicates(1)260# --------------------------------------------------------------------------------------------------------261# Same scanner deduplication - Deduplication on engagement262# Test deduplication for Checkmarx SAST Scan with custom hash_code computation263# Upon import, Checkmarx Scan aggregates on : categories, cwe, name, sinkFilename264# That test shows that the custom hash_code (excluding line number, see settings.py)265# makes it possible to detect the duplicate even if the line number has changed (which will occur in a normal software lifecycle)266# --------------------------------------------------------------------------------------------------------267 def test_add_path_test_suite_checkmarx_scan(self):268 print("Same scanner deduplication - Deduplication on engagement. Test dedupe on checkmarx aggregated with custom hash_code computation")269 # Create engagement270 driver = self.login_page()271 self.goto_product_overview(driver)272 driver.find_element_by_class_name("pull-left").click()273 driver.find_element_by_link_text("Add New Engagement").click()274 driver.find_element_by_id("id_name").send_keys("Dedupe on hash_code only")275 driver.find_element_by_xpath('//*[@id="id_deduplication_on_engagement"]').click()276 driver.find_element_by_name("_Add Tests").click()277 self.assertTrue(self.is_success_message_present(text='Engagement added successfully.'))278 # Add the tests279 # Test 1280 driver.find_element_by_id("id_title").send_keys("Path Test 1")281 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Checkmarx Scan")282 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")283 driver.find_element_by_name("_Add Another Test").click()284 self.assertTrue(self.is_success_message_present(text='Test added successfully'))285 # Test 2286 driver.find_element_by_id("id_title").send_keys("Path Test 2")287 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Checkmarx Scan")288 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")289 driver.find_element_by_css_selector("input.btn.btn-primary").click()290 self.assertTrue(self.is_success_message_present(text='Test added successfully'))291 def test_import_path_tests_checkmarx_scan(self):292 # First test293 driver = self.login_page()294 self.goto_active_engagements_overview(driver)295 driver.find_element_by_partial_link_text("Dedupe on hash_code only").click()296 driver.find_element_by_partial_link_text("Path Test 1").click()297 driver.find_element_by_id("dropdownMenu1").click()298 driver.find_element_by_link_text("Re-Upload Scan").click()299 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()300 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()301 # os.path.realpath makes the path canonical302 driver.find_element_by_id('id_file').send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/multiple_findings.xml"))303 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()304 self.assertTrue(self.is_success_message_present(text='a total of 2 findings were processed'))305 # Second test306 self.goto_active_engagements_overview(driver)307 driver.find_element_by_partial_link_text("Dedupe on hash_code only").click()308 driver.find_element_by_partial_link_text("Path Test 2").click()309 driver.find_element_by_id("dropdownMenu1").click()310 driver.find_element_by_link_text("Re-Upload Scan").click()311 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()312 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()313 driver.find_element_by_id('id_file').send_keys(os.path.realpath(self.relative_path + "/dedupe_scans/multiple_findings_line_changed.xml"))314 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()315 self.assertTrue(self.is_success_message_present(text='a total of 2 findings were processed'))316 def test_check_path_status_checkmarx_scan(self):317 # After aggregation, it's only two findings. Both are duplicates even though the line number has changed318 # because we ignore the line number when computing the hash_code for this scanner319 # (so that findings keep being found as duplicate even if the code changes slightly)320 self.check_nb_duplicates(2)321# --------------------------------------------------------------------------------------------------------322# Cross scanners deduplication - product-wide deduplication323# Test deduplication for Generic Findings Import with URL (dynamic) vs Immuniweb dynamic scanner324# --------------------------------------------------------------------------------------------------------325 def test_add_cross_test_suite(self):326 print("Cross scanners deduplication dynamic; generic finding vs immuniweb. Creating tests...")327 # Create generic engagement328 driver = self.login_page()329 self.goto_product_overview(driver)330 driver.find_element_by_class_name("pull-left").click()331 driver.find_element_by_link_text("Add New Engagement").click()332 driver.find_element_by_id("id_name").send_keys("Dedupe Generic Test")333 # driver.find_element_by_xpath('//*[@id="id_deduplication_on_engagement"]').click()334 driver.find_element_by_name("_Add Tests").click()335 self.assertTrue(self.is_success_message_present(text='Engagement added successfully.'))336 # Test337 driver.find_element_by_id("id_title").send_keys("Generic Test")338 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Generic Findings Import")339 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")340 driver.find_element_by_css_selector("input.btn.btn-primary").click()341 self.assertTrue(self.is_success_message_present(text='Test added successfully'))342 # Create immuniweb engagement343 self.goto_product_overview(driver)344 driver.find_element_by_class_name("pull-left").click()345 driver.find_element_by_link_text("Add New Engagement").click()346 driver.find_element_by_id("id_name").send_keys("Dedupe Immuniweb Test")347 # driver.find_element_by_xpath('//*[@id="id_deduplication_on_engagement"]').click()348 driver.find_element_by_name("_Add Tests").click()349 self.assertTrue(self.is_success_message_present(text='Engagement added successfully.'))350 # Test351 driver.find_element_by_id("id_title").send_keys("Immuniweb Test")352 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Immuniweb Scan")353 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")354 driver.find_element_by_css_selector("input.btn.btn-primary").click()355 self.assertTrue(self.is_success_message_present(text='Test added successfully'))356 def test_import_cross_test(self):357 print("Importing findings...")358 # First test : Immuniweb Scan (dynamic)359 driver = self.login_page()360 self.goto_active_engagements_overview(driver)361 driver.find_element_by_partial_link_text("Dedupe Immuniweb Test").click()362 driver.find_element_by_partial_link_text("Immuniweb Test").click()363 driver.find_element_by_css_selector("b.fa.fa-ellipsis-v").click()364 driver.find_element_by_link_text("Re-Upload Scan Results").click()365 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()366 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()367 driver.find_element_by_id('id_file').send_keys(self.relative_path + "/dedupe_scans/dedupe_endpoint_1.xml")368 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()369 self.assertTrue(self.is_success_message_present(text='a total of 3 findings were processed'))370 # Second test : generic scan with url (dynamic)371 self.goto_active_engagements_overview(driver)372 driver.find_element_by_partial_link_text("Dedupe Generic Test").click()373 driver.find_element_by_partial_link_text("Generic Test").click()374 driver.find_element_by_css_selector("b.fa.fa-ellipsis-v").click()375 driver.find_element_by_link_text("Re-Upload Scan Results").click()376 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[3]/div/div').click()377 driver.find_element_by_xpath('//*[@id="base-content"]/form/div[4]/div/div').click()378 driver.find_element_by_id('id_file').send_keys(self.relative_path + "/dedupe_scans/dedupe_cross_1.csv")379 driver.find_elements_by_css_selector("button.btn.btn-primary")[1].click()380 self.assertTrue(self.is_success_message_present(text='a total of 3 findings were processed'))381 def test_check_cross_status(self):382 self.check_nb_duplicates(1)383def add_dedupe_tests_to_suite(suite):384 suite.addTest(ProductTest('test_create_product'))385 suite.addTest(DedupeTest('test_enable_deduplication'))386 # Test same scanners - same engagement - static - dedupe387 suite.addTest(DedupeTest('test_delete_findings'))388 suite.addTest(DedupeTest('test_add_path_test_suite'))389 suite.addTest(DedupeTest('test_import_path_tests'))390 suite.addTest(DedupeTest('test_check_path_status'))391 # Test same scanners - same engagement - dynamic - dedupe392 suite.addTest(DedupeTest('test_delete_findings'))393 suite.addTest(DedupeTest('test_add_endpoint_test_suite'))394 suite.addTest(DedupeTest('test_import_endpoint_tests'))395 suite.addTest(DedupeTest('test_check_endpoint_status'))396 # Test different scanners - same engagement - dynamic - dedupe397 suite.addTest(DedupeTest('test_delete_findings'))398 suite.addTest(DedupeTest('test_add_same_eng_test_suite'))399 suite.addTest(DedupeTest('test_import_same_eng_tests'))400 suite.addTest(DedupeTest('test_check_same_eng_status'))401 # Test same scanners - same engagement - static - dedupe with custom hash_code402 suite.addTest(DedupeTest('test_delete_findings'))403 suite.addTest(DedupeTest('test_add_path_test_suite_checkmarx_scan'))404 suite.addTest(DedupeTest('test_import_path_tests_checkmarx_scan'))405 suite.addTest(DedupeTest('test_check_path_status_checkmarx_scan'))406 # Test different scanners - different engagement - dynamic - dedupe407 suite.addTest(DedupeTest('test_delete_findings'))408 suite.addTest(DedupeTest('test_add_cross_test_suite'))409 suite.addTest(DedupeTest('test_import_cross_test'))410 suite.addTest(DedupeTest('test_check_cross_status'))411 # Clean up412 suite.addTest(ProductTest('test_delete_product'))413 return suite414def suite():415 suite = unittest.TestSuite()416 add_dedupe_tests_to_suite(suite)417 suite.addTest(DedupeTest('enable_jira'))418 suite.addTest(DedupeTest('enable_github'))419 suite.addTest(DedupeTest('enable_block_execution'))420 add_dedupe_tests_to_suite(suite)421 return suite422if __name__ == "__main__":423 runner = unittest.TextTestRunner(descriptions=True, failfast=True, verbosity=2)424 ret = not runner.run(suite()).wasSuccessful()425 BaseTestCase.tearDownDriver()...

Full Screen

Full Screen

dialysis_aut.py

Source:dialysis_aut.py Github

copy

Full Screen

1import os2from selenium import webdriver3from time import sleep4from selenium.webdriver import ActionChains5from selenium.webdriver.chrome.options import Options6from selenium.webdriver.support.ui import Select7from selenium.webdriver.support import expected_conditions as EC8from selenium.webdriver.common.by import By9from selenium.webdriver.support import expected_conditions10from selenium.webdriver.support.wait import WebDriverWait11from selenium.webdriver.common.keys import Keys12from selenium.common.exceptions import NoSuchElementException13from webdriver_manager.chrome import ChromeDriverManager14import urllib15import urllib.request16# functions17def check_exists_by_xpath(xpath):18 try:19 driver.find_element_by_xpath(xpath)20 except NoSuchElementException:21 return False22 return True23def check_exists_by_id(id):24 try:25 driver.find_element_by_id(id)26 except NoSuchElementException:27 return False28 return True29options = webdriver.ChromeOptions()30options.add_argument('--disable-notifications')31driver = webdriver.Chrome(ChromeDriverManager().install(),options=options)32driver.maximize_window()33driver.implicitly_wait(10)34w = WebDriverWait(driver,8)35# user = input('enter email or phone no')36# pswd = input('enter password')37driver.get('https://pmjaylive.sevensigma.in/home')38user_name = driver.find_element_by_name('User Name')39user_name.send_keys(8590050640)40password = driver.find_element_by_name('Password')41password.send_keys(50640)42driver.find_element_by_xpath('/html/body/div/div[2]/div/div/div[1]/div/div/form/div/div[3]/button').click()43sleep(3)44view_list = driver.find_element_by_xpath('//*[@id="out-table"]/div/div/div[4]/div/div[4]/div[2]/table/tbody/tr/td[5]/div/button[1]')45view_list.click()46sleep(3)47preauth = driver.find_element_by_xpath('/html/body/div/div[2]/div[2]/div/div/div[2]/div[2]/a/div/div[1]/div/div[2]/div/p[1]').click()48sleep(3)49driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div/div/div[1]/div/div[1]/div/div[2]/div/div/div[6]/div/div/div/div/div/div/input').send_keys('DIALYSIS')50sleep(10)51dialysis = driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/ul/li[1]/span')52dialysis.click()53sleep(3)54number_of_rows= len(driver.find_elements_by_xpath('//*[@id="out-table"]/div[1]/div/div[4]/div'))55print(number_of_rows)56id_list=[]# list creation57for i in range(1,number_of_rows+1):58 u=driver.find_elements_by_xpath("//*[@id='out-table']/div[1]/div/div[4]/div/div[3]/table/tbody/tr[' + str(i) + ']/td[3]")[0].text59 print(u)60 id_list.append(u)61 sleep(1)62 # reg_no = driver.find_element_by_xpath(63 # '/html/body/div[1]/div[2]/div[2]/div/div/div[1]/div/div[1]/div/div[4]/div/div[3]/table/tbody/tr[1]/td[3]/div')64 # reg = reg_no.get_attribute('innerHTML')65 ip_number = driver.find_element_by_xpath(66 '/html/body/div[1]/div[2]/div[2]/div/div/div[1]/div/div[1]/div/div[4]/div/div[3]/table/tbody/tr[1]/td[7]/div')67 ip_num = ip_number.get_attribute('innerHTML')68 print("ip_num", ip_num)69 view_profile = driver.find_element_by_xpath(70 '//*[@id="out-table"]/div[1]/div/div[4]/div/div[4]/div[2]/table/tbody/tr[1]/td[10]/div/button[2]/i')71 view_profile.click()72 treat_date = driver.find_element_by_xpath(73 '/html/body/div/div[2]/div[2]/div/div/div[1]/div/div[1]/div/div[4]/div/div[3]/table/tbody/tr/td[9]/div')74 treatment_d = treat_date.get_attribute('innerHTML')75 print("treatment_d", treatment_d)76 card_id = driver.find_element_by_xpath(77 '//*[@id="out-table"]/div[1]/div/div[4]/div/div[3]/table/tbody/tr[1]/td[4]/div')78 card = card_id.get_attribute('innerHTML')79 print(card)80 patient_name = driver.find_element_by_xpath('//*[@id="out-table"]/div[1]/div/div[4]/div/div[3]/table/tbody/tr[1]/td[5]/div')81 p_name = patient_name.get_attribute('innerHTML')82 print(p_name)83 # dep = driver.find_element_by_xpath('')84 # treat_photo = dep.get_attribute('innerHTML')85 pulse_rate = driver.find_element_by_xpath(86 '/html/body/div[1]/div[2]/div[2]/div/div/div[2]/div[1]/div/div[2]/div/div/div[3]/p[2]')87 pulse = pulse_rate.get_attribute('innerHTML')88 print(pulse)89 x = pulse[:3]90 print(x)91 y = pulse[4:6]92 print(y)93 # p_p = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div/div/div[2]/div[1]/div/div[6]/div/div/div/div[2]/div/div/div/div[1]/div/div/div/img')94 # action = ActionChains(driver)95 # action.context_click(p_p).key_down (Keys.SHIFT).perform()96 p_chart1 = driver.find_element_by_xpath(97 '/html/body/div[1]/div[2]/div[2]/div/div/div[2]/div[1]/div/div[6]/div/div/div/div[2]/div/div/div/div[1]/div/div/div/img')98 src1 = p_chart1.get_attribute('src')99 print(src1)100 p_chart2 = driver.find_element_by_xpath(101 '/html/body/div[1]/div[2]/div[2]/div/div/div[2]/div[1]/div/div[6]/div/div/div/div[3]/div/div/div/div[1]/div/div/div/img')102 src2 = p_chart2.get_attribute('src')103 print(src2)104 p_patient = driver.find_element_by_xpath(105 '/html/body/div[1]/div[2]/div[2]/div/div/div[2]/div[1]/div/div[6]/div/div/div/div[4]/div/div/div/div[1]/div/div/div/img')106 src3 = p_patient.get_attribute('src')107 print(src3)108 def dl_img(url, file_path, file_name):109 filename = file_name+".jpeg"110 fullfilename = os.path.join(file_path, filename)111 # urllib.urlretrieve(url, fullfilename)112 urllib.request.urlretrieve(url, fullfilename)113 url = src1114 file_name = card115 dl_img(url, r'C:\Users\PC\Desktop\auto', file_name)116 # def dl_img(url, file_path, file_name):117 # full_path = file_path + file_name + '.jpg'118 # urllib.request.urlretrieve(url, full_path)119 url = src2120 file_name = p_name121 dl_img(url, r'C:\Users\PC\Desktop\certificate', file_name)122 sleep(2)123 url = src3124 file_name = ip_num125 dl_img(url, r'C:\Users\PC\Desktop\chart', file_name)126 sleep(3)127driver.get('http://tms.pmjay.gov.in/')128sleep(5)129def login_tms():130 username = driver.find_element_by_xpath('//*[@id="username"]')131 username.send_keys('KER002197')132 pas = driver.find_element_by_xpath('//*[@id="password"]')133 pas.send_keys('Automate@1')134 # driver.find_element_by_xpath('//*[@id="select2-userState-container"]').click()135 driver.find_element_by_xpath('//*[@id="select2-userState-container"]').click()136 driver.find_element_by_xpath('/html/body/span/span/span[1]/input').send_keys('KERALA')137 sleep(1)138 driver.find_element_by_xpath('/html/body/span/span/span[2]/ul/li').click()139 # captcha = input("enter captcha here")140 captcha_text = driver.find_element_by_xpath('//*[@id="reqCaptcha"]')141 captcha_text.click()142 sleep(15)143 captcha_text.send_keys(Keys.ENTER)144 driver.find_element_by_id('checkSubmit').click()145 login = driver.find_element_by_xpath('//*[@id="login-submit"]')146 login.click()147 sleep(2)148login_tms()149# to click on close session if it shows up150if (check_exists_by_xpath('/html/body/div[10]/div/div/div[3]/button[2]')):151 driver.find_element_by_xpath('/html/body/div[10]/div/div/div[3]/button[2]').click()152 sleep(2)153 driver.find_element_by_xpath('/html/body/div[10]/div/div/div[2]/button').click()154 sleep(2)155 login_tms()156close = driver.find_element_by_xpath('//*[@id="notificationModal"]/div/div/div[1]/button')157close.click()158sleep(5)159preauth = driver.find_element_by_link_text('Preauth')160preauth.click()161sleep(2)162preauth_ins = driver.find_element_by_xpath('//*[@id="childmenu3"]/li[1]/a/span[1]')163actions = ActionChains(driver)164actions.move_to_element(preauth_ins).click().perform()165sleep(2)166driver.switch_to.frame(0)167regg_no = driver.find_element_by_name('patientNo')168regg_no.send_keys(id_list)169search = driver.find_element_by_xpath('//*[@id="registeredCases"]/div/div[4]/button[1]')170search.click()171regno =driver.find_element_by_xpath('//*[@id="no-more-tables"]/table/tbody/tr/td[2]').click()172sleep(3)173driver.switch_to.default_content()174driver.switch_to.frame(driver.find_element_by_id("middleFrame"))175sleep(2)176try:177 ip = driver.find_element_by_id('patientTypeIP')178 ip.click()179 Ipop = driver.find_element_by_id('submitIpOp')180 Ipop.click()181 sleep(3)182 ok = driver.find_element_by_xpath('/html/body/div[26]/div/div/div[2]/button[2]')183 ok.click()184 sleep(5)185 print('try')186except:187 sleep(5)188 # driver.find_element_by_xpath('html/body/div[2]/div[1]/div[1]/div/div[2]/div[1]/div[1]/div/span/span[1]/span/span[1]').click()189print('true')190try:191 driver.find_element_by_xpath(192 '/html/body/div[2]/div[1]/div[1]/div/div[2]/div[1]/div[1]/div/span/span[1]/span/span[1]').click()193 print('except')194 driver.find_element_by_xpath('/html/body/span/span/span[2]/ul/li[2]').click()195 sleep(2)196 sleep(2)197 d_description = driver.find_element_by_xpath('//*[@id="diagDesc"]')198 d_description.send_keys('CKD')199 procedure = driver.find_element_by_xpath(200 '/html/body/div[2]/div[1]/div[2]/div/div[3]/div/div[1]/div[1]/div[2]/span/span[1]/span/span[2]')201 procedure.click()202 sleep(2)203 driver.find_element_by_xpath('/html/body/span/span/span[1]/input').send_keys('MG072A')204 sleep(1)205 sel_procedure = driver.find_element_by_xpath('/html/body/span/span/span[2]/ul/li')206 sel_procedure.click()207 sleep(2)208 speciality = driver.find_element_by_xpath(209 '/html/body/div[2]/div[1]/div[2]/div/div[3]/div/div[1]/div[1]/div[1]/span/span[1]/span/span[2]')210 speciality.click()211 sleep(2)212 driver.find_element_by_xpath('/html/body/span/span/span[2]/ul/li[2]').click()213 doctor = driver.find_element_by_xpath(214 '/html/body/div[2]/div[1]/div[2]/div/div[3]/div/div[1]/div[1]/div[5]/span/span[1]/span/span[2]')215 doctor.click()216 driver.find_element_by_xpath('/html/body/span/span/span[1]/input').send_keys(5697)217 sel_doc = driver.find_element_by_xpath('/html/body/span/span/span[2]/ul/li').click()218 sleep(5)219 add_pro = driver.find_element_by_id('addSpeciality')220 add_pro.click()221 sleep(2)222 ok = w.until(223 expected_conditions.presence_of_element_located((By.XPATH, '/html/body/div[26]/div/div/div[2]/button')))224 ok.click()225 sleep(2)226except:227 pass228close_b = w.until(229 expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="notify"]/div/div/div[3]/button')))230close_b.click()231sleep(3)232seq = driver.find_elements_by_tag_name('iframe')233for num, frame in enumerate(seq):234 print(num, frame.get_attribute("id"))235print("No of frames present in the web page are: ", len(seq))236driver.switch_to.default_content()237sleep(5)238driver.switch_to.frame(driver.find_element_by_id('middleFrame'))239sleep(5)240try:241 driver.find_element_by_xpath('/html/body/div[26]/div/div/div[2]/button').click()242except:243 pass244driver.switch_to.default_content()245sleep(1)246driver.switch_to.frame(driver.find_element_by_id('middleFrame'))247sleep(2)248# driver.switch_to.frame(driver.find_element_by_id('iframe1'))249if check_exists_by_id("iframe1") and check_exists_by_id("iframe2"):250 # driver.switch_to.frame(driver.find_element_by_id('iframe1'))251 # upload_p = driver.find_element_by_id('invattachButton')252 # upload_p.send_keys(r'C:\Users\PC\Desktop\certificate\MUHAMMED ASHRAF .jpeg')253 driver.switch_to.frame(driver.find_element_by_id('iframe1'))254 upload = driver.find_element_by_xpath('//*[@id="invAttach"]')255 file_path = r'C:\Users\PC\Desktop\chart'256 filename = ip_num + ".jpeg"257 fullfilename = os.path.join(file_path, filename)258 upload.send_keys(fullfilename)259 driver.switch_to.parent_frame()260 driver.switch_to.frame(driver.find_element_by_id('iframe2'))261 upload_p = driver.find_element_by_xpath('//*[@id="invAttach"]')262 file_path = r'C:\Users\PC\Desktop\certificate'263 filename = p_name + ".jpeg"264 fullfilename = os.path.join(file_path, filename)265 upload_p.send_keys(fullfilename)266elif check_exists_by_id("iframe0") and check_exists_by_id("iframe1"):267 driver.switch_to.frame(driver.find_element_by_id('iframe0'))268 upload = driver.find_element_by_xpath('//*[@id="invAttach"]')269 file_path = r'C:\Users\PC\Desktop\chart'270 filename = ip_num + ".jpeg"271 fullfilename = os.path.join(file_path, filename)272 upload.send_keys(fullfilename)273 driver.switch_to.parent_frame()274 driver.switch_to.frame(driver.find_element_by_id('iframe1'))275 upload_p = driver.find_element_by_xpath('//*[@id="invAttach"]')276 file_path = r'C:\Users\PC\Desktop\certificate'277 filename = p_name + ".jpeg"278 fullfilename = os.path.join(file_path, filename)279 upload_p.send_keys(fullfilename)280 # # upload on iframe0 and then iframe1281 # print("uploaded")282else:283 print("something went wrong")284 exit()285driver.switch_to.default_content()286driver.switch_to.frame(driver.find_element_by_id("middleFrame"))287ip_no = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div[2]/div[1]/input')288ip_no.send_keys(ip_num)289admission_type = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div[2]/div[2]/select')290drop = Select(admission_type)291drop.select_by_visible_text('Planned')292sleep(2)293diagnosed_by = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div[2]/div[4]/select')294drop = Select(diagnosed_by)295drop.select_by_visible_text('Others')296doctor_name = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div[3]/div[2]/div[1]/input')297doctor_name.send_keys('DR PRADEEP K J')298alldate = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div[3]/div[3]/input')299print(treatment_d)300print(alldate)301alldate.send_keys(treatment_d)302sleep(2)303procedure_con = driver.find_element_by_xpath('//*[@id="procedureConsent"]')304procedure_con.click()305MLC = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div[4]/div[1]/input[2]')306MLC.click()307sleep(5)308general_find = driver.find_element_by_xpath('/html/body/div[1]/div[3]/form/div/div[8]/button[1]')309top = driver.find_element_by_xpath('/html/body/div[1]/div[3]/form/div/div[1]')310driver.execute_script("return arguments[0].scrollIntoView(true);",top)311sleep(10)312general_find.click()313sleep(20)314temperature = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[2]/form/div[2]/div/div/div[2]/div[1]/div[11]/div[1]/input')315sleep(2)316temperature.click()317sleep(2)318f = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[2]/form/div[2]/div/div/div[2]/div[1]/div[11]/div[2]/input[2]')319f.click()320sleep(5)321tmp = driver.find_element_by_name('GE11')322tmp.send_keys(str(98.6))323#sleep(3)324pulse = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[2]/form/div[2]/div/div/div[2]/div[1]/div[12]/div[1]/input')325pulse.click()326#sleep(2)327pulse_r = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[2]/form/div[2]/div/div/div[2]/div[1]/div[12]/div[2]/input')328pulse_r.send_keys(78)329sleep(1)330driver.find_element_by_xpath('/html/body/div[8]/div/div/div[2]/form/div[2]/div/div/div[2]/div[1]/div[14]/div[1]/input').click()331bp = driver.find_element_by_name('GE14')332bp.send_keys(x)333sleep(2)334bp_h = driver.find_element_by_name('BP1')335bp_h.send_keys(y)336sleep(5)337w.until(338 expected_conditions.presence_of_element_located((By.XPATH, '/html/body/div[8]/div/div/div[2]/form/div[2]/div/div/div[2]/div[2]/button'))).click()339sleep(5)340save_ok = w.until(341 expected_conditions.presence_of_element_located((By.XPATH, '/html/body/div[27]/div/div/div[2]/button')))342save_ok.click()343sleep(2)344close_save = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[3]/button')345close_save.click()346sleep(2)347sleep(5)348pf_history = driver.find_element_by_xpath('/html/body/div[1]/div[3]/form/div/div[8]/button[3]')349topp = driver.find_element_by_xpath('/html/body/div[1]/div[3]/form/div')350driver.execute_script("return arguments[0].scrollIntoView(true);",topp)351sleep(10)352pf_history.click()353sleep(20)354not_applicable = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[2]/form/div[1]/div[1]/div/div[2]/div[12]/div[1]/input')355not_applicable.click()356save_history = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[2]/form/div[2]/button')357save_history.click()358sleep(3)359ok_history = driver.find_element_by_xpath('/html/body/div[27]/div/div/div[2]/button')360ok_history.click()361sleep(2)362close_history = driver.find_element_by_xpath('/html/body/div[8]/div/div/div[1]/button')363close_history.click()364sleep(3)365action_typ = driver.find_element_by_id('actionType')366drop = Select(action_typ)367drop.select_by_visible_text('Initiate Pre-auth')368sleep(2)369add_view = driver.find_element_by_id('btnattach')370add_view.click()371driver.switch_to.default_content()372sleep(1)373driver.switch_to.frame('middleFrame')374sleep(2)375driver.switch_to.frame(driver.find_element_by_id('modalattDivIframe'))376p_photo = driver.find_element_by_xpath('//*[@id="BPM1"]')377file_path = r'C:\Users\PC\Desktop\auto'378filename = card + ".jpeg"379full_filename = os.path.join(file_path, filename)380p_photo.send_keys(full_filename)381p_ok = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/button')382p_ok.click()383driver.switch_to.default_content()384driver.switch_to.frame(driver.find_element_by_id('middleFrame'))385p_close = driver.find_element_by_xpath('//*[@id="modalattachDiv"]/div/div/div[3]/button')386p_close.click()387# submit = driver.find_element_by_xpath('//*[@id="btnSubmit"]')388# submit.click()389# sleep(2)390# QA_button = driver.find_element_by_xpath('/html/body/div[26]/div/div/div[2]/button[2]')391# QA_button.click()392# sleep(2)393# Q1 = driver.find_element_by_xpath('//*[@id="triggerDetails"]/div/table/tbody/tr[1]/td[3]/label[1]/span[2]')394# Q1.click()395# Q2 = driver.find_element_by_xpath('//*[@id="triggerDetails"]/div/table/tbody/tr[2]/td[3]/label[1]/span[2]')396# Q2.click()397# Q3 = driver.find_element_by_xpath('//*[@id="triggerDetails"]/div/table/tbody/tr[3]/td[3]/label[1]/span[2]')398# Q3.click()399# Q4 = driver.find_element_by_xpath('//*[@id="triggerDetails"]/div/table/tbody/tr[4]/td[3]/label[1]/span[2]')400# Q4.click()401# Q5 = driver.find_element_by_xpath('//*[@id="triggerDetails"]/div/table/tbody/tr[5]/td[3]/label[1]/span[2]')402# Q5.click()403# sleep(3)404# Q_ok = driver.find_element_by_xpath('/html/body/div[4]/div/div/div[2]/button')405# Q_ok.click()406# Q_close = driver.find_element_by_xpath('//*[@id="questionaireModal"]/div/div/div[1]/button')407# Q_close.click()408# sleep(2)409# intiate = driver.find_element_by_xpath('/html/body/div[26]/div/div/div[2]/button[2]')410# intiate.click()411# sleep(5)412# case_id = driver.find_element_by_xpath('/html/body/form[1]/center[1]/font/div/div/div[2]/div/strong/b[2]')413# id_value = case_id.get_attribute('innerHTML')414# sleep(2)415# sub_id = driver.find_element_by_xpath('//*[@id="generateCasePrintPage"]')416# sub_id.click()417# sleep(10)418# case_sd = driver.find_element_by_xpath('//*[@id="childmenu3"]/li[2]/a/span[1]')419# case_sd.click()420# sleep(2)421# case_no = driver.find_element_by_name('caseNo')422# case_no.send_keys(id_value)423# search_no = driver.find_element_by_xpath('//*[@id="preauthForApproval"]/div[3]/button[1]')424# search_no.click()425# sleep(3)426# caseno = driver.find_element_by_xpath('//*[@id="no-more-tables"]/table/tbody/tr/td[2]/b/u/a')427# caseno.click()428# close_n = driver.find_element_by_xpath('//*[@id="notify"]/div/div/div[3]/button')429# close_n.click()430#431# # authonticate432#433# covid_case = driver.find_element_by_xpath('//*[@id="covidNo"]')434# covid_case.click()435# sleep(1)436# t_dr = driver.find_element_by_xpath('//*[@id="collapseTrtDr"]/div[1]/span/span[1]/span/span[2]')437# t_dr.click()438# driver.find_element_by_xpath('/html/body/span/span/span[1]/input').send_keys('Specialist')439# specialist = driver.find_element_by_xpath('//*[@id="select2-docType-result-ib3j-D"]')...

Full Screen

Full Screen

dfp.py

Source:dfp.py Github

copy

Full Screen

1from selenium import webdriver 2import unittest3from selenium.webdriver.common.by import By4from selenium.webdriver.support.ui import WebDriverWait as W5from selenium.webdriver.support import expected_conditions as E6from webdriver_manager.chrome import ChromeDriverManager7from selenium.webdriver.chrome.options import Options8import time9chrome_options = Options()10chrome_options.headless = True11chrome_options.add_argument("--headless") 12#driver = webdriver.Chrome(options=chrome_options) 13driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)14class dfp(unittest.TestCase): 15 16 def test_dfpnews(self):17 18 self.driver = driver19 driver.maximize_window()20 driver.get("https:www.collegedekho.com/news?magicflag=1")21 print("----------------------------------------------News Listing---------------------------------")22 print("current url = " + driver.current_url)23 print("current title = " + driver.title)24 frames = driver.find_elements_by_tag_name("iframe")25 print("There are ", len(frames),"frames on this webpage") 26 for f in frames:27 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),28 "frame height:", f.get_attribute('height'))29 30 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_College_NEWS_Home_Page_Header_LeaderBoard_0")31 elm.click()32 time.sleep(5)33 childwindow = driver.window_handles[1]34 driver.switch_to_window(childwindow)35 print("current url =" + driver.current_url)36 print("current title = " + driver.title)37 parentwindow = driver.window_handles[0]38 driver.switch_to_window(parentwindow)39 driver.quit()40 41 def test_dfpstream(self):42 self.driver = driver43 driver.maximize_window()44 driver.get("https://www.collegedekho.com/engineering-stream/?magicflag=1")45 print("----------------------------------------------Stream ---------------------------------")46 print("current url = " + driver.current_url)47 print("current title = " + driver.title)48 frames = driver.find_elements_by_tag_name("iframe")49 print("There are ", len(frames),"frames on this webpage") 50 for f in frames:51 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),52 "frame height:", f.get_attribute('height'))53 54 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_Stream_Template_Leaderboard_0")55 elm.click()56 time.sleep(5)57 childwindow = driver.window_handles[1]58 driver.switch_to_window(childwindow)59 print("current url =" + driver.current_url)60 print("current title = " + driver.title)61 parentwindow = driver.window_handles[0]62 driver.switch_to_window(parentwindow)63 driver.quit()64 def test_dfpcourses(self):65 self.driver = driver66 driver.maximize_window()67 print("----------------------------------------------Course Listing---------------------------------")68 driver.get("https://www.collegedekho.com/courses/?magicflag=1")69 print("current url = " + driver.current_url)70 print("current title = " + driver.title)71 frames = driver.find_elements_by_tag_name("iframe")72 print("There are ", len(frames),"frames on this webpage") 73 for f in frames:74 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),75 "frame height:", f.get_attribute('height'))76 77 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_Course_Listing_Leaderboard_0")78 elm.click()79 time.sleep(5)80 childwindow = driver.window_handles[1]81 driver.switch_to_window(childwindow)82 print("current url =" + driver.current_url)83 print("current title = " + driver.title)84 parentwindow = driver.window_handles[0]85 driver.switch_to_window(parentwindow)86 driver.quit()87 def test_dfpcoursesdetail(self):88 self.driver = driver89 driver.maximize_window()90 print("--------------------------------Course Detail------------------------------------------")91 time.sleep(2)92 driver.get("https://www.collegedekho.com/courses/btech/?magicflag=1")93 print("current url = " + driver.current_url)94 print("current title = " + driver.title)95 frames = driver.find_elements_by_tag_name("iframe")96 print("There are ", len(frames),"frames on this webpage") 97 for f in frames:98 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),99 "frame height:", f.get_attribute('height'))100 101 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_Course_Detail_Leaderboard_0")102 elm.click()103 time.sleep(5)104 childwindow = driver.window_handles[1]105 driver.switch_to_window(childwindow)106 print("current url =" + driver.current_url)107 print("current title = " + driver.title)108 parentwindow = driver.window_handles[0]109 driver.switch_to_window(parentwindow)110 driver.quit()111 def test_dfpexamlisting(self):112 self.driver = driver113 driver.maximize_window()114 print("----------------------------------------------Exam Listing---------------------------------")115 driver.get("https://www.collegedekho.com/test-preparation/?magicflag=1")116 print("current url = " + driver.current_url)117 print("current title = " + driver.title)118 frames = driver.find_elements_by_tag_name("iframe")119 print("There are ", len(frames),"frames on this webpage") 120 for f in frames:121 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),122 "frame height:", f.get_attribute('height'))123 124 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_Home_Exam_Listing_Leaderboard_0")125 elm.click()126 time.sleep(5)127 childwindow = driver.window_handles[1]128 driver.switch_to_window(childwindow)129 print("current url =" + driver.current_url)130 print("current title = " + driver.title)131 parentwindow = driver.window_handles[0]132 driver.switch_to_window(parentwindow)133 driver.quit()134 def test_dfpQnalisting(self):135 self.driver = driver136 driver.maximize_window()137 print("----------------------------------------------Qna Listing---------------------------------")138 driver.get("https://www.collegedekho.com/qna/?magicflag=1")139 print("current url = " + driver.current_url)140 print("current title = " + driver.title)141 frames = driver.find_elements_by_tag_name("iframe")142 print("There are ", len(frames),"frames on this webpage") 143 for f in frames:144 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),145 "frame height:", f.get_attribute('height'))146 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_College_QNA_Header_LeaderBoard_0")147 elm.click()148 time.sleep(5)149 childwindow = driver.window_handles[1]150 driver.switch_to_window(childwindow)151 print("current url =" + driver.current_url)152 print("current title = " + driver.title)153 parentwindow = driver.window_handles[0]154 driver.switch_to_window(parentwindow)155 driver.quit()156 def test_dfpQnadetail(self):157 self.driver = driver158 driver.maximize_window()159 print("----------------------------------------------Qna Detail---------------------------------")160 driver.get("https://www.collegedekho.com/qna/i-want-to-know-about-the-eligibility-requirements-for-pursuing-btech-at-alliance-university")161 print("current url = " + driver.current_url)162 print("current title = " + driver.title)163 frames = driver.find_elements_by_tag_name("iframe")164 print("There are ", len(frames),"frames on this webpage") 165 for f in frames:166 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),167 "frame height:", f.get_attribute('height'))168 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_College_QNA_Detail_Header_LeaderBoard_0")169 elm.click()170 time.sleep(5)171 childwindow = driver.window_handles[1]172 driver.switch_to_window(childwindow)173 print("current url =" + driver.current_url)174 print("current title = " + driver.title)175 parentwindow = driver.window_handles[0]176 driver.switch_to_window(parentwindow)177 def test_dfpcollegelisting(self):178 self.driver = driver179 driver.maximize_window()180 print("----------------------------------------------College Lising---------------------------------")181 driver.get("https://www.collegedekho.com/colleges-in-india/?magicflag=1")182 print("current url = " + driver.current_url)183 print("current title = " + driver.title)184 frames = driver.find_elements_by_tag_name("iframe")185 print("There are ", len(frames),"frames on this webpage") 186 for f in frames:187 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),188 "frame height:", f.get_attribute('height'))189 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_College_List_Page_Body1_LeaderBoard_0")190 elm.click()191 time.sleep(5)192 childwindow = driver.window_handles[1]193 driver.switch_to_window(childwindow)194 print("current url =" + driver.current_url)195 print("current title = " + driver.title)196 parentwindow = driver.window_handles[0]197 driver.switch_to_window(parentwindow)198 driver.quit()199 def test_dfpcollegedetail(self):200 self.driver = driver201 driver.maximize_window()202 print("----------------------------------------------College Detail---------------------------------")203 driver.get("https://www.collegedekho.com/colleges/iima?magicflag=1")204 print("current url = " + driver.current_url)205 print("current title = " + driver.title)206 frames = driver.find_elements_by_tag_name("iframe")207 print("There are ", len(frames),"frames on this webpage") 208 for f in frames:209 print("frame ID:", f.get_attribute('id'), "frame Name:", f.get_attribute('name'), "frame width:", f.get_attribute('width'),210 "frame height:", f.get_attribute('height'))211 elm = driver.find_element_by_id("google_ads_iframe_/99910373/CLD_College_Detail_Overview_Page_Header_Leaderboard_0__container__")212 elm.click()213 time.sleep(5)214 childwindow = driver.window_handles[1]215 driver.switch_to_window(childwindow)216 print("current url =" + driver.current_url)217 print("current title = " + driver.title)218 parentwindow = driver.window_handles[0]219 driver.switch_to_window(parentwindow)220 driver.quit()221 def tearDown(self):222 self.driver.quit()223if __name__ == '__main__':...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

1import time2import random3import names4from selenium import webdriver5from selenium.webdriver.common.by import By6from selenium.webdriver.support.ui import WebDriverWait7from selenium.webdriver.support import expected_conditions as EC8from selenium.webdriver.common.keys import Keys9PATH = "C:\Program Files (x86)\chromedriver.exe"10URL = "https://localhost:8091"11PRODUCTS_NUM = 212FIRST_CATEGORY_PRODUCTS_NUM = 113FIRST_CATEGORY = '/index.php?id_category=17&controller=category'14SECOND_CATEGORY = '/index.php?id_category=24&controller=category'15#FIRST_CATEGORY = '/index.php?id_category=7&controller=category'16#SECOND_CATEGORY = '/index.php?id_category=15&controller=category'17class Test:18 def __init__(self, driver, url, products_num, first_category_products_num, first_category, second_category):19 self.driver = driver20 self.url = url21 self.products_num = products_num22 self.first_category_products_num = first_category_products_num23 self.second_category_products_num = products_num - first_category_products_num24 self.first_category_url = url + '/' + first_category25 self.second_category_url = url + '/' + second_category26 def test(self):27 self.fill_cart(self.first_category_products_num, self.first_category_url)28 self.fill_cart(self.second_category_products_num, self.second_category_url)29 selected_product_index = random.randint(0,self.products_num - 1)30 self.remove_product(selected_product_index)31 self.create_account()32 self.fill_order_form()33 def fill_cart(self, products_num, category_url):34 added_products = 035 current_page_number = 136 while(added_products<products_num):37 self.driver.get(category_url + '?page=' + str(current_page_number))38 try:39 products_on_page = len(WebDriverWait(driver, 10).until(40 EC.presence_of_all_elements_located((By.CLASS_NAME, 'product'))41 ))42 except Exception:43 print('Not enough products for this category: ' + category_url)44 return45 for product_index in range(products_on_page):46 if (added_products >= products_num):47 break48 products = WebDriverWait(driver, 10).until(49 EC.presence_of_all_elements_located((By.CLASS_NAME, 'product'))50 )51 products[product_index].click()52 added_products += self.add_one_product()53 self.driver.get(category_url + '?page=' + str(current_page_number))54 current_page_number += 155 def add_one_product(self):56 NOT_ADDED = 057 ADDED = 158 try:59 product_quantities = WebDriverWait(driver, 10).until(60 EC.presence_of_element_located((By.CSS_SELECTOR, '.product-quantities > span'))61 )62 except Exception:63 return NOT_ADDED64 quantity = product_quantities.get_attribute('data-stock')65 if int(quantity) == 0:66 return NOT_ADDED67 selected_quantity = random.randint(1,int(quantity))68 driver.find_element_by_id('quantity_wanted').clear()69 driver.find_element_by_id('quantity_wanted').send_keys(Keys.BACK_SPACE)70 driver.find_element_by_id('quantity_wanted').send_keys(selected_quantity)71 driver.find_element_by_css_selector('.add > button').click()72 btn = WebDriverWait(driver, 10).until(73 EC.element_to_be_clickable((By.CSS_SELECTOR,'.cart-content-btn > button'))74 )75 btn.click()76 return ADDED77 def remove_product(self, selected_product_index):78 cart_link = WebDriverWait(driver, 10).until(79 EC.presence_of_element_located((By.CSS_SELECTOR, '.header > a'))80 )81 cart_link.click()82 remove_links = WebDriverWait(driver, 10).until(83 EC.presence_of_all_elements_located((By.CSS_SELECTOR, 'a.remove-from-cart'))84 )85 remove_links[selected_product_index].click()86 cart_itmes = WebDriverWait(driver, 10).until(87 EC.presence_of_all_elements_located((By.CSS_SELECTOR, '.cart-item'))88 )89 def create_account(self):90 FIRST_NAME = 'Luke'91 LAST_NAME = 'Skywalker'92 EMAIL = names.get_last_name()+'luukeskywalker2@gmail.com'93 PASSWORD = 'LeiaOrgana123321'94 MALE = 095 self.driver.get(self.url)96 sign_in_link = WebDriverWait(driver, 10).until(97 EC.presence_of_element_located((By.CSS_SELECTOR, '.user-info > a'))98 )99 sign_in_link.click()100 create_account_link = WebDriverWait(driver, 10).until(101 EC.presence_of_element_located((By.CSS_SELECTOR, '.no-account > a'))102 )103 create_account_link.click()104 WebDriverWait(driver, 10).until(105 EC.presence_of_element_located((By.CSS_SELECTOR, '#customer-form'))106 )107 gender_radio_btn = self.driver.find_elements_by_css_selector('label.radio-inline')108 gender_radio_btn[MALE].click()109 name_field = self.driver.find_element_by_css_selector('#field-firstname')110 name_field.send_keys(FIRST_NAME)111 last_name_field = self.driver.find_element_by_css_selector('#field-lastname')112 last_name_field.send_keys(LAST_NAME)113 email_field = self.driver.find_element_by_css_selector('#field-email')114 email_field.send_keys(EMAIL)115 password_field = self.driver.find_element_by_css_selector('#field-password')116 password_field.send_keys(PASSWORD)117 customer_privacy_checkbox = self.driver.find_element_by_css_selector\118 ('.custom-checkbox > label > input[name=customer_privacy]')119 customer_privacy_checkbox.click()120 psgdpr_checkbox = self.driver.find_element_by_css_selector \121 ('.custom-checkbox > label > input[name=psgdpr]')122 psgdpr_checkbox.click()123 submit_btn = self.driver.find_element_by_css_selector\124 ('button.btn.btn-primary.form-control-submit.float-xs-right')125 submit_btn.click()126 personal_info = WebDriverWait(driver, 10).until(127 EC.presence_of_element_located((By.CSS_SELECTOR, '.hidden-sm-down'))128 ).text129 def fill_order_form(self):130 cart_link = WebDriverWait(driver, 10).until(131 EC.presence_of_element_located((By.CSS_SELECTOR, '.header > a'))132 )133 cart_link.click()134 order_form_link = WebDriverWait(driver, 10).until(135 EC.presence_of_element_located((By.CSS_SELECTOR, '.text-sm-center > a'))136 )137 order_form_link.click()138 self.fill_address()139 self.choose_delivery_method()140 self.choose_payment_method()141 self.check_status()142 def fill_address(self):143 CITY = 'GDANSK'144 POSTAL_CODE = '80-223'145 ADDRESS = 'Gabriela Narutowicza 11/12'146 WebDriverWait(driver, 10).until(147 EC.presence_of_element_located((By.CSS_SELECTOR, '.js-address-form'))148 )149 addres_field = self.driver.find_element_by_css_selector('#field-address1')150 addres_field.send_keys(ADDRESS)151 postal_code_field = self.driver.find_element_by_css_selector('#field-postcode')152 postal_code_field.send_keys(POSTAL_CODE)153 city_field = self.driver.find_element_by_css_selector('#field-city')154 city_field.send_keys(CITY)155 continue_btn = self.driver.find_element_by_css_selector\156 ('.form-footer.clearfix > button[name=confirm-addresses]')157 continue_btn.click()158 def choose_delivery_method(self):159 delivery_option = WebDriverWait(driver, 10).until(160 EC.presence_of_element_located((By.CSS_SELECTOR, '#delivery_option_2'))161 )162 delivery_option.click()163 subbmit_bttn = WebDriverWait(driver, 10).until(164 EC.presence_of_element_located((By.NAME, 'confirmDeliveryOption'))165 )166 subbmit_bttn.click()167 def choose_payment_method(self):168 delivery_option = WebDriverWait(driver, 10).until(169 EC.presence_of_element_located((By.CSS_SELECTOR, '#payment-option-2'))170 )171 delivery_option.click()172 self.driver.find_element_by_id('conditions_to_approve[terms-and-conditions]').click()173 subbmit_bttn = WebDriverWait(driver, 10).until(174 EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Złóż zamówienie')]"))175 )176 subbmit_bttn.click()177 def check_status(self):178 try:179 WebDriverWait(driver, 10).until(180 EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Płatność przy odbiorze')]"))181 )182 except Exception:183 print("TEST FAILED")184 self.driver.get(self.url+'/index.php?controller=history')185 try:186 WebDriverWait(driver, 10).until(187 EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Przygotowanie w toku')]"))188 )189 except Exception:190 print("TEST FAILED")191if __name__ == "__main__":192 driver = webdriver.Chrome(PATH)193 driver.maximize_window()194 #driver.find_element_by_class_name()195 test = Test(driver, URL, PRODUCTS_NUM, FIRST_CATEGORY_PRODUCTS_NUM, FIRST_CATEGORY, SECOND_CATEGORY)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful