예제 #1
0
    def setUp(self):
        """
        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
        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:]
            desired_capabilities = capabilities_map[browser]
            command_executor = "http://%s:%s/wd/hub" % (self.cf.get("Selenium", "server_host"), self.cf.get("Selenium", "server_port"))
        self.driver = wrapper().remote_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"):
            wrapper().sauce_session = self.driver.session_id
예제 #2
0
    def setUp(self):
        """
        Default setup method for all scripts. Connects either to the RC server configured in conf/selenium.ini
        or to Sauce Labs OnDemand
        """
        self.verificationErrors = []
        self.cf = saunter.ConfigWrapper.ConfigWrapper().config
        self.cf.set("Saunter", "name", self._testMethodName)
        if self.cf.getboolean("SauceLabs", "ondemand"):
            host = self.cf.get("SauceLabs", "server_host")
            port = self.cf.get("SauceLabs", "server_port")
            j = {}
            j['username'] = self.cf.get("SauceLabs", "username")
            j['access-key'] = self.cf.get("SauceLabs", "key")
            j['os'] = self.cf.get("SauceLabs", "os")
            j['browser'] = self.cf.get("SauceLabs", "browser")
            if j['browser'][0] == "*":
                j['browser'] = j['browser'][1:]
            j['browser-version'] = self.cf.get("SauceLabs", "browser_version")
            browser = json.dumps(j)
        else:
            host = self.cf.get("Selenium", "server_host")
            port = self.cf.get("Selenium", "server_port")
            browser = self.cf.get("Selenium", "browser")

        self.selenium = wrapper().remote_control(host, port, browser, self.cf.get("Selenium", "base_url"))
        self.selenium.start()
        
        if self.cf.getboolean("SauceLabs", "ondemand"):
            wrapper().sauce_session = self.selenium.get_eval("selenium.sessionId")
        
        self.selenium.window_maximize()
        self.selenium.open('/');
예제 #3
0
def pytest_runtest_logreport(report):
    # this will make sure the browser is dead even if there was an exception in setUp
    try:
        c = wrapper().connection
        if c.running:
            if hasattr(c, "capabilities"):
                c.quit()
            else:
                c.stop()
    except AttributeError:
        pass
        
    if cf.getboolean("SauceLabs", "ondemand"):
        # session couldn't be established for some reason
        if not hasattr(wrapper(), "sauce_session"):
           return
        sauce_session = wrapper().sauce_session
        
        j = {}
    
        # name
        names = report.nodeid.split("::")
        names[0] = names[0].replace("/", '.')
        names = tuple(names)
        d = {}
        names = [x.replace(".py", "") for x in names if x != "()"]
        classnames = names[:-1]
        d['classname'] = ".".join(classnames)
        d['name'] = py.xml.escape(names[-1])
        attrs = ['%s="%s"' % item for item in sorted(d.items())]
        j["name"] = d['name']
    
        # result
        if report.passed:
            j["passed"] = True
        else:
            j["passed"] = False

        # tags
        j["tags"] = report.keywords
        
        # update
        which_url = "https://saucelabs.com/rest/v1/%s/jobs/%s" % (cf.get("SauceLabs", "username"), sauce_session)
        r = requests.put(which_url,
                         data=json.dumps(j),
                         headers={"Content-Type": "application/json"},
                         auth=(cf.get("SauceLabs", "username"), cf.get("SauceLabs", "key")))
        r.raise_for_status()

        if cf.getboolean("SauceLabs", "get_video"):
            fetch_artifact("video.flv")
        
        if cf.getboolean("SauceLabs", "get_log"):
            fetch_artifact("selenium-server.log")
예제 #4
0
 def __get__(self, obj, cls=None):
     try:
         return str(wrapper().connection.get_value(self.locator))
     except AttributeError as e:
         if str(e) == "'SeleniumWrapper' object has no attribute 'connection'":
             pass
         else:
             raise e
     except ElementNotFound as e:
         msg = "Element %s was not found. It is used in the %s page object in the %s module." % (self.locator, obj.__class__.__name__, self.__module__)
         raise ElementNotFound(msg)
예제 #5
0
 def __get__(self, obj, cls=None):
     try:
         return str(wrapper().connection.get_selected_label(self.locator))
     except AttributeError as e:
         if str(e) == "'SeleniumWrapper' object has no attribute 'connection'":
             pass
         else:
             raise e
     except ElementNotFound as e:
         msg = "Element %s was not found. It is used in the %s page object in the %s module." % (self.locator, obj.__class__.__name__, self.__module__)
         raise ElementNotFound(msg)
예제 #6
0
def fetch_artifact(which):
    sauce_session = wrapper().sauce_session
    which_url = "https://saucelabs.com/rest/%s/jobs/%s/results/%s" % (cf.get("SauceLabs", "username"), sauce_session, which)
    code = 404
    timeout = 0
    while code in [401, 404]:
        r = requests.get(which_url, auth = (cf.get("SauceLabs", "username"), cf.get("SauceLabs", "key")))
        try:
            code = r.status_code
            r.raise_for_status()
        except urllib2.HTTPError, e:
            time.sleep(4)
예제 #7
0
    def setup_method(self, method):
        """
        Default setup method for all scripts. Connects either to the RC server configured in conf/selenium.ini
        or to Sauce Labs OnDemand
        """
        self.config = saunter.ConfigWrapper.ConfigWrapper().config
        self.cf = self.config

        self.current_method_name = method.__name__

        if self.cf.getboolean("SauceLabs", "ondemand"):
            host = self.cf.get("SauceLabs", "server_host")
            port = self.cf.get("SauceLabs", "server_port")
            j = {}
            j['username'] = self.cf.get("SauceLabs", "username")
            j['access-key'] = self.cf.get("SauceLabs", "key")
            j['os'] = self.cf.get("SauceLabs", "os")
            j['browser'] = self.cf.get("SauceLabs", "browser")
            if j['browser'][0] == "*":
                j['browser'] = j['browser'][1:]
            j['browser-version'] = self.cf.get("SauceLabs", "browser_version")
            browser = json.dumps(j)
        else:
            host = self.cf.get("Selenium", "server_host")
            port = self.cf.get("Selenium", "server_port")
            browser = self.cf.get("Selenium", "browser")

        self.selenium = wrapper().remote_control(host, port, browser, self.cf.get("Selenium", "base_url"))
        self.selenium.start()

        self.verificationErrors = []
        self.matchers = Matchers(self.selenium, self.verificationErrors)
        
        if self.cf.getboolean("SauceLabs", "ondemand"):
            self.sauce_session = self.selenium.get_eval("selenium.sessionId")
            
        
        self.selenium.window_maximize()
        if self.cf.has_option("Selenium", "timeout"):
            self.selenium.set_timeout(self.cf.getint("Selenium", "timeout") * 1000)
        self.selenium.open(self.cf.get("Selenium", "base_url"));

        self._screenshot_number = 1
예제 #8
0
    def setUp(self):
        """
        Default setup method for all scripts. Connects either to the RC server configured in conf/selenium.ini
        or to Sauce Labs OnDemand
        """
        self.verificationErrors = []
        self.cf = saunter.ConfigWrapper.ConfigWrapper().config
        self.cf.set("Saunter", "name", self._testMethodName)
        if self.cf.getboolean("SauceLabs", "ondemand"):
            host = self.cf.get("SauceLabs", "server_host")
            port = self.cf.get("SauceLabs", "server_port")
            j = {}
            j['username'] = self.cf.get("SauceLabs", "username")
            j['access-key'] = self.cf.get("SauceLabs", "key")
            j['os'] = self.cf.get("SauceLabs", "os")
            j['browser'] = self.cf.get("SauceLabs", "browser")
            if j['browser'][0] == "*":
                j['browser'] = j['browser'][1:]
            j['browser-version'] = self.cf.get("SauceLabs", "browser_version")
            browser = json.dumps(j)
        else:
            host = self.cf.get("Selenium", "server_host")
            port = self.cf.get("Selenium", "server_port")
            browser = self.cf.get("Selenium", "browser")

        self.selenium = wrapper().remote_control(
            host, port, browser, self.cf.get("Selenium", "base_url"))
        self.selenium.start()

        if self.cf.getboolean("SauceLabs", "ondemand"):
            self.selenium.sauce_session = self.selenium.get_eval(
                "selenium.sessionId")

        self.selenium.window_maximize()
        if self.cf.has_option("Selenium", "timeout"):
            self.selenium.set_timeout(
                self.cf.getint("Selenium", "timeout") * 1000)
        self.selenium.open(self.cf.get("Selenium", "base_url"))
 def __init__(self):
     self.se = wrapper().connection
예제 #10
0
 def __set__(self, obj, val):
     if (val == True and str(wrapper().connection.get_value(self.locator))
             == 'off') or (val == False and str(
                 wrapper().connection.get_value(self.locator)) == 'on'):
         wrapper().connection.click(self.locator)
예제 #11
0
 def __set__(self, obj, val):
     if (val == True and str(wrapper().connection.get_value(self.locator)) == 'off') or (val == False and str(wrapper().connection.get_value(self.locator)) == 'on'):
         wrapper().connection.click(self.locator)
예제 #12
0
 def __set__(self, obj, val):
     wrapper().connection.type(self.locator, val)
예제 #13
0
 def __init__(self):
     self.se = wrapper().connection
예제 #14
0
    def setup_method(self, method):
        """
        Default setup method for all scripts. Connects either to the RC server configured in conf/selenium.ini
        or to Sauce Labs OnDemand
        """
        self.config = saunter.ConfigWrapper.ConfigWrapper().config
        self.cf = self.config

        self.current_method_name = method.__name__

        if self.cf.getboolean("SauceLabs", "ondemand"):
            host = self.cf.get("SauceLabs", "server_host")
            port = self.cf.get("SauceLabs", "server_port")
            j = {}
            j['username'] = self.cf.get("SauceLabs", "username")
            j['access-key'] = self.cf.get("SauceLabs", "key")
            j['os'] = self.cf.get("SauceLabs", "os")
            j['browser'] = self.cf.get("SauceLabs", "browser")
            if j['browser'][0] == "*":
                j['browser'] = j['browser'][1:]

            if j['browser'] == "firefox":
                if self.cf.has_option("Selenium", "profile-%s" % sys.platform):
                    profile_path = os.path.join(self.cf.get("Saunter", "base"), 'support', 'profiles', self.cf.get("Selenium", "profile-%s" % sys.platform))
                elif self.cf.has_option("Selenium", "profile"):
                    profile_path = os.path.join(self.cf.get("Saunter", "base"), 'support', 'profiles', self.cf.get("Selenium", "profile"))
                else:
                    profile_path = None

                if profile_path:
                    if os.path.isdir(profile_path):
                        profile_zip = os.path.join(self.cf.get("Saunter", "base"), 'support', 'profiles', "%s.zip" % self.cf.get("Selenium", "profile"))
                        
                        zipped = zipfile.ZipFile(profile_zip, 'w', zipfile.ZIP_DEFLATED)
                        path_root = len(profile_path) + 1 # account for trailing slash
                        for base, dirs, files in os.walk(profile_path):
                            for fyle in files:
                                filename = os.path.join(base, fyle)
                                zipped.write(filename, filename[path_root:])
                        zipped.close()
                    else:
                        raise ProfileNotFound("Profile not found at %s" % profile_path)
                    j['firefox-profile-url'] = "%s/profiles/%s.zip" % (self.cf.get("YourCompany", "file_server_base"), self.cf.get("Selenium", "profile"))
            j['browser-version'] = self.cf.get("SauceLabs", "browser_version")

            if self.cf.has_option("SauceLabs", "selenium_version"):
                j['selenium-version'] = self.cf.get('SauceLabs', 'selenium_version')

            browser = json.dumps(j)
            # print(browser)
        else:
            host = self.cf.get("Selenium", "server_host")
            port = self.cf.get("Selenium", "server_port")
            browser = self.cf.get("Selenium", "browser")

        self.selenium = wrapper().remote_control(host, port, browser, self.cf.get("Selenium", "base_url"))
        self.selenium.start()

        self.verificationErrors = []
        self.matchers = Matchers(self.selenium, self.verificationErrors)
        
        if self.cf.getboolean("SauceLabs", "ondemand"):
            self.sauce_session = self.selenium.get_eval("selenium.sessionId")
            
        
        self.selenium.window_maximize()
        if self.cf.has_option("Selenium", "timeout"):
            self.selenium.set_timeout(self.cf.getint("Selenium", "timeout") * 1000)
        self.selenium.open(self.cf.get("Selenium", "base_url"));

        self._screenshot_number = 1
예제 #15
0
 def __set__(self, obj, val):
     wrapper().connection.select(self.locator, val)