Beispiel #1
0
    def __init__(self,
                 driver_exe_path,
                 browser='firefox',
                 profile_path='',
                 browser_binary=None):

        mylog.debug("Init WebClicker")

        self.webdriver = None
        self.profile = None
        try:
            if browser == 'firefox':
                if profile_path:
                    self.profile = wd.FirefoxProfile(profile_path)
                else:
                    self.profile = None
                self.webdriver = wd.Firefox(firefox_profile=self.profile,
                                            executable_path=driver_exe_path,
                                            firefox_binary=browser_binary)
            else:
                raise ClickerException(
                    'Not supported browser {0}'.format(browser))
        except Exception as e:
            mylog.error(e)
            mylog.error('Fail to initialize {0}'.format(browser))
Beispiel #2
0
 def clear(self, name, value, partial=False):
     element = self.find_element(name, value, partial)
     if element:
         mylog.debug("Clear element {0}={1}".format(name, value))
         element.clear()
     else:
         mylog.error("Can't clear element {0}={1}".format(name, value))
Beispiel #3
0
def write_excel(file_name: str,
                df,  # data frame or dict of data frames where sheet_name is key
                prompt=False,
                convert_strings_to_urls=True,
                sheet_name='Sheet1') -> Error:
    while True:
        try:
            if convert_strings_to_urls:
                writer = pd.ExcelWriter(file_name, engine='xlsxwriter')
            else:
                writer = pd.ExcelWriter(file_name, engine='xlsxwriter', options={'strings_to_urls': False})

            if isinstance(df, pd.DataFrame):  # if this is single sheet
                df.to_excel(writer, index=False, sheet_name=sheet_name)

            else:  # must be a dict of sheets
                for sheet in df:
                    df[sheet].to_excel(writer, index=False, sheet_name=sheet)
                    mylog.debug("Adding sheet {0}".format(sheet))

            writer.save()

            return Error(None)

        except Exception as e:
            error = Error(e)
            if prompt:
                answer = input("Can't write file {0}. Try again? (y/n)".format(file_name))
                if answer.lower() == 'y':
                    continue
                else:
                    break
            else:
                break
    return error
Beispiel #4
0
    def _open_dreg_search(self):
        """
        switch_to_frame index=0
        switch_to_frame index=1
        click xpath="//*[contains(text(),'Sales Center')]"
        switch_to_frame index=0
        switch_to_frame index=1
        wait id="C19_W49_V50_HT-DR-SR"
        click id="C19_W49_V50_HT-DR-SR"
        :return: True if success, else False
        """

        mylog.debug("Open DREG search page...")
        self.wc.wait(10)
        self.wc.switch_to_frame_by_index(0)
        self.wc.switch_to_frame_by_index(1)
        self.wc.wait_element('xpath',
                             r"//*[contains(text(),'Sales Center')]",
                             time_sec=5)
        self.wc.click('xpath',
                      r"//*[contains(text(),'Sales Center')]",
                      time_sec=5)
        self.wc.wait_element('id', r"C19_W49_V50_HT-DR-SR", time_sec=5)
        self.wc.click('id', r"C19_W49_V50_HT-DR-SR", time_sec=5)

        success = self.wc.wait_element(
            'xpath',
            r"//*[contains(text(),'Search: Design Registrations - [SAP]')]",
            time_sec=5)

        if not success:
            raise IdisWebControllerException(
                "Can't see 'Search: Design Registrations - [SAP]' "
                "link on the resulting page.")
Beispiel #5
0
 def find_element(self, name, value, partial=False):
     out = self.find_elements(name, value, partial)
     if len(out) > 0:
         mylog.debug('{0}: {1} - {2} element(s) found'.format(
             name, value, len(out)))
         return out[0]
     else:
         return None
Beispiel #6
0
 def switch_to_frame(self, name, value):
     element = self.find_element(name, value)
     if element:
         self.webdriver.switch_to.frame(element)
         mylog.debug('Switching to frame {0}={1}'.format(name, value))
         return True
     else:
         mylog.error("Can't switch to frame {0}={1}".format(name, value))
         return False
