How to use activate_messenger method in SeleniumBase

Best Python code snippet using SeleniumBase

js_utils.py

Source:js_utils.py Github

copy

Full Screen

...400 except Exception:401 time.sleep(0.1)402 wait_for_ready_state_complete(driver)403 wait_for_angularjs(driver)404def activate_messenger(driver):405 jquery_js = constants.JQuery.MIN_JS406 messenger_css = constants.Messenger.MIN_CSS407 messenger_js = constants.Messenger.MIN_JS408 msgr_theme_flat_js = constants.Messenger.THEME_FLAT_JS409 msgr_theme_future_js = constants.Messenger.THEME_FUTURE_JS410 msgr_theme_flat_css = constants.Messenger.THEME_FLAT_CSS411 msgr_theme_future_css = constants.Messenger.THEME_FUTURE_CSS412 msgr_theme_block_css = constants.Messenger.THEME_BLOCK_CSS413 msgr_theme_air_css = constants.Messenger.THEME_AIR_CSS414 msgr_theme_ice_css = constants.Messenger.THEME_ICE_CSS415 spinner_css = constants.Messenger.SPINNER_CSS416 underscore_js = constants.Underscore.MIN_JS417 backbone_js = constants.Backbone.MIN_JS418 msg_style = ("Messenger.options = {'maxMessages': 8, "419 "extraClasses: 'messenger-fixed "420 "messenger-on-bottom messenger-on-right', "421 "theme: 'future'}")422 add_js_link(driver, jquery_js)423 wait_for_jquery_active(driver, timeout=0.2)424 add_css_link(driver, messenger_css)425 add_css_link(driver, msgr_theme_flat_css)426 add_css_link(driver, msgr_theme_future_css)427 add_css_link(driver, msgr_theme_block_css)428 add_css_link(driver, msgr_theme_air_css)429 add_css_link(driver, msgr_theme_ice_css)430 add_js_link(driver, underscore_js)431 add_js_link(driver, backbone_js)432 add_css_link(driver, spinner_css)433 add_js_link(driver, messenger_js)434 add_js_link(driver, msgr_theme_flat_js)435 add_js_link(driver, msgr_theme_future_js)436 from seleniumbase.core import style_sheet437 add_css_style(driver, style_sheet.messenger_style)438 for x in range(int(settings.MINI_TIMEOUT * 10.0)):439 # Messenger needs a small amount of time to load & activate.440 try:441 driver.execute_script(msg_style)442 wait_for_ready_state_complete(driver)443 wait_for_angularjs(driver)444 return445 except Exception:446 time.sleep(0.1)447def set_messenger_theme(driver, theme="default", location="default",448 max_messages="default"):449 if theme == "default":450 theme = "future"451 if location == "default":452 location = "bottom_right"453 if max_messages == "default":454 max_messages = "8"455 valid_themes = ['flat', 'future', 'block', 'air', 'ice']456 if theme not in valid_themes:457 raise Exception("Theme: %s is not in %s!" % (theme, valid_themes))458 valid_locations = (['top_left', 'top_center', 'top_right'459 'bottom_left', 'bottom_center', 'bottom_right'])460 if location not in valid_locations:461 raise Exception(462 "Location: %s is not in %s!" % (location, valid_locations))463 if location == 'top_left':464 messenger_location = "messenger-on-top messenger-on-left"465 elif location == 'top_center':466 messenger_location = "messenger-on-top"467 elif location == 'top_right':468 messenger_location = "messenger-on-top messenger-on-right"469 elif location == 'bottom_left':470 messenger_location = "messenger-on-bottom messenger-on-left"471 elif location == 'bottom_center':472 messenger_location = "messenger-on-bottom"473 elif location == 'bottom_right':474 messenger_location = "messenger-on-bottom messenger-on-right"475 msg_style = ("Messenger.options = {'maxMessages': %s, "476 "extraClasses: 'messenger-fixed %s', theme: '%s'}"477 % (max_messages, messenger_location, theme))478 try:479 driver.execute_script(msg_style)480 except Exception:481 activate_messenger(driver)482 driver.execute_script(msg_style)483 time.sleep(0.1)484def post_message(driver, message, msg_dur, style="info"):485 """ A helper method to post a message on the screen with Messenger.486 (Should only be called from post_message() in base_case.py) """487 if not msg_dur:488 msg_dur = settings.DEFAULT_MESSAGE_DURATION489 msg_dur = float(msg_dur)490 message = re.escape(message)491 message = escape_quotes_if_needed(message)492 messenger_script = ('''Messenger().post({message: "%s", type: "%s", '''493 '''hideAfter: %s, hideOnNavigate: true});'''494 % (message, style, msg_dur))495 try:496 driver.execute_script(messenger_script)497 except Exception:498 activate_messenger(driver)499 set_messenger_theme(driver)500 try:501 driver.execute_script(messenger_script)502 except Exception:503 time.sleep(0.2)504 activate_messenger(driver)505 time.sleep(0.2)506 set_messenger_theme(driver)507 time.sleep(0.5)508 driver.execute_script(messenger_script)509def post_messenger_success_message(driver, message, msg_dur):510 if not msg_dur:511 msg_dur = settings.DEFAULT_MESSAGE_DURATION512 msg_dur = float(msg_dur)513 try:514 theme = "future"515 location = "bottom_right"516 if sb_config.mobile_emulator:517 theme = "block"518 location = "top_center"...

Full Screen

Full Screen

messenger.py

Source:messenger.py Github

copy

Full Screen

...8 from sel4.core.webdriver_test import WebDriverTest9class Messenger:10 def __init__(self, test: "WebDriverTest"):11 self.test = test12 def activate_messenger(self):13 self.__check_scope()14 self.__check_browser()15 js_utils.activate_messenger(self.driver)16 self.wait_for_ready_state_complete()17 def set_messenger_theme(18 self, theme="default", location="default", max_messages="default"19 ):20 """Sets a theme for posting messages.21 Themes: ["flat", "future", "block", "air", "ice"]22 Locations: ["top_left", "top_center", "top_right",23 "bottom_left", "bottom_center", "bottom_right"]24 max_messages is the limit of concurrent messages to display.25 """26 self.__check_scope()27 self.__check_browser()28 if not theme:29 theme = "default" # "flat"...

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run SeleniumBase automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful