Beispiel #1
0
    def fill_filter_old(self, gender = None, from_age = None, till_age = None, location = None, on_site = None,
                        walk_plan = None, url = None):

        self.driver.set_page_load_timeout(50)
        try:
            self.driver.get(url)
            #w = self.driver.get_window_size()['width']
            #self.driver.set_window_size(w, 640)
        except:
            r = 1

        sex_tag = 'span'
        # изменение от 15.12.2016
        sex_tag = 'div'

        # переход в начало страницы
        self.driver.execute_script("window.scrollTo(0, 20);")
        sleep(3)
        flts = self.driver.find_elements_by_class_name("gs_filter_list")
        if gender is not None:
            lst = flts[0].find_elements_by_tag_name('li')
            if gender == 'm':
                lst[1].find_element_by_tag_name(sex_tag).click()
            if gender == 'f':
                lst[2].find_element_by_tag_name(sex_tag).click()

        if from_age is not None:
            elem = Select(flts[1].find_elements_by_tag_name('select')[0])
            elem.select_by_value(from_age)
            #elem = flts[1].find_elements_by_tag_name('select')[0].find_element_by_xpath("//option[@value='"+from_age+"']")
            #elem.click()

        if till_age is not None:
            elem = Select(flts[1].find_elements_by_tag_name('select')[1])
            elem.select_by_value(till_age)
            #elem = elem.find_element_by_xpath("option[@value='" + till_age + "']")
            #elem.click()

        if location is not None:
            i = 0
            while i < 3:
                try:
                    # до 15.12.2016 был тэг спан
                    elem = flts[2].find_element_by_xpath("li/div[@data-field_location='" + location +
                                                         "' and @data-field_country='10414533690']")
                    self.center_click(elem)
                    break
                except:
                    self.driver.execute_script("window.scrollTo(0, 20);")
                    i += 1
            if i >= 3:
                # до 15.12.2016 был тэг спан
                elem = flts[2].find_element_by_xpath("li/div[@data-field_location='" + location +
                                                     "' and @data-field_country='10414533690']")
                elem.click()

        if on_site is not None:
            wait = WebDriverWait(self.driver, 50)
            #elem = wait.until(EC.element_to_be_clickable((By.ID, 'field_onSite')))
            elem = flts[9].find_element_by_id('field_onSite')
            elem_m = flts[9].find_element_by_id('field_refs')
            #elem = WebDriverWait(self.driver, 60).until((EC.visibility_of_element_located(By.ID, 'field_onSite')))
            #elem = wait.until(EC.element_to_be_clickable((By.ID, 'field_onSite')))
            elem = wait.until(EC.visibility_of_element_located((By.ID, 'field_onSite')))
            if on_site != elem.is_selected():
                #action = ActionChains(self.driver)
                #action.move_to_element(elem_m)
                #action.click(elem)
                #action.perform()
                #elem = wait.until(EC.element_to_be_clickable((By.ID, 'field_onSite')))
                elem.click()
                #wait.until(stalenessOf(load));
                #self.driver.move_to_element(elem)
            #print elem.get_attribute('outerHTML')
            #if on_site != elem.is_selected():
            #    elem.click()

        #self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        sleep(5)
        self.logger.write_log(WALKER_FIENDS,
                              0,
                              self.logger.dumps(
                                          {'gender': gender,
                                           'from_age': from_age,
                                           'till_age': till_age,
                                           'location': location,
                                           'on_site': on_site,
                                           'walk_plan': walk_plan}),
                                  '')