Beispiel #7
0
 def _activate_dreg_edit(self):
     """
     click xpath="//img[@title='Edit Page']"
     wait time=5
     :return:
     """
     mylog.debug("Press Edit button")
     self.wc.click('xpath', r"//img[@title='Edit Page']")
     self.wc.wait(time_sec=5)
Beispiel #8
0
    def _edit_open_dreg(self, status, reason, approver, category):

        mylog.debug("Start edit current dreg")

        self._edit_registration_status(status)
        if status == 'Rejected':
            self._edit_rejection_reason(reason)
        self._edit_dreg_approver(approver)
        self._edit_dreg_category(category)
Beispiel #9
0
 def get_website(self, url):
     if not url.startswith(r'https://'):
         url = r'https://' + url
     mylog.debug("Trying load '{0}'".format(url))
     try:
         self.webdriver.get(url)
         return True
     except WebDriverException:
         mylog.error("Can't open page: '{0}'".format(url))
         return False
Beispiel #10
0
 def send_ctrl_key(self, name, value, key):
     element = self.find_element(name, value)
     if element:
         element.send_keys(Keys.CONTROL + key + Keys.NULL)
         mylog.debug("Sent Ctrl-{0} to element {1} {2}".format(
             key, name, value))
         return True
     else:
         mylog.error("Can't send Ctrl-{0} to element {1} {2}".format(
             key, name, value))
         return False
Beispiel #11
0
 def get_attribute(self, name, value, attribute_name):
     element = self.find_element(name, value)
     if element:
         attribute = element.get_attribute(attribute_name)
         mylog.debug("Element {0} = '{1}' attribute {2}={3}".format(
             name, value, attribute_name, attribute))
         return attribute
     else:
         mylog.error(
             "Can't read attribute {2}: Element {0}: {1} NOT found.".format(
                 name, value, attribute_name))
         return ''
Beispiel #12
0
 def send_string(self, name, value, string: str, end='', partial=False):
     element = self.find_element(name, value, partial)
     if not element:
         mylog.error(
             "Element {0}: {1} NOT found. String '{2}' NOT sent".format(
                 name, value, string))
         return False
     else:
         element.send_keys(string + end)
         mylog.debug("Sent string '{0}' to element {1} {2}".format(
             string, name, value))
         return True
Beispiel #13
0
    def _save_dreg(self):
        """
        send_ctrl_key tag=body key=s
        wait 10 sec
        click id=BackButton
        :return:
        """

        mylog.debug("Pressing save button...")
        self.wc.click('xpath',
                      '//*[@title="Save (Ctrl+S)" and @alt="Save"]',
                      time_sec=10)
        self.wc.wait(time_sec=10)
Beispiel #14
0
    def _open_idis(self):
        """
        get url="https://sappc1lb.eu.infineon.com:8410/sap(bD1lbiZjPTEwMCZkPW1pbg==)/bc/bsp/sap/crm_ui_start/default.htm"

        :return: True if success, else False
        """
        mylog.debug("Open IDIS website url ='{0}'".format(self.idis_url))
        self.wc.get_website(self.idis_url)

        success = self.wc.wait_element('xpath',
                                       r"//*[contains(text(),'Home - [SAP]')]",
                                       time_sec=10)

        if not success:
            raise IdisWebControllerException(
                "Can't see 'Home - [SAP]' link on the resulting page.")
Beispiel #15
0
    def _wait_element(self, how: str, what: str, timeout_sec=1):

        for i in range(timeout_sec):
            if self.is_element_ready(how, what):
                mylog.debug(
                    'Element {0}: {1} found. Waiting time is {2} sec'.format(
                        how, what, i))
                return True
            else:
                self.sleep(1)
                mylog.debug('Waiting element {0}: {1} {2} sec'.format(
                    how, what, i))

        mylog.error("Element {0}: {1} NOT found. Timeout = {2} sec".format(
            how, what, timeout_sec))
        return False
