Skip to content

Commit

Permalink
selenium: raise exception when browser does not start
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Oct 7, 2024
1 parent 711f812 commit 305286b
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 55 deletions.
2 changes: 1 addition & 1 deletion automon/integrations/seleniumWrapper/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def run(self) -> bool:
return run
except Exception as exception:
logger.error(f'webdriver :: run :: failed :: {exception=}')
return False
raise Exception(f'webdriver :: run :: failed :: {exception=}')

def save_cookies_for_current_url(self) -> bool:
"""save cookies for current url"""
Expand Down
39 changes: 21 additions & 18 deletions automon/integrations/seleniumWrapper/tests/test_browser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import unittest


from automon.integrations.seleniumWrapper import SeleniumBrowser, ChromeWrapper

browser = SeleniumBrowser()
Expand All @@ -9,29 +8,33 @@


class SeleniumClientTest(unittest.TestCase):
if browser.run():
try:
if browser.run():

def test_fake_page(self):
self.assertFalse(browser.get('http://555.555.555.555'))
def test_fake_page(self):
self.assertFalse(browser.get('http://555.555.555.555'))

def test_real_page(self):
if browser.get('http://1.1.1.1'):
self.assertTrue(True)
def test_real_page(self):
if browser.get('http://1.1.1.1'):
self.assertTrue(True)

def test_screenshot_png(self):
if browser.get('http://google.com'):
self.assertTrue(browser.get_screenshot_as_png())
def test_screenshot_png(self):
if browser.get('http://google.com'):
self.assertTrue(browser.get_screenshot_as_png())

def test_screenshot_base64(self):
if browser.get('http://yahoo.com'):
self.assertTrue(browser.get_screenshot_as_base64())
def test_screenshot_base64(self):
if browser.get('http://yahoo.com'):
self.assertTrue(browser.get_screenshot_as_base64())

def test_screenshot_file(self):
if browser.get('http://bing.com'):
self.assertTrue(browser.save_screenshot())
self.assertTrue(browser.save_screenshot(folder='./'))
def test_screenshot_file(self):
if browser.get('http://bing.com'):
self.assertTrue(browser.save_screenshot())
self.assertTrue(browser.save_screenshot(folder='./'))

browser.quit()
browser.quit()

except:
pass


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import unittest


from automon.integrations.seleniumWrapper import SeleniumBrowser, ChromeWrapper

browser = SeleniumBrowser()
browser.config.webdriver_wrapper = ChromeWrapper()
browser.config.webdriver_wrapper.enable_defaults().enable_headless()

class Test(unittest.TestCase):
browser = SeleniumBrowser()
browser.config.webdriver_wrapper = ChromeWrapper()
browser.config.webdriver_wrapper.enable_defaults().enable_headless()

# if browser.run():
browser.run()
class Test(unittest.TestCase):
try:
if browser.run():

def test_autosave(self):
if self.browser.run():
def test_autosave(self):
if browser.get('http://bing.com'):
self.assertTrue(browser.autosave_cookies())

if self.browser.get('http://bing.com'):
self.assertTrue(self.browser.autosave_cookies())
browser.quit()

self.browser.quit()
except:
pass


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import unittest


from automon.integrations.seleniumWrapper import SeleniumBrowser, ChromeWrapper

browser = SeleniumBrowser()
Expand All @@ -9,18 +8,22 @@


class SeleniumClientTest(unittest.TestCase):
if browser.run():
try:
if browser.run():

def test(self):
def test(self):

if browser.get('http://1.1.1.1'):
if browser.get('http://1.1.1.1'):

if browser.check_page_load_finished():
self.assertTrue(browser.save_screenshot())
self.assertTrue(browser.save_screenshot(folder='./'))
if browser.check_page_load_finished():
self.assertTrue(browser.save_screenshot())
self.assertTrue(browser.save_screenshot(folder='./'))

browser.quit()

except:
pass


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import unittest


from automon.integrations.seleniumWrapper import SeleniumBrowser, ChromeWrapper

browser = SeleniumBrowser()
Expand All @@ -13,10 +12,14 @@


class SeleniumClientTest(unittest.TestCase):
if browser.run():
def test_user_agent(self):
self.assertEqual(browser.user_agent, agent)
try:
if browser.run():
def test_user_agent(self):
self.assertEqual(browser.user_agent, agent)

browser.quit()
except:
pass


if __name__ == '__main__':
Expand Down
21 changes: 12 additions & 9 deletions automon/integrations/seleniumWrapper/tests/test_logs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import unittest


from automon.integrations.seleniumWrapper import SeleniumBrowser, ChromeWrapper

browser = SeleniumBrowser()
Expand All @@ -9,20 +8,24 @@


class SeleniumClientTest(unittest.TestCase):
if browser.run():
try:
if browser.run():

def test_logs(self):
def test_logs(self):

if browser.get('http://binance.com'):
logs = browser.get_log_performance()
logs = browser.get_log_browser()
logs = browser.get_log_driver()
logs = browser.get_logs()
if browser.get('http://binance.com'):
logs = browser.get_log_performance()
logs = browser.get_log_browser()
logs = browser.get_log_driver()
logs = browser.get_logs()

pass
pass

browser.quit()

except:
pass


if __name__ == '__main__':
unittest.main()
13 changes: 9 additions & 4 deletions automon/integrations/seleniumWrapper/tests/test_new_browser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import unittest


from automon.integrations.seleniumWrapper import SeleniumBrowser, ChromeWrapper

browser = SeleniumBrowser()
Expand All @@ -9,9 +8,15 @@


class SeleniumClientTest(unittest.TestCase):
if browser.run():
def test(self):
self.assertTrue(browser.quit())
try:
if browser.run():
def test(self):
self.assertTrue(browser.quit())

browser.quit()

except:
pass


if __name__ == '__main__':
Expand Down

0 comments on commit 305286b

Please sign in to comment.