Beispiel #2
0
class webgui(dut, object):
    obj = None
    path = None
    common_wait_interval = 1
    old_retry = 5
    driver = None

    def quit(self):
        if self.driver:
            self.driver.quit()

    def __init__(self,
                 name,
                 attr=None,
                 logger=None,
                 logpath=None,
                 shareData=None):
        #try:
        dut.__init__(self, name, attr, logger, logpath, shareData)
        self.log_file = self.logfile

        binary = None
        if FireFox:
            binary_path = './selenium/webdriver/firefox/'

            profile_path = None
            profile = None  # webdriver.FirefoxProfile(profile_path)
            #profile = webdriver.FirefoxProfile()
            a = FirefoxBinary()._get_firefox_start_cmd()
            #print(a, 'firefox file!!!!!!!!!!!!!!!!!!')
            if os.path.exists(binary_path):
                binary = FirefoxBinary(a)
                profile = webdriver.FirefoxProfile(binary_path)

            self.driver = webdriver.Firefox(firefox_binary=binary,
                                            firefox_profile=profile)

            self.driver.log_file = self.logfile
        else:
            self.driver = webdriver.Chrome()
            #webdriver.Chrome.__init__(self)
        #webdriver.Firefox.__init__(self,firefox_profile=profile)#, firefox_profile=profile, firefox_binary=)#

        #except:
        #    webdriver.Chrome.__init__(self)
        #webdriver.Firefox.__init__(self)

        if self.attribute.has_key('INTERVAL'):
            self.common_wait_interval = self.attribute['INTERVAL']
            time.sleep(0.5)
        else:
            self.common_wait_interval = 1

    @retry
    def set_retry(self, retry_max):
        global g_retry_counter
        self.old_retry = g_retry_counter
        g_retry_counter = retry_max

    @retry
    def restore_retry(self):
        global g_retry_counter
        g_retry_counter = self.old_retry

    @retry
    def xfind(self, path, type):
        if path is not None:
            self.path = path
        if str(type).lower() == 'xpath':
            function = self.driver.find_element_by_xpath
        elif str(type).lower() == 'name':
            function = self.driver.find_element_by_name
        elif str(type).lower() == 'text':
            function = self.driver.find_element_by_link_text
        elif str(type).lower() == 'id':
            function = self.driver.find_element_by_id
        self.obj = function(self.path)
        return self.obj

    @retry
    def xsend(self, cmd, path=None, type_by='xpath'):
        element = self.xfind(path, type_by)
        element.send_keys(cmd)
        #time.sleep(1)
    @retry
    def xclick(self, xpath=None, type_by='xpath'):
        element = self.xfind(xpath, type_by)
        element.click()
        self.sleep(1)

    @retry
    def xclear(self, xpath=None, type_by='xpath'):
        element = self.xfind(xpath, type_by)
        element.clear()
        #time.sleep(1)
    @retry
    def xrefill(self, data, xpath, type_by='xpath'):
        element = self.xfind(xpath, type_by)
        element.clear()
        element.send_keys(data)

    @retry
    def xselect(self, value, xpath=None, type_by='xpath'):
        self.obj = Select(self.xfind(xpath, type_by))
        self.obj.select_by_visible_text(value)
        self.sleep(1)

    @retry
    def xget(self, url=None):
        if url is not None:
            self.curr_url = url
        self.driver.get(self.curr_url)
        self.sleep(1)

    @retry
    def have_text(self, exp_txt, path, type_by='xpath'):
        try:
            elem = self.xfind(path, type_by)
            if elem.text.find(exp_txt) != -1:
                return True
            else:
                return False
        except Exception as e:
            return False

    def closeSession(self):
        super(webgui, self).closeSession()
        self.quit()

    def xcheck(self, xpath=None, type_by='xpath'):
        self.obj = self.xfind(xpath, type_by)
        if not self.obj.is_selected():
            self.obj.click()
            self.sleep(1)

    def xuncheck(self, xpath=None, type_by='xpath'):
        self.obj = self.xfind(xpath, type_by)
        if self.obj.is_selected():
            self.obj.click()
            self.sleep(1)

    def xswitch_2_pop(self, ):
        browser = self.driver
        parent_h = browser.current_window_handle
        # click on the link that opens a new window
        handles = browser.window_handles  # before the pop-up window closes
        handles.remove(parent_h)
        browser.switch_to.window(handles.pop())
        # do stuff in the popup
        # popup window closes
        browser.switch_to.window(parent_h)