Beispiel #16
0
    def click(self, name, value, partial=False, time_sec=1):
        element = self.find_element(name, value, partial)
        if element:
            mylog.debug("Click element {0}={1}".format(name, value))
            t = 0
            while t < time_sec:
                try:
                    element.click()
                    return True
                except WebDriverException:
                    self.wait(1)
                    t += 1
        else:
            mylog.error("Can't click element {0}={1}".format(name, value))

        return False
Beispiel #17
0
    def switch_to_frame_by_index(self, index, time_sec=10):
        t = 0
        while t < time_sec:
            try:
                self.webdriver.switch_to.frame(index)
                mylog.debug('Switching to frame index={0}; time={1}'.format(
                    index, t))
                return True
            except NoSuchFrameException:
                self.wait(1)
                t += 1
                mylog.debug('Waiting frame index={0}; time={1}'.format(
                    index, t))

        mylog.error("Can't switch to frame index = {0}; time = time_sec")
        return False
Beispiel #18
0
    def get_element_value(self, how: By, path: str, timeout_sec=30):

        for i in range(timeout_sec):
            element = self.get_element(how, path)
            if element is not None:
                mylog.debug(
                    'Element {0}: {1} found. Waiting time is {2} sec'.format(
                        how, path, i))
                return element.get_attribute('value')
            else:
                self.sleep(1)
                mylog.debug('Waiting element {0}: {1} {2} sec'.format(
                    how, path, i))

        mylog.error("Element {0}: {1} NOT found. Timeout = {2} sec".format(
            how, path, timeout_sec))
        return ''
Beispiel #19
0
    def _edit_rejection_reason(self, reason):
        """
        click id='C24_W74_V76_V80_btsubject_struct.conc_key-btn'
        click link_text="Already registered to another disti"
        :param status:
        :return:
        """
        mylog.debug("Edit rejection reason")

        if (not self.wc.drop_down(
                'id',
                r'C24_W74_V76_V80_btsubject_struct.conc_key-btn',
                reason,
                time_sec=5,
                repeat_if_fail=3)):
            raise IdisWebControllerException(
                "Can't change on '{0}' in Rejection Reason".format(reason))
Beispiel #20
0
    def _edit_dreg_category(self, category):
        """
        click id=C24_W74_V76_V80_btcustomerh_ext.zzqp_dmnd_flg
        click link_text="Opportunity Tracking"
        :param category:
        :return:
        """
        mylog.debug("Edit dreg category: '{0}'".format(category))

        if (not self.wc.drop_down(
                'id',
                r"C24_W74_V76_V80_btcustomerh_ext.zzqp_dmnd_flg",
                category,
                time_sec=5,
                repeat_if_fail=3)):
            raise IdisWebControllerException(
                "Can't change on '{0}' in Category".format(category))
Beispiel #21
0
def update_excel_sheet(updated_sheet_name: str,
                       file_name: str,
                       df: pd.DataFrame,
                       prompt=False,
                       convert_strings_to_urls=True) -> Error:
    original_sheet_list, error = read_sheet_names(file_name)

    #  overwrite first sheet if updates_sheet_name is empty
    if len(updated_sheet_name) == 0:
        updated_sheet_name = original_sheet_list[0]

    if error:
        # file doesn't exist yet, try to create new
        mylog.warning("File {0} doesn't exist. Creating new".format(file_name))
        error = write_excel(file_name,
                            df,
                            prompt=prompt,
                            convert_strings_to_urls=convert_strings_to_urls,
                            sheet_name=updated_sheet_name)
        return error
    else:
        # read all existing sheets
        excel_with_sheets_dict = OrderedDict()

        # reading all sheets
        for sheet in original_sheet_list:
            next_sheet, error = read_excel(file_name,
                                           replace_nan='',
                                           sheet_name=sheet)
            if error:
                mylog.error("Can't read {0} - {1}: {2}".format(
                    file_name, sheet, error))
            else:
                excel_with_sheets_dict[sheet] = next_sheet

        excel_with_sheets_dict[updated_sheet_name] = df

        mylog.debug("excel_with_sheets_dict={0}".format(
            list(excel_with_sheets_dict)))
        error = write_excel(file_name,
                            excel_with_sheets_dict,
                            prompt=prompt,
                            convert_strings_to_urls=convert_strings_to_urls)

        return error
