test(unit_test_data): web driver to be class obj

Set back to be a class object so that if an exception occurs  the object
can still be removed and cleared.

MR !4
This commit is contained in:
2022-01-28 12:04:15 +09:30
parent f77363beea
commit e1d3a33418

View File

@ -55,7 +55,7 @@ class Data:
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("window-size=1900,1080");
driver = webdriver.Chrome(desired_capabilities=caps, options=chrome_options)
self.driver = webdriver.Chrome(desired_capabilities=caps, options=chrome_options)
self.urls = []
self.suffux_path = os.path.realpath('./build')
@ -77,9 +77,9 @@ class Data:
if source_file not in data['source_files']:
data['source_files'].append(source_file)
driver.get(check_url)
self.driver.get(check_url)
links = driver.find_elements_by_css_selector("a")
links = self.driver.find_elements_by_css_selector("a")
for link in links:
@ -101,7 +101,7 @@ class Data:
data['hyperlinks'][link['url_id']] = link
events = [self.process_browser_log_entry(entry) for entry in driver.get_log('performance')]
events = [self.process_browser_log_entry(entry) for entry in self.driver.get_log('performance')]
for entry in events:
@ -145,11 +145,14 @@ class Data:
else:
data['page_load_resource_links'][url_id] = {'url': url, 'request_protocol': request_protocol, 'domain': domain, 'request_path': request_path, 'source_files': [ {'name': source_file, 'line_number': source_file_line_number, 'http_status': http_status} ]}
driver.close()
self.driver.quit()
self.test_data = data
def __del__(self):
self.driver.quit()
print("\n"+'Creating test data')
print("\n\ntest data:\n" + json.dumps(Data().test_data, indent=2, default=str))