Beispiel #3
0
class webgui(dut, object):
    obj     = None
    path = None
    common_wait_interval = 1
    old_retry = 5
    driver = None

    def quit(self):
        if self.driver:
            self.driver.quit()
    def __init__(self, name, attr =None,logger=None, logpath= None, shareData=None):
        #try:
        dut.__init__(self, name,attr,logger,logpath,shareData)
        self.log_file =self.logfile


        binary = None
        if FireFox:
            binary_path = './selenium/webdriver/firefox/'

            profile_path =None
            profile =None# webdriver.FirefoxProfile(profile_path)
            #profile = webdriver.FirefoxProfile()
            a = FirefoxBinary()._get_firefox_start_cmd()
            #print(a, 'firefox file!!!!!!!!!!!!!!!!!!')
            if os.path.exists(binary_path):
                binary = FirefoxBinary(a)
                profile = webdriver.FirefoxProfile(binary_path)

            self.driver= webdriver.Firefox(firefox_binary=binary,firefox_profile=profile)

            self.driver.log_file= self.logfile
        else:
            self.driver = webdriver.Chrome()
            #webdriver.Chrome.__init__(self)
        #webdriver.Firefox.__init__(self,firefox_profile=profile)#, firefox_profile=profile, firefox_binary=)#

        #except:
        #    webdriver.Chrome.__init__(self)
            #webdriver.Firefox.__init__(self)

        if self.attribute.has_key('INTERVAL'):
            self.common_wait_interval = self.attribute['INTERVAL']
            time.sleep(0.5)
        else:
            self.common_wait_interval = 1

    @retry
    def set_retry(self, retry_max):
        global g_retry_counter
        self.old_retry = g_retry_counter
        g_retry_counter = retry_max
    @retry
    def restore_retry(self):
        global g_retry_counter
        g_retry_counter =self.old_retry
    @retry
    def xfind(self, path, type):
        if path is not None:
            self.path = path
        if str(type).lower() == 'xpath':
            function = self.driver.find_element_by_xpath
        elif str(type).lower() == 'name':
            function = self.driver.find_element_by_name
        elif str(type).lower() == 'text':
            function = self.driver.find_element_by_link_text
        elif str(type).lower() == 'id':
            function = self.driver.find_element_by_id
        self.obj = function(self.path)
        return  self.obj
    @retry
    def xsend(self, cmd, path=None, type_by= 'xpath'):
        element = self.xfind(path, type_by)
        element.send_keys(cmd)
        #time.sleep(1)
    @retry
    def xclick( self, xpath=None, type_by='xpath'):
        element = self.xfind(xpath, type_by)
        element.click()
        self.sleep(1)
    @retry
    def xclear( self, xpath=None, type_by='xpath'):
        element = self.xfind(xpath, type_by)
        element.clear()
        #time.sleep(1)
    @retry
    def xrefill(self, data, xpath, type_by = 'xpath'):
        element = self.xfind(xpath, type_by)
        element.clear()
        element.send_keys(data)
    @retry
    def xselect(self, value, xpath=None, type_by='xpath'):
        self.obj = Select(self.xfind(xpath, type_by))
        self.obj.select_by_visible_text(value)
        self.sleep(1)
    @retry
    def xget(self,url=None):
        if url is not None:
            self.curr_url = url
        self.driver.get(self.curr_url)
        self.sleep(1)
    @retry
    def have_text(self, exp_txt, path, type_by = 'xpath'):
        try:
            elem = self.xfind(path, type_by)
            if elem.text.find(exp_txt)!=-1:
                return True
            else:
                return False
        except Exception as e:
            return False
    def closeSession(self):
        super(webgui,self).closeSession()
        self.quit()
    def xcheck(self, xpath=None, type_by='xpath'):
        self.obj = self.xfind(xpath, type_by)
        if not self.obj.is_selected():
            self.obj.click()
            self.sleep(1)
    def xuncheck(self, xpath=None, type_by='xpath'):
        self.obj = self.xfind(xpath, type_by)
        if self.obj.is_selected():
            self.obj.click()
            self.sleep(1)
    def xswitch_2_pop(self,):
        browser = self.driver
        parent_h = browser.current_window_handle
        # click on the link that opens a new window
        handles = browser.window_handles # before the pop-up window closes
        handles.remove(parent_h)
        browser.switch_to.window(handles.pop())
        # do stuff in the popup
        # popup window closes
        browser.switch_to.window(parent_h)