Beispiel #22
0
    def expand_node(self, current_node: BizDataNode, by: str) -> Error:

        subset_df = self._subset_df(current_node)
        dv_list, error = self._different_values(subset_df, by)

        if error:
            return error

        # df = self._subset_df(current_node)

        mylog.debug("{0} unique values".format(len(dv_list)))

        for v in dv_list:
            flt = {'column': by, 'value': v}
            s = self._sum(subset_df, flt)
            BizDataNode(v, str(s), parent=current_node, subset_filter=flt)

        return Error(None)
Beispiel #23
0
    def _edit_registration_status(self, status):
        """
        click id='C24_W74_V76_V80_btstatus_struct.act_status-btn'
        wait link_text=Approved time=5
        click link_text=Approved
        :param status:
        :return:
        """
        mylog.debug("Edit registration status")

        if (not self.wc.drop_down(
                'id',
                r"C24_W74_V76_V80_btstatus_struct.act_status-btn",
                status,
                time_sec=5,
                repeat_if_fail=3)):
            raise IdisWebControllerException(
                "Can't change on '{0}' in Registration Status".format(status))
Beispiel #24
0
    def drop_down(self,
                  by_name,
                  how_value,
                  set_value,
                  time_sec=1,
                  repeat_if_fail=0):

        for repeat in range(repeat_if_fail + 1):
            success = self.click(by_name, how_value, time_sec=time_sec)
            if success:
                success = self.click('link_text', set_value, time_sec=time_sec)
                if success:
                    mylog.debug("Dropdown {0}='{1}' selected '{2}'".format(
                        by_name, how_value, set_value))
                    return True

        mylog.error("Dropdown {0}='{1}' FAIL to select '{2}'".format(
            by_name, how_value, set_value))
        return False
def filter_and_remove_empty(*, df: pd.DataFrame, destination_col: str,
                            source_cols: tuple, **options):
    del options

    if destination_col in df.columns:
        df.drop(df[~df[destination_col].isin(source_cols)].index, inplace=True)
    else:
        mylog.warning(
            "Column {0} doesn't exist. Can't filter".format(destination_col))

    df.dropna(axis=1, how='all', inplace=True)

    col_list = list(df.columns)
    for col in col_list:
        if df[col].nunique() == 1 and df[col].tolist()[0] == '':
            df.drop(col, 1, inplace=True)

    mylog.debug("Dropped empty columns. Remaining columns: {0}".format(
        list(df.columns)))
Beispiel #26
0
    def command(self, request_args) -> None:

        command = request_args.get('command')
        node_id = request_args.get('id')

        if node_id:
            if command == 'collapse':
                expanded, _ = self.data.is_expanded(node_id)
                if expanded:
                    self.data.collapse(node_id)

            if command == 'expand':
                expanded, _ = self.data.is_expanded(node_id)
                if expanded:
                    self.data.collapse(node_id)

                expand_by = request_args.get('by')
                error = self.data.expand_id(node_id, expand_by)
                mylog.debug(error)
Beispiel #27
0
    def __init__(self, portal_url, idis_url, login, password, browser,
                 browser_binary, profile_path, driver_exe_path):

        mylog.debug("Start IdisWebController")

        self.portal_url = portal_url
        self.idis_url = idis_url
        self.login = login
        self.password = password
        self.browser = browser
        self.browser_binary = browser_binary
        self.profile_path = profile_path
        self.driver_exe_path = driver_exe_path

        self.first_run = True

        self.wc = WebClicker(self.driver_exe_path,
                             browser=self.browser,
                             profile_path=self.profile_path,
                             browser_binary=self.browser_binary)
