Best JavaScript code snippet using mountebank
dedupe_unit_test.py
Source:dedupe_unit_test.py
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()...
dialysis_aut.py
Source:dialysis_aut.py
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"]')...
dfp.py
Source:dfp.py
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__':...
test.py
Source:test.py
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)...
login_mail.py
Source:login_mail.py
1import time2import selenium3from util import explicit_wait4from receiveEmail import get_confirm_url5def login_yahoo(driver, email, email_pwd, paypal_pwd, step_flag, paypal_type):6 time.sleep(5)7 paypal_confirm_url = get_confirm_email(email, email_pwd)8 if not paypal_confirm_url and paypal_type == 1:9 print('Not email url, Send again!')10 paypal_confirm_url = paypal_personal_send_email_again(driver, step_flag)11 elif not paypal_confirm_url and paypal_type == 2:12 print('Not email url, Send again!')13 paypal_confirm_url = paypal_here_send_email_again(driver, step_flag)14 if paypal_confirm_url:15 js = 'window.open("%s");' % paypal_confirm_url16 driver.execute_script(js)17 windows = driver.window_handles18 # Gets the new page handle19 driver.switch_to.window(windows[1])20 time.sleep(3)21 step_flag = activate(driver, email, paypal_pwd, step_flag)22 else:23 step_flag = 024 return step_flag25def paypal_personal_send_email_again(driver, step_flag):26 print('Send email again!')27 try:28 driver.find_element_by_xpath('//div[@class="myAccount"]/a').click()29 time.sleep(3)30 except:31 pass32 email_flag_XP = '//a[@data-name="confirm_your_email"]'33 email_flag_exist = explicit_wait(driver, "VOEL", [email_flag_XP, "XPath"], 30, False)34 if email_flag_exist:35 email_flag = driver.find_element_by_xpath(email_flag_XP)36 (ActionChains(driver)37 .move_to_element(email_flag)38 .click()39 .perform())40 click_send_button_XP = '//button[@id="js_unconfirmedEmail"]'41 click_send_button_flag = explicit_wait(driver, "VOEL", [click_send_button_XP, "XPath"], 30, False)42 if click_send_button_flag:43 click_send_button = driver.find_element_by_xpath(click_send_button_XP)44 (ActionChains(driver)45 .move_to_element(click_send_button)46 .click()47 .perform())48 else:49 driver.refresh()50 click_send_button_XP = '//button[@id="js_unconfirmedEmail"]'51 click_send_button_flag = explicit_wait(driver, "VOEL", [click_send_button_XP, "XPath"], 30, False)52 if click_send_button_flag:53 click_send_button = driver.find_element_by_xpath(click_send_button_XP)54 (ActionChains(driver)55 .move_to_element(click_send_button)56 .click()57 .perform())58 else:59 step_flag = 060 if step_flag == 1:61 time.sleep(10)62 paypal_confirm_url = get_confirm_email(email, email_pwd)63 else:64 step_flag = 065 return paypal_confirm_url66def paypal_here_send_email_again(driver, step_flag):67 driver.get('https://www.paypal.com/businessprofile/settings/email')68 email_edit_XP = '//span[@class="links"]//a[1]'69 email_edit_flag = explicit_wait(driver, "VOEL", [email_edit_XP, "XPath"], 10, False)70 if email_edit_flag:71 driver.find_element_by_xpath(email_edit_XP).click()72 email_confirm_XP = '//a[@class="confirm"]'73 email_confirm_flag = explicit_wait(driver, "VOEL", [email_confirm_XP, "XPath"], 10, False)74 if email_confirm_flag:75 driver.find_element_by_xpath(email_confirm_XP).click()76 time.sleep(5)77 paypal_confirm_url = get_confirm_email(email, email_pwd)78 step_flag = 079 else:80 step_flag = 081 return paypal_confirm_url82def login_gmail(driver, conn, email, email_pwd, paypal_pwd, recovery_email):83 js = 'window.open("https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1");'84 driver.execute_script(js)85 windows = driver.window_handles86 # Gets the new page handle87 driver.switch_to.window(windows[1])88 time.sleep(3)89 if driver.page_source.find('This site canât be reached') > -1:90 print('Net Error!')91 driver.refence()92 time.sleep(5)93 try:94 # element = WebDriverWait(driver, 10).until(95 # EC.presence_of_element_located((By.ID, 'identifierId')))96 # element.send_keys(email)97 driver.find_element_by_id('identifierId').send_keys(email)98 time.sleep(1)99 driver.find_element_by_id('identifierNext').click()100 time.sleep(5)101 except Exception as e:102 pass103 try:104 driver.find_element_by_name('password').send_keys(email_pwd)105 driver.find_element_by_id('passwordNext').click()106 time.sleep(3)107 error_info = driver.find_element_by_xpath(108 '//div[@class="GQ8Pzc"]')109 if error_info:110 print('Password error!')111 except Exception as e:112 pass113 try:114 time.sleep(5)115 element1 = WebDriverWait(driver, 10).until(116 EC.presence_of_element_located((By.XPATH, '//li[@class="C5uAFc"]/div')))117 element1.click()118 time.sleep(3)119 element2 = WebDriverWait(driver, 10).until(120 EC.presence_of_element_located((By.ID, 'identifierId')))121 element2.send_keys(recovery_email)122 driver.find_element_by_xpath(123 '//div[@class="qhFLie"]/div').click()124 except Exception as e:125 pass126 try:127 element3 = WebDriverWait(driver, 5).until(128 EC.presence_of_element_located((By.XPATH, '//div[@class="N4lOwd"]')))129 time.sleep(3)130 driver.find_element_by_xpath(131 '//div[@class="yKBrKe"]/div').click()132 except Exception as e:133 pass134 try:135 element = WebDriverWait(driver, 10).until(136 EC.presence_of_element_located((By.XPATH, '//div[@class="tbyFuf"]//a[2]')))137 element.click()138 time.sleep(3)139 except Exception as e:140 pass141 try:142 driver.find_element_by_xpath(143 '//button[@name="welcome_dialog_next"]').click()144 time.sleep(2)145 driver.find_element_by_xpath('//button[@name="ok"]').click()146 time.sleep(2)147 except:148 pass149 try:150 email_element = driver.find_elements_by_xpath(151 '//div[@class="yW"]//span[@name="service@paypal.com"]')152 email_element[0].click()153 time.sleep(3)154 except:155 pass156 while True:157 link_element = ''158 try:159 link_element = driver.find_element_by_xpath(160 '//a[text()="Confirm My Email"]')161 except:162 pass163 if link_element:164 link_element.click()165 time.sleep(5)166 break167 windows = driver.window_handles168 # Gets the new page handle169 driver.switch_to.window(windows[2])170 time.sleep(3)171 activate(driver, email, paypal_pwd, created_flag)172def activate(driver, email, paypal_pwd, step_flag):173 input_password_XP = '//input[@id="password"]'174 input_password_flag = explicit_wait(175 driver, "VOEL", [input_password_XP, "XPath"], 30, False)176 if input_password_flag:177 time.sleep(8)178 driver.find_element_by_xpath(input_password_XP).send_keys(paypal_pwd)179 time.sleep(1)180 driver.find_element_by_xpath('//button[@id="btnLogin"]').click()181 time.sleep(1)182 not_now_button_XP = '//p[@class="secondaryLink"]/a'183 not_now_button_flag = explicit_wait(184 driver, "VOEL", [not_now_button_XP, "XPath"], 10, False)185 if not_now_button_flag:186 not_now_button = driver.find_element_by_xpath(not_now_button_XP)187 (ActionChains(driver)188 .move_to_element(not_now_button)189 .click()190 .perform())191 else:192 try_times = 0193 while True:194 msg_code = ''195 try:196 msg_code = driver.find_element_by_xpath(197 '//form/div[1]/p').text198 except:199 pass200 if msg_code == 'Your email is all set!':201 # Not now202 driver.find_element_by_xpath(203 '//button[@id="/appData/action"]').click()204 break205 else:206 try_times += 1207 time.sleep(3)208 if try_times > 5:209 step_flag = 0210 break211 else:212 step_flag = 0...
FlightPages.py
Source:FlightPages.py
1import time2from calendar import Calendar3from selenium.webdriver.support.ui import Select4from 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.action_chains import ActionChains9from selenium.webdriver.common.keys import Keys10from selenium.webdriver.common.action_chains import ActionChains11from selenium.common.exceptions import NoAlertPresentException, NoSuchWindowException, NoSuchFrameException, StaleElementReferenceException12from FlightLocators import FlightLocators13from FlightData import FlightData14class BaseFlightPage():15 def __init__(self,driver):16 self.driver = driver17 def click(self,by_locator):18 WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator)).click()19 def assert_element_text(self, by_locator, element_text):20 web_element = WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(by_locator))21 assert web_element.text == element_text22 def enter_keys(self,by_locator,text):23 return WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(by_locator)).send_keys(text)24 def is_enabled(self,by_locator):25 return WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(by_locator))26 def is_visible(self,by_locator):27 element = WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(by_locator))28 return bool (element)29 def hover_to(self,by_locator):30 element = WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(by_locator))31 ActionChains(self.driver).move_to_element(element).perform()32class FlightHomePage(BaseFlightPage):33 def __init__(self, driver):34 super().__init__(driver)35 self.driver.get(FlightData.BASE_URL)36 def select_round_trip(self):37 self.driver.find_element(*FlightLocators.RoundTrip).click()38class SelectDestinations(BaseFlightPage):39 def __init__(self, driver):40 super().__init__(driver)41 def select_destinations(self):42 self.driver.find_element(*FlightLocators.From).send_keys("Mumbai")43 self.driver.find_element(*FlightLocators.Select_Mumbai).click()44 self.driver.find_element(*FlightLocators.To).send_keys("Delhi")45 self.driver.find_element(*FlightLocators.Select_Delhi).click()46class SelectDateRange(BaseFlightPage):47 def __init__(self, driver):48 super().__init__(driver)49 def select_daterange(self):50 calendar = self.driver.find_element(*FlightLocators.select_calendar)51 calendar.click()52 picker = self.driver.find_element(*FlightLocators.DatePicker)53 actions = ActionChains(self.driver)54 actions.move_to_element(picker)55 # perform the operation on the element56 actions.perform()57 fromdate = self.driver.find_element(*FlightLocators.From_Date)58 fromdate.click()59 todate = self.driver.find_element(*FlightLocators.To_Date)60 todate.click()61class SelectPassengerInfo(BaseFlightPage):62 def __init__(self, driver):63 super().__init__(driver)64 def select_passengers(self):65 selectadult = self.driver.find_element(*FlightLocators.Adults)66 adultcount = Select(selectadult)67 adultcount.select_by_value("2")68 selectchild = self.driver.find_element(*FlightLocators.Child)69 childcount = Select(selectchild)70 childcount.select_by_value("1")71class SearchFlight(BaseFlightPage):72 def __init__(self, driver):73 super().__init__(driver)74 def search_flight(self):75 self.driver.find_element(*FlightLocators.SearchFlight).click()76 time.sleep(3)77class BookFlight(BaseFlightPage):78 def __init__(self, driver):79 super().__init__(driver)80 def book_flight(self):81 #self.driver.find_element(*FlightLocators.BookButton).click()82 parent_window_handle = self.driver.current_window_handle83 print("Parent Window Handle is - ", parent_window_handle)84 book_flight = self.driver.find_element(*FlightLocators.BookButton)85 book_flight.click()86 time.sleep(5)87 try:88 self.driver.switch_to.window(self.driver.window_handles[1])89 except NoSuchWindowException:90 print("No Such Window Present")91 def standard_fare(self):92 time.sleep(6)93 self.driver.execute_script("window.scrollTo(0, 300)")94 self.driver.find_element(*FlightLocators.StandardFare).click()95 self.driver.execute_script("window.scrollTo(0, 1400)")96 time.sleep(3)97 self.driver.find_element(*FlightLocators.Continue).click()98 time.sleep(3)99 self.driver.find_element(*FlightLocators.select_seats).click()100class FlightDetails(BaseFlightPage):101 def __init__(self, driver):102 super().__init__(driver)103 def select_seats(self):104 time.sleep(3)105 seats = self.driver.find_elements(*FlightLocators.Seat)106 selectseats = []107 for x in (seats):108 selectseats.append(x)109 if len(selectseats)==3:110 break111 for y in selectseats:112 y.click()113 print("hello")114 time.sleep(4)115 self.driver.find_element(*FlightLocators.Done).click()116 self.driver.find_element(*FlightLocators.SaveNextSeats).click()117 def select_meals(self):118 time.sleep(3)119 self.driver.find_element(*FlightLocators.Meals).click()120 self.driver.find_element(*FlightLocators.MealsNext).click()121 self.driver.find_element(*FlightLocators.Next_menu).click()122 self.driver.find_element(*FlightLocators.MealsDone).click()123 self.driver.find_element(*FlightLocators.SaveNext).click()124 def select_baggage(self):125 time.sleep(3)126 self.driver.find_element(*FlightLocators.Baggage).click()127 self.driver.find_element(*FlightLocators.AddedLuggage).click()128 self.driver.find_element(*FlightLocators.LuggageDone).click()129 self.driver.find_element(*FlightLocators.SaveAndExit).click()130 self.driver.find_element(*FlightLocators.ContinueAfterLuggage).click()131 def contact_details(self):132 time.sleep(4)133 self.driver.find_element(*FlightLocators.MobileNumber).send_keys("9096914627")134 self.driver.find_element(*FlightLocators.Email).send_keys("isha.rth@gmail.com")135 time.sleep(3)136 self.driver.find_element(*FlightLocators.ContinueAfterContact).click()137 def traveler_details(self):138 time.sleep(3)139 self.driver.find_element(*FlightLocators.Adult1FN).send_keys("Mark")140 self.driver.find_element(*FlightLocators.Adult1LN).send_keys("Zuck")141 self.driver.find_element(*FlightLocators.Adult1G).click()142 self.driver.find_element(*FlightLocators.GenderM).click()143 self.driver.find_element(*FlightLocators.Adult2FN).send_keys("Mary")144 self.driver.find_element(*FlightLocators.Adult2LN).send_keys("Lane")145 self.driver.find_element(*FlightLocators.Adult2G).click()146 self.driver.find_element(*FlightLocators.GenderF).click()147 self.driver.find_element(*FlightLocators.ChildFN).send_keys("Rob")148 self.driver.find_element(*FlightLocators.ChildLN).send_keys("Zuck")149 self.driver.find_element(*FlightLocators.ChildG).click()150 self.driver.find_element(*FlightLocators.GenderM).click()151 self.driver.find_element(*FlightLocators.BirthD).send_keys("01/01/2012")152 time.sleep(2)153 self.driver.execute_script("window.scrollTo(0, 3000)")154 try :155 a = self.driver.find_element_by_xpath("//label/p[contains(text(),'Use GSTIN details for this booking')]/parent::label/following-sibling::div[3]/div/button")156 time.sleep(2)157 a.click()158 except StaleElementReferenceException as e :...
Engagement_unit_test.py
Source:Engagement_unit_test.py
1from selenium.webdriver.support.ui import Select2import unittest3import sys4from base_test_class import BaseTestCase5from Product_unit_test import ProductTest6class EngagementTest(BaseTestCase):7 def test_list_active_engagements(self):8 driver = self.login_page()9 self.goto_active_engagements_overview(driver)10 def test_list_all_engagements(self):11 driver = self.login_page()12 self.goto_all_engagements_overview(driver)13 def test_add_new_engagement(self):14 driver = self.login_page()15 self.goto_product_overview(driver)16 driver.find_element_by_class_name("pull-left").click()17 driver.find_element_by_link_text("Add New Engagement").click()18 driver.find_element_by_id("id_name").send_keys("test engagement")19 driver.find_element_by_id("id_name").send_keys("\tthis is engagement test.")20 driver.find_element_by_id("id_test_strategy").clear()21 driver.find_element_by_id('id_test_strategy').send_keys("http://localhost:5000")22 Select(driver.find_element_by_id("id_status")).select_by_visible_text("In Progress")23 driver.find_element_by_css_selector("input[value='Done']").click()24 self.assertTrue(self.is_success_message_present(text='Engagement added successfully.'))25 def test_edit_created_new_engagement(self):26 driver = self.login_page()27 self.goto_product_overview(driver)28 driver.find_element_by_class_name("pull-left").click()29 driver.find_element_by_link_text("View Engagements").click()30 driver.find_element_by_link_text("test engagement").click()31 driver.find_element_by_id("dropdownMenu1").click()32 driver.find_element_by_link_text("Edit Engagement").click()33 driver.find_element_by_id("id_name").clear()34 driver.find_element_by_id("id_name").send_keys("edited test engagement")35 Select(driver.find_element_by_id("id_status")).select_by_visible_text("In Progress")36 driver.find_element_by_css_selector("input[value='Done']").click()37 self.assertTrue(self.is_success_message_present(text='Engagement updated successfully.'))38 def test_close_new_engagement(self):39 driver = self.login_page()40 self.goto_product_overview(driver)41 driver.find_element_by_class_name("pull-left").click()42 driver.find_element_by_link_text("View Engagements").click()43 driver.find_element_by_link_text("edited test engagement").click()44 driver.find_element_by_id("dropdownMenu1").click()45 driver.find_element_by_link_text("Close Engagement").click()46 self.assertTrue(self.is_success_message_present(text='Engagement closed successfully.'))47 def test_delete_new_closed_engagement(self):48 driver = self.login_page()49 self.goto_product_overview(driver)50 driver.find_element_by_class_name("pull-left").click()51 driver.find_element_by_link_text('View Engagements').click()52 driver.find_element_by_link_text("edited test engagement").click()53 driver.find_element_by_id("dropdownMenu1").click()54 driver.find_element_by_link_text('Delete Engagement').click()55 driver.find_element_by_name('delete_name').click()56 self.assertTrue(self.is_success_message_present(text='Engagement and relationships removed.'))57 def test_new_ci_cd_engagement(self):58 driver = self.login_page()59 self.goto_product_overview(driver)60 # wait for product_wrapper div as datatables javascript modifies the DOM on page load.61 driver.find_element_by_id('products_wrapper')62 driver.find_element_by_link_text('QA Test').click()63 driver.find_element_by_xpath("//a[@class='dropdown-toggle active']//span[@class='hidden-xs']").click()64 driver.find_element_by_link_text('Add New CI/CD Engagement').click()65 driver.find_element_by_id("id_name").send_keys("test new ci/cd engagement")66 driver.find_element_by_id("id_name").send_keys("\ttest new ci/cd engagement")67 driver.find_element_by_id('id_deduplication_on_engagement').get_attribute('checked')68 driver.find_element_by_css_selector("input[value='Done']").click()69 self.assertTrue(self.is_success_message_present(text='Engagement added successfully.'))70def suite():71 suite = unittest.TestSuite()72 suite.addTest(ProductTest('test_create_product'))73 suite.addTest(EngagementTest('test_add_new_engagement'))74 suite.addTest(EngagementTest('test_edit_created_new_engagement'))75 suite.addTest(EngagementTest('test_close_new_engagement'))76 suite.addTest(EngagementTest('test_delete_new_closed_engagement'))77 suite.addTest(EngagementTest('test_new_ci_cd_engagement'))78 suite.addTest(ProductTest('test_delete_product'))79 return suite80if __name__ == "__main__":81 runner = unittest.TextTestRunner(descriptions=True, failfast=True, verbosity=2)82 ret = not runner.run(suite()).wasSuccessful()83 BaseTestCase.tearDownDriver()...
smoke_test.py
Source:smoke_test.py
1from selenium.webdriver.support.ui import Select2from selenium.common.exceptions import NoSuchElementException3from selenium.common.exceptions import NoAlertPresentException4import unittest5import sys6from base_test_class import BaseTestCase7class DojoTests(BaseTestCase):8 def test_login(self):9 driver = self.login_page()10 self.assertTrue(self.is_text_present_on_page(text='Active Engagements'))11 def test_create_product(self):12 driver = self.login_page()13 self.goto_product_overview(driver)14 driver.find_element_by_id("dropdownMenu1").click()15 driver.find_element_by_link_text("Add Product").click()16 driver.find_element_by_id("id_name").clear()17 driver.find_element_by_id("id_name").send_keys("QA Test")18 driver.find_element_by_id("id_description").clear()19 driver.find_element_by_id("id_description").send_keys("QA Test 1 Description")20 Select(driver.find_element_by_id("id_prod_type")).select_by_visible_text("Research and Development")21 driver.find_element_by_css_selector("input.btn.btn-primary").click()22 self.assertTrue(self.is_success_message_present(text='Product added successfully'))23 def test_engagement(self):24 driver = self.login_page()25 driver = self.driver26 self.goto_product_overview(driver)27 driver.find_element_by_link_text("Product List").click()28 driver.find_element_by_xpath("//table[@id='products']/tbody/tr[1]/td[5]/a").click()29 driver.find_element_by_id("id_pen_test").click()30 driver.find_element_by_id("id_check_list").click()31 driver.find_element_by_id("id_name").clear()32 driver.find_element_by_id("id_name").send_keys("New QA Engagement")33 driver.find_element_by_id("id_target_start").clear()34 driver.find_element_by_id("id_target_start").send_keys("2016-09-01")35 driver.find_element_by_id("id_name").click()36 driver.find_element_by_id("id_target_end").click()37 driver.find_element_by_id("id_target_end").send_keys("2016-09-02")38 driver.find_element_by_link_text("15").click()39 Select(driver.find_element_by_id("id_lead")).select_by_value("1")40 driver.find_element_by_css_selector("input[name=\"_Add Tests\"]").click()41 Select(driver.find_element_by_id("id_test_type")).select_by_visible_text("Pen Test")42 driver.find_element_by_id("id_target_start").clear()43 driver.find_element_by_id("id_target_start").send_keys("2016-09-01")44 driver.find_element_by_id("id_target_end").click()45 driver.find_element_by_link_text("22").click()46 Select(driver.find_element_by_id("id_environment")).select_by_visible_text("Development")47 driver.find_element_by_id("id_percent_complete").clear()48 driver.find_element_by_id("id_percent_complete").send_keys("50")49 driver.find_element_by_css_selector("input[name=\"_Add Findings\"]").click()50 driver.find_element_by_id("id_title").clear()51 driver.find_element_by_id("id_title").send_keys("Test Finding")52 driver.find_element_by_id("id_description").clear()53 driver.find_element_by_id("id_description").send_keys("Description")54 driver.find_element_by_id("id_mitigation").clear()55 driver.find_element_by_id("id_mitigation").send_keys("Mitigation")56 driver.find_element_by_id("id_impact").clear()57 driver.find_element_by_id("id_impact").send_keys("Impact")58 driver.find_element_by_name("_Finished").click()59 self.assertTrue(self.is_success_message_present(text='Finding added successfully'))60 def is_element_present(self, how, what):61 try:62 self.driver.find_element(by=how, value=what)63 except NoSuchElementException as e:64 return False65 return True66 def is_alert_present(self):67 try:68 self.driver.switch_to_alert()69 except NoAlertPresentException as e:70 return False71 return True72 def close_alert_and_get_its_text(self):73 try:74 alert = self.driver.switch_to_alert()75 alert_text = alert.text76 if self.accept_next_alert:77 alert.accept()78 else:79 alert.dismiss()80 return alert_text81 finally:82 self.accept_next_alert = True83def suite():84 suite = unittest.TestSuite()85 suite.addTest(DojoTests('test_login'))86 return suite87if __name__ == "__main__":88 runner = unittest.TextTestRunner(descriptions=True, failfast=True, verbosity=2)89 ret = not runner.run(suite()).wasSuccessful()90 BaseTestCase.tearDownDriver()...
Using AI Code Generation
1const mb = require('mountebank');2mb.create({3}, function (error, server) {4 if (error) {5 console.error(error);6 } else {7 }8});9const mb = require('mountebank');10mb.create({11}, function (error, server) {12 if (error) {13 console.error(error);14 } else {15 }16});17const mb = require('mountebank');18mb.create({19}, function (error, server) {20 if (error) {21 console.error(error);22 } else {23 }24});25const mb = require('mountebank');26mb.create({27}, function (error, server) {28 if (error) {29 console.error(error);30 } else {31 }32});33const mb = require('mountebank');34mb.create({
Using AI Code Generation
1var mb = require('mountebank');2mb.start({3}, function (error) {4 console.log('Error starting mountebank', error);5});6mb.stop(2525, function (error) {7 console.log('Error stopping mountebank', error);8});9mb.start({10}, function (error) {11 console.log('Error starting mountebank', error);12});13mb.stop(2525, function (error) {14 console.log('Error stopping mountebank', error);15});16mb.start({17}, function (error) {18 console.log('Error starting mountebank', error);19});20mb.stop(2525, function (error) {21 console.log('Error stopping mountebank', error);22});23mb.start({24}, function (error) {25 console.log('Error starting mountebank', error);26});27mb.stop(2525, function (error) {28 console.log('Error stopping mountebank', error);29});30mb.start({31}, function (error) {32 console.log('Error starting mountebank', error);33});34mb.stop(2525, function (error) {35 console.log('Error stopping mountebank', error);36});37mb.start({38}, function (error) {39 console.log('Error starting mountebank', error);40});41mb.stop(2525, function (error) {42 console.log('Error stopping mountebank', error);43});44mb.start({
Using AI Code Generation
1var driver = require('mountebank').createDriver();2driver.create({3}, function () {4});5driver.getImposters(function (err, imposters) {6});7driver.deleteImposter(2525, function (err) {8});9driver.deleteAllImposters(function (err) {10});11driver.deleteAllRequests(function (err) {12});13driver.addStub(2525, { responses: [{ is: { body: 'Hello, World!' } }] }, function (err) {14});15driver.getRequests(2525, function (err, requests) {16});17driver.deleteRequest(2525, 0, function (err) {18});19driver.getLogs(function (err, logs) {20});21driver.deleteLog(function (err) {22});23driver.getMetadata(function (err, metadata) {24});25driver.deleteMetadata(function (err) {26});27driver.close(function () {28});29var driver = require('mountebank').createDriver();30driver.create({31}, function () {32});33driver.getImposters(function (err, imposters) {34});35driver.deleteImposter(2525, function (err) {36});37driver.deleteAllImposters(function (err) {38});39driver.deleteAllRequests(function (err) {40});41driver.addStub(2525, { responses: [{ is: { body: 'Hello, World!' } }] }, function (err) {42});43driver.getRequests(2525, function (err, requests) {44});45driver.deleteRequest(2525, 0, function (err) {46});47driver.getLogs(function (err, logs) {
Using AI Code Generation
1var mb = require('mountebank');2var port = 2525;3var protocol = 'http';4var host = 'localhost';5mb.create(port, protocol, host, function (error, imposter) {6 if (error) {7 console.log('Error creating imposter: ' + error.message);8 } else {9 console.log('Imposter created on port %s', imposter.port);10 }11});
Using AI Code Generation
1var driver = require('mountebank-driver');2var assert = require('assert');3var request = require('supertest');4var chai = require('chai');5var chaiHttp = require('chai-http');6var chaiAsPromised = require('chai-as-promised');7var chaiJson = require('chai-json');8var chaiThings = require('chai-things');9var chaiString = require('chai-string');10var chaiFuzzy = require('chai-fuzzy');11var chaiArrays = require('chai-arrays');12var chaiMatch = require('chai-match');13var chaiDatetime = require('chai-datetime');14var chaiSpies = require('chai-spies');15var chaiFs = require('chai-fs');16var chaiXml = require('chai-xml');17var chaiJquery = require('chai-jquery');18var chaiLike = require('chai-like');19var chaiThings = require('chai-things');20var chaiXml = require('chai-xml');21var chaiJquery = require('chai-jquery');22var chaiLike = require('chai-like');23var chaiThings = require('chai-things');24var chaiXml = require('chai-xml');25var chaiJquery = require('chai-jquery');26var chaiLike = require('chai-like');27var chaiThings = require('chai-things');28var chaiXml = require('chai-xml');29var chaiJquery = require('chai-jquery');
Using AI Code Generation
1var mb = require('mountebank');2var webdriverio = require('webdriverio');3var chai = require('chai');4var expect = chai.expect;5var chaiAsPromised = require('chai-as-promised');6chai.use(chaiAsPromised);
Using AI Code Generation
1var driver = require('mountebank').createDriver({port: 2525});2var mb = require('mountebank');3var mbHelper = require('mountebank-helper');4describe('mbHelper', function () {5 var mbServer = mb.create({port: 2525});6 var mbHelperServer = mbHelper.create({port: 2525});7 before(function (done) {8 mbServer.start(done);9 });10 after(function (done) {11 mbServer.stop(done);12 });13 it('should return a response', function (done) {14 mbHelperServer.addStub({15 {16 equals: {17 }18 }19 {20 is: {21 headers: {22 },23 body: JSON.stringify({test: true})24 }25 }26 }, function () {27 assert.equal(response.statusCode, 200);28 assert.equal(response.body, JSON.stringify({test: true}));29 done();30 });31 });32 });33});34describe('driver', function () {35 before(function (done) {36 mbServer.start(done);37 });38 after(function (done) {39 mbServer.stop(done);40 });41 it('should return a response', function (done) {42 mbHelperServer.addStub({43 {44 equals: {45 }46 }47 {48 is: {49 headers: {50 },51 body: JSON.stringify({test: true})52 }53 }54 }, function () {55 assert.equal(response.statusCode, 200);56 assert.equal(response.body, JSON.stringify({test: true}));57 done();58 });59 });60 });61});
Using AI Code Generation
1const { create } = require("mountebank");2const { driver } = require("mountebank");3const { createLogger } = require("bunyan");4const logger = createLogger({ name: "mb" });5 {6 {7 {8 is: {9 headers: {10 },11 },12 },13 },14 },15];16const driverConfig = {17};18const mb = driver.create(logger, driverConfig);19mb.start()20 .then(() => mb.post("/imposters", imposters))21 .then(() => mb.get("/imposters"))22 .then((response) => console.log(response.body))23 .then(() => mb.stop())24 .catch((error) => console.error(error));25{26 "scripts": {27 },28 "dependencies": {29 }30}31[ { port: 3000, protocol: 'http', stubs: [ [Object] ], _links: [Object] } ]
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!