class SaunterTestCase(BaseTestCase): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ def setup_method(self, method): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ self.verificationErrors = [] self.cf = saunter.ConfigWrapper.ConfigWrapper().config self.config = self.cf if self.cf.getboolean("SauceLabs", "ondemand"): desired_capabilities = { "platform": self.cf.get("SauceLabs", "os"), "browserName": self.cf.get("SauceLabs", "browser"), "version": self.cf.get("SauceLabs", "browser_version"), "name": self._testMethodName } if desired_capabilities["browserName"][0] == "*": desired_capabilities["browserName"] = desired_capabilities["browserName"][1:] if desired_capabilities["platform"] in os_map: desired_capabilities["platform"] = os_map[desired_capabilities["platform"]] command_executor = "http://%s:%[email protected]:80/wd/hub" % (self.cf.get("SauceLabs", "username"), self.cf.get("SauceLabs", "key")) else: browser = self.cf.get("Selenium", "browser") if browser[0] == "*": browser = browser[1:] if browser == "chrome": os.environ["webdriver.chrome.driver"] = self.cf.get("Selenium", "chromedriver_path") desired_capabilities = capabilities_map[browser] if self.cf.has_section("Proxy") \ and self.cf.has_option("Proxy", "proxy_url") \ and (self.cf.has_option("Proxy", "browsermob") and self.cf.getboolean("Proxy", "browsermob")): from browsermobproxy import Client self.client = Client(self.cf.get("Proxy", "proxy_url")) self.client.add_to_webdriver_capabilities(desired_capabilities) if self.cf.has_section("Grid"): if self.cf.getboolean("Grid", "use_grid") and self.cf.get("Grid", "type") == "selenium": if self.cf.has_option("Grid", "platform"): desired_capabilities["platform"] = self.cf.get("Grid", "platform").upper() if self.cf.has_option("Grid", "version"): desired_capabilities["version"] = str(self.cf.get("Grid", "browser_version")) command_executor = "http://%s:%s/wd/hub" % (self.cf.get("Selenium", "server_host"), self.cf.get("Selenium", "server_port")) self.driver = WebDriver(desired_capabilities = desired_capabilities, command_executor = command_executor) if self.cf.getboolean("Saunter", "use_implicit_wait"): self.driver.implicitly_wait(self.cf.getint("Saunter", "implicit_wait")) if self.cf.getboolean("SauceLabs", "ondemand"): self.sauce_session = self.driver.session_id def teardown_method(self, method): """ Default teardown method for all scripts. If run through Sauce Labs OnDemand, the job name, status and tags are updated. Also the video and server log are downloaded if so configured. """ if hasattr(self, "driver"): self.driver.quit() if hasattr(self, "cf") and self.cf.getboolean("SauceLabs", "ondemand"): # session couldn't be established for some reason if not hasattr(self, "sauce_session"): return sauce_session = self.sauce_session j = {} # name j["name"] = self._testMethodName # result if self._resultForDoCleanups._excinfo == None and not self.verificationErrors: # print("pass") j["passed"] = True else: # print("fail") j["passed"] = False # tags j["tags"] = [] for keyword in self._resultForDoCleanups.keywords: if isinstance(self._resultForDoCleanups.keywords[keyword], MarkInfo): j["tags"].append(keyword) # update which_url = "https://saucelabs.com/rest/v1/%s/jobs/%s" % (self.cf.get("SauceLabs", "username"), sauce_session) r = requests.put(which_url, data=json.dumps(j), headers={"Content-Type": "application/json"}, auth=(self.cf.get("SauceLabs", "username"), self.cf.get("SauceLabs", "key"))) r.raise_for_status() if self.cf.getboolean("SauceLabs", "get_video"): self.fetch_sauce_artifact("video.flv") if self.cf.getboolean("SauceLabs", "get_log"): self.fetch_sauce_artifact("selenium-server.log") # def fetch_artifact(session, which): # which_url = "https://saucelabs.com/rest/%s/jobs/%s/results/%s" % (self.cf.get("SauceLabs", "username"), session, which) # code = 404 # timeout = 0 # while code in [401, 404]: # r = requests.get(which_url, auth = (cf.get("SauceLabs", "username"), self.cf.get("SauceLabs", "key"))) # try: # code = r.status_code # r.raise_for_status() # except urllib2.HTTPError, e: # time.sleep(4) # # artifact = open(os.path.join(os.path.dirname(__file__), "logs", which), "wb") # artifact.write(r.content)
class SaunterTestCase(BaseTestCase): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ def setup_method(self, method): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ self.cf = saunter.ConfigWrapper.ConfigWrapper().config self.config = self.cf self.current_method_name = method.__name__ if self.cf.getboolean("SauceLabs", "ondemand"): desired_capabilities = { "platform": self.cf.get("SauceLabs", "os"), "browserName": self.cf.get("SauceLabs", "browser"), "version": self.cf.get("SauceLabs", "browser_version"), "name": method.__name__ } if desired_capabilities["browserName"][0] == "*": desired_capabilities["browserName"] = desired_capabilities["browserName"][1:] if desired_capabilities["platform"] in os_map: desired_capabilities["platform"] = os_map[desired_capabilities["platform"]] command_executor = "http://%s:%[email protected]:80/wd/hub" % (self.cf.get("SauceLabs", "username"), self.cf.get("SauceLabs", "key")) else: browser = self.cf.get("Selenium", "browser") if browser[0] == "*": browser = browser[1:] if browser == "chrome": os.environ["webdriver.chrome.driver"] = self.cf.get("Selenium", "chromedriver_path") desired_capabilities = capabilities_map[browser] if self.cf.has_section("Proxy") \ and self.cf.has_option("Proxy", "proxy_url") \ and (self.cf.has_option("Proxy", "browsermob") and self.cf.getboolean("Proxy", "browsermob")): from browsermobproxy import Client self.client = Client(self.cf.get("Proxy", "proxy_url")) self.client.add_to_webdriver_capabilities(desired_capabilities) if self.cf.has_section("Grid"): if self.cf.getboolean("Grid", "use_grid") and self.cf.get("Grid", "type") == "selenium": if self.cf.has_option("Grid", "platform"): desired_capabilities["platform"] = self.cf.get("Grid", "platform").upper() if self.cf.has_option("Grid", "version"): desired_capabilities["version"] = str(self.cf.get("Grid", "browser_version")) command_executor = "http://%s:%s/wd/hub" % (self.cf.get("Selenium", "server_host"), self.cf.get("Selenium", "server_port")) self.driver = WebDriver(desired_capabilities = desired_capabilities, command_executor = command_executor) self.verificationErrors = [] self.matchers = Matchers(self.driver, self.verificationErrors) if self.cf.getboolean("SauceLabs", "ondemand"): self.sauce_session = self.driver.session_id self._screenshot_number = 1 def teardown_method(self, method): """ Default teardown method for all scripts. If run through Sauce Labs OnDemand, the job name, status and tags are updated. Also the video and server log are downloaded if so configured. """ if hasattr(self, "config") and not self.config.getboolean("SauceLabs", "ondemand"): self.take_named_screenshot("final") if hasattr(self, "driver"): self.driver.quit() def take_numbered_screenshot(self): if self.config.has_option("Saunter", "take_screenshots"): if self.cf.getboolean("Saunter", "take_screenshots"): method_dir = self._screenshot_prep_dirs() self.driver.get_screenshot_as_file(os.path.join(method_dir, str(self._screenshot_number).zfill(3) + ".png")) self._screenshot_number = self._screenshot_number + 1 def take_named_screenshot(self, name): method_dir = self._screenshot_prep_dirs() self.driver.get_screenshot_as_file(os.path.join(method_dir, str(name) + ".png"))
class Browser(TailoredWebDriver): def __init__(self, browser_config, all_config): self.browser_config = browser_config self.config = all_config profile = None if browser_config["type"] == 'firefox': if browser_config["profiles"][sys.platform]: profile_path = os.path.join( self.config["saunter"]["base"], 'support', 'profiles', browser_config["profiles"][sys.platform]) elif browser_config["profiles"]["profile"]: profile_path = os.path.join( self.config["saunter"]["base"], 'support', 'profiles', browser_config["profiles"]["profile"]) else: profile_path = None if profile_path: if os.path.isdir(profile_path): profile = FirefoxProfile(profile_path) else: raise ProfileNotFound("Profile not found at %s" % profile_path) if browser_config["sauce labs"]["ondemand"]: desired_capabilities = { "platform": browser_config["sauce labs"]["os"], "browserName": browser_config["type"], "version": browser_config["sauce labs"]["version"], } if desired_capabilities["platform"] in os_map: desired_capabilities["platform"] = os_map[ desired_capabilities["platform"]] if browser_config['sauce labs']['selenium version']: desired_capabilities['selenium-version'] = browser[ 'sauce labs']['selenium version'] if "disable" in self.config["sauce labs"] and self.config[ "sauce labs"]["disable"] is not None: if "record video" in self.config["sauce labs"]["disable"]: if self.config["sauce labs"]["disable"][ "record video"] == True: desired_capabilities['record-video'] = False if "upload video on pass" in self.config["sauce labs"][ "disable"]: if self.config["sauce labs"]["disable"][ "upload video on pass"] == True: desired_capabilities['video-upload-on-pass'] = False if "step screenshots" in self.config["sauce labs"]["disable"]: if self.config["sauce labs"]["disable"][ "step screenshots"] == True: desired_capabilities['record-screenshots'] = False if "sauce advisor" in self.config["sauce labs"]["disable"]: if self.config["sauce labs"]["disable"][ "sauce advisor"] == True: desired_capabilities['sauce-advisor'] = False if "enable" in self.config["sauce labs"] and self.config[ "sauce labs"]["enable"] is not None: if "source capture" in self.config["sauce labs"]["enable"]: if self.config["sauce labs"]["enable"][ "source capture"] == True: desired_capabilities['source capture'] = True if "error screenshots" in self.config["sauce labs"]["enable"]: if self.config["sauce labs"]["enable"][ "error screenshots"] == True: desired_capabilities[ 'webdriver.remote.quietExceptions'] = True command_executor = "http://%s:%[email protected]:80/wd/hub" % ( self.config["sauce labs"]["username"], self.config["sauce labs"]["key"]) else: desired_capabilities = capabilities_map[browser_config["type"]] if browser_config["proxy"]["type"] and browser_config["proxy"][ "type"].lower() == "browsermob": from browsermobproxy import Client self.client = Client(self.config.get("Proxy", "proxy_url")) self.client.add_to_webdriver_capabilities(desired_capabilities) if "is grid" in self.config["selenium"] and self.config[ "selenium"]["executor"]["is grid"]: if browser_config["grid filters"]["platform"]: desired_capabilities["platform"] = browser_config[ "grid filters"]["platform"].upper() if browser_config["grid filters"]["version"]: desired_capabilities["platform"] = str( browser_config["grid filters"]["version"]) command_executor = "http://%s:%s/wd/hub" % ( self.config["selenium"]["executor"]["host"], self.config["selenium"]["executor"]["port"]) # print(desired_capabilities) self.driver = TailoredWebDriver( desired_capabilities=desired_capabilities, command_executor=command_executor, browser_profile=profile)
class SaunterTestCase(BaseTestCase): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ def setup_method(self, method): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ self.verificationErrors = [] self.cf = saunter.ConfigWrapper.ConfigWrapper().config self.config = self.cf if self.cf.getboolean("SauceLabs", "ondemand"): desired_capabilities = { "platform": self.cf.get("SauceLabs", "os"), "browserName": self.cf.get("SauceLabs", "browser"), "version": self.cf.get("SauceLabs", "browser_version"), "name": self._testMethodName } if desired_capabilities["browserName"][0] == "*": desired_capabilities["browserName"] = desired_capabilities[ "browserName"][1:] if desired_capabilities["platform"] in os_map: desired_capabilities["platform"] = os_map[ desired_capabilities["platform"]] command_executor = "http://%s:%[email protected]:80/wd/hub" % ( self.cf.get("SauceLabs", "username"), self.cf.get("SauceLabs", "key")) else: browser = self.cf.get("Selenium", "browser") if browser[0] == "*": browser = browser[1:] if browser == "chrome": os.environ["webdriver.chrome.driver"] = self.cf.get( "Selenium", "chromedriver_path") desired_capabilities = capabilities_map[browser] if self.cf.has_section("Proxy") \ and self.cf.has_option("Proxy", "proxy_url") \ and (self.cf.has_option("Proxy", "browsermob") and self.cf.getboolean("Proxy", "browsermob")): from browsermobproxy import Client self.client = Client(self.cf.get("Proxy", "proxy_url")) self.client.add_to_webdriver_capabilities(desired_capabilities) if self.cf.has_section("Grid"): if self.cf.getboolean("Grid", "use_grid") and self.cf.get( "Grid", "type") == "selenium": if self.cf.has_option("Grid", "platform"): desired_capabilities["platform"] = self.cf.get( "Grid", "platform").upper() if self.cf.has_option("Grid", "version"): desired_capabilities["version"] = str( self.cf.get("Grid", "browser_version")) command_executor = "http://%s:%s/wd/hub" % (self.cf.get( "Selenium", "server_host"), self.cf.get("Selenium", "server_port")) self.driver = WebDriver(desired_capabilities=desired_capabilities, command_executor=command_executor) if self.cf.getboolean("Saunter", "use_implicit_wait"): self.driver.implicitly_wait( self.cf.getint("Saunter", "implicit_wait")) if self.cf.getboolean("SauceLabs", "ondemand"): self.sauce_session = self.driver.session_id def teardown_method(self, method): """ Default teardown method for all scripts. If run through Sauce Labs OnDemand, the job name, status and tags are updated. Also the video and server log are downloaded if so configured. """ if hasattr(self, "driver"): self.driver.quit() if hasattr(self, "cf") and self.cf.getboolean("SauceLabs", "ondemand"): # session couldn't be established for some reason if not hasattr(self, "sauce_session"): return sauce_session = self.sauce_session j = {} # name j["name"] = self._testMethodName # result if self._resultForDoCleanups._excinfo == None and not self.verificationErrors: # print("pass") j["passed"] = True else: # print("fail") j["passed"] = False # tags j["tags"] = [] for keyword in self._resultForDoCleanups.keywords: if isinstance(self._resultForDoCleanups.keywords[keyword], MarkInfo): j["tags"].append(keyword) # update which_url = "https://saucelabs.com/rest/v1/%s/jobs/%s" % ( self.cf.get("SauceLabs", "username"), sauce_session) r = requests.put(which_url, data=json.dumps(j), headers={"Content-Type": "application/json"}, auth=(self.cf.get("SauceLabs", "username"), self.cf.get("SauceLabs", "key"))) r.raise_for_status() if self.cf.getboolean("SauceLabs", "get_video"): self.fetch_sauce_artifact("video.flv") if self.cf.getboolean("SauceLabs", "get_log"): self.fetch_sauce_artifact("selenium-server.log")
class SaunterTestCase(BaseTestCase): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ def setup_method(self, method): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ self.cf = self.config = saunter.ConfigWrapper.ConfigWrapper() self.current_method_name = method.__name__ browser = self.cf["browsers"][self.cf["saunter"]["default_browser"]] if browser["type"][0] == "*": browser = browser["type"] = browser["type"][1:] profile = None if browser["type"] == 'firefox': if browser["profiles"][sys.platform]: profile_path = os.path.join(self.cf["saunter"]["base"], 'support', 'profiles', browser["profiles"][sys.platform]) elif browser["profiles"]["profile"]: profile_path = os.path.join(self.cf["saunter"]["base"], 'support', 'profiles', browser["profiles"]["profile"]) else: profile_path = None if profile_path: if os.path.isdir(profile_path): profile = FirefoxProfile(profile_path) else: raise ProfileNotFound("Profile not found at %s" % profile_path) if "saucelabs" in browser and browser["saucelabs"]["ondemand"]: desired_capabilities = { "platform": self.cf["sauceLabs"]["os"], "browserName": self.cf["sauceLabs"]["browser"], "version": self.cf.get("SauceLabs", "browser_version"), "name": method.__name__ } if desired_capabilities["browserName"][0] == "*": desired_capabilities["browserName"] = desired_capabilities["browserName"][1:] if desired_capabilities["platform"] in os_map: desired_capabilities["platform"] = os_map[desired_capabilities["platform"]] if self.cf.has_option("SauceLabs", "selenium_version"): desired_capabilities['selenium-version'] = self.cf.get('SauceLabs', 'selenium_version') command_executor = "http://%s:%[email protected]:80/wd/hub" % (self.cf.get("SauceLabs", "username"), self.cf.get("SauceLabs", "key")) else: desired_capabilities = capabilities_map[browser["type"]] if browser["proxy"]["type"] and browser["proxy"]["type"].lower() == "browsermob": from browsermobproxy import Client self.client = Client(self.cf.get("Proxy", "proxy_url")) self.client.add_to_webdriver_capabilities(desired_capabilities) if "is grid" in self.cf["selenium"] and self.cf["selenium"]["executor"]["is grid"]: if browser["grid filters"]["platform"]: desired_capabilities["platform"] = browser["grid filters"]["platform"].upper() if browser["grid filters"]["version"]: desired_capabilities["platform"] = str(browser["grid filters"]["version"]) command_executor = "http://%s:%s/wd/hub" % (self.cf["selenium"]["executor"]["host"], self.cf["selenium"]["executor"]["port"]) self.driver = WebDriver(desired_capabilities = desired_capabilities, command_executor = command_executor, browser_profile=profile) self.verificationErrors = [] self.matchers = Matchers(self.driver, self.verificationErrors) if "saucelabs" in self.cf["browsers"][self.cf["saunter"]["default_browser"]] and self.cf["browsers"][self.cf["saunter"]["default_browser"]]["saucelabs"]["ondemand"]: self.sauce_session = self.driver.session_id self._screenshot_number = 1 def teardown_method(self, method): """ Default teardown method for all scripts. If run through Sauce Labs OnDemand, the job name, status and tags are updated. Also the video and server log are downloaded if so configured. """ if hasattr(self, "config"): if "saucelabs" in self.cf["browsers"][self.cf["saunter"]["default_browser"]] and not self.cf["browsers"][self.cf["saunter"]["default_browser"]]["saucelabs"]["ondemand"]: self.take_named_screenshot("final") if hasattr(self, "driver"): self.driver.quit() def take_numbered_screenshot(self): if self.config.has_option("Saunter", "take_screenshots"): if self.cf.getboolean("Saunter", "take_screenshots"): method_dir = self._screenshot_prep_dirs() self.driver.get_screenshot_as_file(os.path.join(method_dir, str(self._screenshot_number).zfill(3) + ".png")) self._screenshot_number = self._screenshot_number + 1 if self.config.has_option("Saunter", "jenkins"): if self.cf.getboolean("Saunter", "jenkins"): sys.stdout.write(os.linesep + "[[ATTACHMENT|%s]]" % image_path + os.linesep) def take_named_screenshot(self, name): method_dir = self._screenshot_prep_dirs() image_path = os.path.join(method_dir, str(name) + ".png") self.driver.get_screenshot_as_file(image_path) if "ci_type" in self.cf and self.cf["ci_type"].lower() == "jenkins": sys.stdout.write(os.linesep + "[[ATTACHMENT|%s]]" % image_path + os.linesep)
class Browser(TailoredWebDriver): def __init__(self, browser_config, all_config): self.browser_config = browser_config self.config = all_config profile = None if browser_config["type"] == 'firefox': if browser_config["profiles"][sys.platform]: profile_path = os.path.join(self.config["saunter"]["base"], 'support', 'profiles', browser_config["profiles"][sys.platform]) elif browser_config["profiles"]["profile"]: profile_path = os.path.join(self.config["saunter"]["base"], 'support', 'profiles', browser_config["profiles"]["profile"]) else: profile_path = None if profile_path: if os.path.isdir(profile_path): profile = FirefoxProfile(profile_path) else: raise ProfileNotFound("Profile not found at %s" % profile_path) if browser_config["sauce labs"]["ondemand"]: desired_capabilities = { "platform": browser_config["sauce labs"]["os"], "browserName": browser_config["type"], "version": browser_config["sauce labs"]["version"], } if desired_capabilities["platform"] in os_map: desired_capabilities["platform"] = os_map[desired_capabilities["platform"]] if browser_config['sauce labs']['selenium version']: desired_capabilities['selenium-version'] = browser['sauce labs']['selenium version'] if "disable" in self.config["sauce labs"] and self.config["sauce labs"]["disable"] is not None: if "record video" in self.config["sauce labs"]["disable"]: if self.config["sauce labs"]["disable"]["record video"] == True: desired_capabilities['record-video'] = False if "upload video on pass" in self.config["sauce labs"]["disable"]: if self.config["sauce labs"]["disable"]["upload video on pass"] == True: desired_capabilities['video-upload-on-pass'] = False if "step screenshots" in self.config["sauce labs"]["disable"]: if self.config["sauce labs"]["disable"]["step screenshots"] == True: desired_capabilities['record-screenshots'] = False if "sauce advisor" in self.config["sauce labs"]["disable"]: if self.config["sauce labs"]["disable"]["sauce advisor"] == True: desired_capabilities['sauce-advisor'] = False if "enable" in self.config["sauce labs"] and self.config["sauce labs"]["enable"] is not None: if "source capture" in self.config["sauce labs"]["enable"]: if self.config["sauce labs"]["enable"]["source capture"] == True: desired_capabilities['source capture'] = True if "error screenshots" in self.config["sauce labs"]["enable"]: if self.config["sauce labs"]["enable"]["error screenshots"] == True: desired_capabilities['webdriver.remote.quietExceptions'] = True command_executor = "http://%s:%[email protected]:80/wd/hub" % (self.config["sauce labs"]["username"], self.config["sauce labs"]["key"]) else: desired_capabilities = capabilities_map[browser_config["type"]] if browser_config["proxy"]["type"] and browser_config["proxy"]["type"].lower() == "browsermob": from browsermobproxy import Client self.client = Client(self.config.get("Proxy", "proxy_url")) self.client.add_to_webdriver_capabilities(desired_capabilities) if "is grid" in self.config["selenium"] and self.config["selenium"]["executor"]["is grid"]: if browser_config["grid filters"]["platform"]: desired_capabilities["platform"] = browser_config["grid filters"]["platform"].upper() if browser_config["grid filters"]["version"]: desired_capabilities["platform"] = str(browser_config["grid filters"]["version"]) command_executor = "http://%s:%s/wd/hub" % (self.config["selenium"]["executor"]["host"], self.config["selenium"]["executor"]["port"]) # print(desired_capabilities) self.driver = TailoredWebDriver(desired_capabilities=desired_capabilities, command_executor=command_executor, browser_profile=profile)
class SaunterTestCase(BaseTestCase): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ def setup_method(self, method): """ Parent class of all script classes used for custom asserts (usually 'soft' asserts) and shared fixture setup and teardown """ self.cf = self.config = saunter.ConfigWrapper.ConfigWrapper() self.current_method_name = method.__name__ browser = self.cf["browsers"][self.cf["saunter"]["default_browser"]] if browser["type"][0] == "*": browser = browser["type"] = browser["type"][1:] profile = None if browser["type"] == 'firefox': if browser["profiles"][sys.platform]: profile_path = os.path.join(self.cf["saunter"]["base"], 'support', 'profiles', browser["profiles"][sys.platform]) elif browser["profiles"]["profile"]: profile_path = os.path.join(self.cf["saunter"]["base"], 'support', 'profiles', browser["profiles"]["profile"]) else: profile_path = None if profile_path: if os.path.isdir(profile_path): profile = FirefoxProfile(profile_path) else: raise ProfileNotFound("Profile not found at %s" % profile_path) if "saucelabs" in browser and browser["saucelabs"]["ondemand"]: desired_capabilities = { "platform": self.cf["sauceLabs"]["os"], "browserName": self.cf["sauceLabs"]["browser"], "version": self.cf.get("SauceLabs", "browser_version"), "name": method.__name__ } if desired_capabilities["browserName"][0] == "*": desired_capabilities["browserName"] = desired_capabilities[ "browserName"][1:] if desired_capabilities["platform"] in os_map: desired_capabilities["platform"] = os_map[ desired_capabilities["platform"]] if self.cf.has_option("SauceLabs", "selenium_version"): desired_capabilities['selenium-version'] = self.cf.get( 'SauceLabs', 'selenium_version') command_executor = "http://%s:%[email protected]:80/wd/hub" % ( self.cf.get("SauceLabs", "username"), self.cf.get("SauceLabs", "key")) else: desired_capabilities = capabilities_map[browser["type"]] if browser["proxy"]["type"] and browser["proxy"]["type"].lower( ) == "browsermob": from browsermobproxy import Client self.client = Client(self.cf.get("Proxy", "proxy_url")) self.client.add_to_webdriver_capabilities(desired_capabilities) if "is grid" in self.cf["selenium"] and self.cf["selenium"][ "executor"]["is grid"]: if browser["grid filters"]["platform"]: desired_capabilities["platform"] = browser["grid filters"][ "platform"].upper() if browser["grid filters"]["version"]: desired_capabilities["platform"] = str( browser["grid filters"]["version"]) command_executor = "http://%s:%s/wd/hub" % ( self.cf["selenium"]["executor"]["host"], self.cf["selenium"]["executor"]["port"]) self.driver = WebDriver(desired_capabilities=desired_capabilities, command_executor=command_executor, browser_profile=profile) self.verificationErrors = [] self.matchers = Matchers(self.driver, self.verificationErrors) if "saucelabs" in self.cf["browsers"][ self.cf["saunter"]["default_browser"]] and self.cf["browsers"][ self.cf["saunter"] ["default_browser"]]["saucelabs"]["ondemand"]: self.sauce_session = self.driver.session_id self._screenshot_number = 1 def teardown_method(self, method): """ Default teardown method for all scripts. If run through Sauce Labs OnDemand, the job name, status and tags are updated. Also the video and server log are downloaded if so configured. """ if hasattr(self, "config"): if "saucelabs" in self.cf["browsers"][ self.cf["saunter"] ["default_browser"]] and not self.cf["browsers"][self.cf[ "saunter"]["default_browser"]]["saucelabs"]["ondemand"]: self.take_named_screenshot("final") if hasattr(self, "driver"): self.driver.quit() def take_numbered_screenshot(self): if self.config.has_option("Saunter", "take_screenshots"): if self.cf.getboolean("Saunter", "take_screenshots"): method_dir = self._screenshot_prep_dirs() self.driver.get_screenshot_as_file( os.path.join( method_dir, str(self._screenshot_number).zfill(3) + ".png")) self._screenshot_number = self._screenshot_number + 1 if self.config.has_option("Saunter", "jenkins"): if self.cf.getboolean("Saunter", "jenkins"): sys.stdout.write(os.linesep + "[[ATTACHMENT|%s]]" % image_path + os.linesep) def take_named_screenshot(self, name): method_dir = self._screenshot_prep_dirs() image_path = os.path.join(method_dir, str(name) + ".png") self.driver.get_screenshot_as_file(image_path) if "ci_type" in self.cf and self.cf["ci_type"].lower() == "jenkins": sys.stdout.write(os.linesep + "[[ATTACHMENT|%s]]" % image_path + os.linesep)