Beispiel #28
0
    def _open_dreg(self, dreg_id):
        """
        # change first line in the form to "Design Registration ID"
        wait id="C22_W66_V67_V68_btqopp_parameters[1].FIELD" time=5
        click id="C22_W66_V67_V68_btqopp_parameters[1].FIELD"
        wait link_text='Design Registration ID' time=5
        click link_text='Design Registration ID'
        wait time=3
        # type DREG ID and "enter" instead of search button
        sendkeys id=C22_W66_V67_V68_btqopp_parameters[1].VALUE1 string=20279935 -enter
        # wait search results and click on DREG ID
        wait link_text=20279935
        click link_text=20279935
        :param dreg_id:
        :return:
        """
        mylog.debug("Open design registration id = {0} details page...".format(
            dreg_id))
        self.wc.wait_element('id',
                             r"C22_W66_V67_V68_btqopp_parameters[1].FIELD",
                             time_sec=5)
        self.wc.click('id', r"C22_W66_V67_V68_btqopp_parameters[1].FIELD")
        self.wc.wait_element('link_text', r'Design Registration ID')
        self.wc.click('link_text', r'Design Registration ID')
        self.wc.wait(time_sec=2)
        self.wc.clear('id', r"C22_W66_V67_V68_btqopp_parameters[1].VALUE1")
        self.wc.send_string('id',
                            r"C22_W66_V67_V68_btqopp_parameters[1].VALUE1",
                            string=str(dreg_id),
                            end=Keys.RETURN)
        self.wc.wait_element('link_text', str(dreg_id), time_sec=10)
        self.wc.click('link_text', str(dreg_id))

        success = self.wc.wait_element(
            'xpath',
            r"//*[contains(text(),'Design Registration Details')]",
            time_sec=10)

        if not success:
            raise IdisWebControllerException(
                "Can't see 'Design Registration Details' on the page")
Beispiel #29
0
    def _edit_dreg_approver(self, approver):
        """
        clear id=C24_W74_V76_V80_btparterapprover_struct.partner_no
        sendkeys id=C24_W74_V76_V80_btparterapprover_struct.partner_no string='Vasily Basov' -enter
        :param approver:
        :return:
        """
        mylog.debug("Edit DREG approver: '{0}'".format(approver))
        self.wc.clear('id',
                      r"C24_W74_V76_V80_btparterapprover_struct.partner_no")
        self.wc.send_string(
            'id',
            r"C24_W74_V76_V80_btparterapprover_struct.partner_no",
            string=approver,
            end=Keys.RETURN)
        self.wc.wait(1)
        check = self.wc.get_attribute(
            'id',
            r"C24_W74_V76_V80_btparterapprover_struct.partner_no",
            attribute_name='value')

        if not check == approver:
            raise IdisWebControllerException("Read approver fail!")
Beispiel #30
0
    def _open_portal_in_new_window(self):
        """
        start url=https://portal.intra.infineon.com/irj/portal
        wait id=logonuidfield
        click id=logonuidfield
        sendkeys id=logonuidfield string=basov
        click id=logonuidfield
        sendkeys id=logonpassfield string=Planet%Mars%Flight -enter
        wait xpath="//*[contains(text(),'PC1 CRM Web Client')]" time=10


        :return: True if success, else False
        """

        mylog.debug(
            "Opening portal in new window and entering login/password...")
        success = self.wc.get_website(self.portal_url)
        if not success:
            raise IdisWebControllerException("Can't open portal '{0}'".format(
                self.portal_url))
        self.wc.wait_element('id', 'logonuidfield', time_sec=10)
        self.wc.click('id', 'logonuidfield')
        self.wc.send_string('id', 'logonuidfield', string=self.login)
        self.wc.click('id', 'logonpassfield')
        self.wc.send_string('id',
                            'logonpassfield',
                            string=self.password,
                            end=Keys.RETURN)

        success = self.wc.wait_element(
            'xpath',
            r"//*[contains(text(),'PC1 CRM Web Client')]",
            time_sec=20)

        if not success:
            raise IdisWebControllerException(
                "Can't see 'PC1 CRM Web Client' link on the resulting page")