Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
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"))
Esempio n. 4
0
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)
Esempio n. 5
0
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")
Esempio n. 6
0
    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
Esempio n. 7
0
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)
Esempio n. 8
0
    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
Esempio n. 9
0
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)