def download_firefox(cls, url, installer): if not file.download_file(url=url, file=installer): log.error( '[Firefox] Failed to download firefox installer from website') return 0 log.info("[Firefox] Downloaded firefox from website successfully!") return 1
def mount(cls, installer): cmd = 'sudo hdiutil attach {}'.format(installer) if not cls.run(cmd): log.error("[FireFox] Failed to mount volume") return 0 log.info("[Firefox] Firefox volume mounted successfully!") return 1
def install(cls): cmd = 'sudo cp -R /Volumes/Firefox/Firefox.app/ /Applications/Firefox.app' if not cls.run(cmd): log.error( "[FireFox] Failed to copy Firefox.app to Applications folder") return 0 log.info("[Firefox] Firefox installed successfully!") return 1
def capture_screen(path=None, filename='screen_print'): if not path: path = variables.SCREENSHOT_PATH filename = path + filename cmd = 'screencapture {}.png'.format(filename) sleep(1) if not Command.run(cmd): log.error("Failed to capture screen") return 0 log.info("Captured screen: " + filename) return 1
def wait_for_object(driver, id=None): if _is_element_located(driver, By.LINK_TEXT, id): return 1 elif _is_element_located(driver, By.XPATH, id): return 1 elif _is_element_located(driver, By.TAG_NAME, id): return 1 elif _is_element_located(driver, By.NAME, id): return 1 elif _is_element_located(driver, By.ID, id): return 1 elif _is_element_located(driver, By.PARTIAL_LINK_TEXT, id): return 1 elif _is_element_located(driver, By.CSS_SELECTOR, id): return 1 elif _is_element_located(driver, By.CLASS_NAME, id): return 1 log.error("[WebDriver] Element not found: '{}'".format(id)) return 0
def execute_step_validate(func, summary, expected_output=(1,), exception=Exception, exception_msg='', *args, **kwargs): """ @brief Executes the given function and validates result @param func Method to be executed @param summary Step summary @param expected_output Tuple of elements to be validated against result @param exception Name of the exception to be thrown @param exception_msg Exception message while throwing @param args List of arguments @param kwargs Keyword arguments """ stars = (len(summary) + 25) * "*" log.info(stars) log.info("Method : " + func.__name__) log.info("Summary : " + summary) log.info("Arguments : " + str(args)) log.info("Keyword args : " + str(kwargs)) log.info(stars) # Force tuple the expected output if not in type tuple or list if not isinstance(expected_output, tuple) or not isinstance(expected_output, list): expected_output = (expected_output,) try: result = func(*args, **kwargs) if result not in expected_output: log.error("Result '{}' not in expected output '{}'".format(result, expected_output)) if not exception_msg: exception_msg = "Result '{}' not in expected output '{}'".format(result, expected_output) raise exception(exception_msg) log.info(log.error("Result '{}' is present in expected output '{}'".format(result, expected_output))) finally: log.info("Completed step: '{}'".format(summary))
def check_installation(cls): found = 0 cmd = 'open -a Firefox' log.info("[Firefox] Starting firefox...") if not cls.run(cmd): log.info("[Firefox] Failed to open firefox") return 0 try: firefox = atomac.getAppRefByBundleId(BID_FIREFOX) found = 1 firefox.activate() sleep(5) capture_screen('firefox_install_success') sleep(2) atomac.terminateAppByBundleId(BID_FIREFOX) log.info("[Firefox] Firefox launched successfully!") except ValueError: log.error("[Firefox] Firefox not running!") return found
def install_firefox(cls, installer=None, remove=False): if not installer: log.error( "Need to specify the installer file to proceed with installation" ) return 0 if remove and cls.is_installed(): if not cls.uninstall(): return 0 if not cls.mount(installer=installer): return 0 sleep(2) if not cls.install(): return 0 sleep(2) if not cls.un_mount(): return 0 sleep(2) return cls.check_installation()