Esempio n. 1
0
 def create_data_file(self):
     """Create a file with the given name.  The file name must be defined first using `Define File Name` keyword. 
     This keyword leverages the Robot Framework OperatingSystem library keyword `Create File`, so if the directory
     for the file does not exist, it is created, along with missing intermediate directories."""
     if self.absolute_name is None:
         raise AssertionError("The file name has not been defined.  Define it using the 'Define File Name' keyword")
     else:
         operating_sys = OperatingSystem()
         try:
             operating_sys.create_file(self.absolute_name)
             self._exists = True
         except PermissionError as e:
             logger.error(e.strerror)
             raise
Esempio n. 2
0
def writeToFile_variables(object, obj, sf_type):
    # MSuccess_Msg = Message(bottom_frame, text='Printing file ....')
    # def Error_Delete():
    #     error_Msg.destroy()
    #     Try_with_Other_object_btn.destroy()
    # Try_with_Other_object_btn = Button(bottom_frame, text="Try_with_Other_object", fg="black", bg="light blue",
    #                                     command=Error_Delete)
    # Try_with_Other_object_btn.grid(row=2, column=2)

    OS = OperatingSystem()
    # path = '../Resources/MedvantageApp/PageElements/%s_Page.robot' % object
    OS.create_file('../../Data/Portal/Dev/%s_data_%s.py' % (object, sf_type))
    OS.append_to_file(
        '../../Data/Portal/Dev/%s_data_%s.py' % (object, sf_type),
        '## Xpath Locators')
    OS.append_to_file(
        '../../Data/Portal/Dev/%s_data_%s.py' % (object, sf_type), '\n')

    # MSuccess_Msg.grid(row=0, column=1)
    print 'Printing file ....'
    # if sf_type is 'classic':
    #     OS.append_to_file(path, '\n''# Locators for All Tabs')
    #     OS.append_to_file(path, '\n''${Alltabs_btn_loc}  //img[@title=\'All Tabs\']')
    #     OS.append_to_file(path, '\n''${%s_tab_link_loc}  //img[@title=\'%s\']'%(object,obj))
    #     OS.append_to_file(path, '\n')
    # elif sf_type is 'lightning':
    #     OS.append_to_file(path, '\n''# Locators for All Items(Tabs)')
    #     OS.append_to_file(path, '\n''${All_App_Launcher_loc}  //img[@title=\'All Tabs\']')
    #     OS.append_to_file(path, '\n''${%s_tab_link_loc}  //img[@title=\'%s\']' % (object, obj))
    #     OS.append_to_file(path, '\n')

    try:
        for xpathdata in xpath_values:
            OS.append_to_file(
                '../../Data/Portal/Dev/%s_data_%s.py' % (object, sf_type),
                xpathdata)
            OS.append_to_file(
                '../../Data/Portal/Dev/%s_data_%s.py' % (object, sf_type),
                '\n')
    except:
        print "No Object"

    writeToFile_keywords(object, obj, sf_type)
def writeToFile_Settings(object, obj, sf_type):
    global OS, path
    OS = OperatingSystem()
    path = '../Resources/MedvantageApp/PO/%s_Page_%s.robot' %(object,sf_type)
    OS.create_file(path, '*** Settings ***')
    print 'Printing Settings ....'
    OS.append_to_file(path, '\n')
    OS.append_to_file(path, 'Documentation    %s Page Reusable Keywords' %object)
    OS.append_to_file(path, '\n')
    OS.append_to_file(path, 'Library  Selenium2Library')
    OS.append_to_file(path, '\n')
    OS.append_to_file(path, 'Library  OperatingSystem')
    OS.append_to_file(path, '\n')
    OS.append_to_file(path, 'Library  ../../../Utility/keyword_generator_lightning.py')
    OS.append_to_file(path, '\n')
    OS.append_to_file(path, 'Resource  ../../common-methods.robot')
    OS.append_to_file(path, '\n')
    OS.append_to_file(path, 'Library  ../../../Utility/datepicker.py')
    OS.append_to_file(path, '\n')
    OS.append_to_file(path, '\n')
    writeToFile_variables(object, obj, sf_type)
class AdvancedLogging(object):
    """
    Creating additional logs when testing.
    If during the test you want to add any additional information in the file, then this library
    provide a hierarchy of folders and files for logging.
    Folder hierarchy is created as follows: output_dir/test_log_folder_name/Test_Suite/Test_Suite/Test_Case/file.log
    Log files and folders are not removed before the test, and overwritten of new files.
    
     == Dependency: ==
    | robot framework | http://robotframework.org |
    -------
    
    When initializing the library, you can define two optional arguments
    | *Argument Name*      |  *Default value*  | *Description*                                                 |
    | output_dir           |  ${OUTPUT_DIR}    | The directory in which create the folder with additional logs |
    | test_log_folder_name |  Advanced_Logs    | Name of the folder from which to build a hierarchy of logs    |
    -------
    
    == Example: ==
    | *Settings*  |  *Value*           | *Value*  |  *Value*        |
    | Library     |  AdvancedLogging   | C:/Temp  |   LogFromServer |
    | Library     |  SSHLibrary        |          |                 |
    
    | *Test cases*              | *Action*                  | *Argument*             |  *Argument*            |
    | Example_TestCase          | ${out}=                   | Execute Command        |  grep error output.log |
    |                           | Write advanced testlog    | error.log              |  ${out}                |
    =>\n
    File C:/Temp/LogFromServer/TestSuite name/Example_TestCase/error.log  with content from variable ${out}
    """

    ROBOT_LIBRARY_SCOPE='TEST SUITE'

    def __init__(self, output_dir = None, test_log_folder_name = 'Advanced_Logs'):
        self.os=OperatingSystem()
        self.bi=BuiltIn()

        self.output_dir=output_dir
        self.test_log_folder_name=test_log_folder_name
        self.sep='/'

    @property
    def _suite_folder (self):
        """
        Define variables that are initialized by a call 'TestSuite'
        """


        if self.output_dir==None :
            self.output_dir=self.bi.get_variable_value('${OUTPUT_DIR}')

        suite_name=self.bi.get_variable_value('${SUITE_NAME}')
        suite_name=suite_name.replace('.', self.sep)
        self.output_dir=os.path.normpath(self.output_dir)
        self.test_log_folder_name=os.path.normpath(self.test_log_folder_name)

        suite_folder=self.output_dir+self.sep+self.test_log_folder_name+self.sep+suite_name
        return os.path.normpath(suite_folder)

    def Write_Advanced_Testlog (self, filename, content):
        """ 
        Inclusion content in additional log file
        
        Return: path to filename
        
        Example:
        | Write advanced testlog   | log_for_test.log  |  test message |
        =>\n
        File ${OUTPUT_DIR}/Advanced_Logs/<TestSuite name>/<TestCase name>/log_for_test.log with content 'test message'
        """

        test_name=BuiltIn().get_variable_value('${TEST_NAME}')

        if not test_name:
            log_folder=self._suite_folder+self.sep
        else:
            log_folder=self._suite_folder+self.sep+test_name

        self.os.create_file(log_folder+self.sep+filename, content)

        return os.path.normpath(log_folder+self.sep+filename)

    def Create_Advanced_Logdir (self):
        """  
        Creating a folder hierarchy for TestSuite
        
        Return: path to folder
        
        Example:
        | *Settings* | *Value* |
        | Library    |        AdvancedLogging |
        | Library    |       OperatingSystem |
        
        | *Test Cases* | *Action* | *Argument* |
        | ${ADV_LOGS_DIR}=   | Create advanced logdir            |                |
        | Create file        | ${ADV_LOGS_DIR}/log_for_suite.log |   test message |
        =>\n
        File ${OUTPUT_DIR}/Advanced_Logs/<TestSuite name>/log_for_suite.log with content 'test message'
        """

        test_name=self.bi.get_variable_value('${TEST_NAME}')

        if not test_name:
            log_folder=self._suite_folder+self.sep
        else:
            log_folder=self._suite_folder+self.sep+test_name

        self.os.create_directory(os.path.normpath(log_folder))

        return os.path.normpath(log_folder)
Esempio n. 5
0
class AdvancedLogging(object):
    """
    Creating additional logs when testing.
    If during the test you want to add any additional information in the file, then this library
    provide a hierarchy of folders and files for logging.
    Folder hierarchy is created as follows: output_dir/test_log_folder_name/Test_Suite/Test_Suite/Test_Case/file.log
    Log files and folders are not removed before the test, and overwritten of new files.

     == Dependency: ==
    | robot framework | http://robotframework.org |
    -------

    When initializing the library, you can define two optional arguments
    | *Argument Name*      |  *Default value*  | *Description*                                                 |
    | output_dir           |  ${OUTPUT_DIR}    | The directory in which create the folder with additional logs |
    | test_log_folder_name |  Advanced_Logs    | Name of the folder from which to build a hierarchy of logs    |
    -------

    == Example: ==
    | *Settings*  |  *Value*           | *Value*  |  *Value*        |
    | Library     |  AdvancedLogging   | C:/Temp  |   LogFromServer |
    | Library     |  SSHLibrary        |          |                 |

    | *Test cases*              | *Action*                  | *Argument*             |  *Argument*            |
    | Example_TestCase          | ${out}=                   | Execute Command        |  grep error output.log |
    |                           | Write advanced testlog    | error.log              |  ${out}                |
    =>\n
    File C:/Temp/LogFromServer/TestSuite name/Example_TestCase/error.log  with content from variable ${out}
    """

    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'

    def __init__(self,
                 output_dir: str = None,
                 test_log_folder_name: str = 'Advanced_Logs') -> None:
        """ Initialisation

        *Args*:\n
            _output_dir_: output directory.\n
            _test_log_folder_name_: name for log folder.
        """
        self.os = OperatingSystem()
        self.bi = BuiltIn()

        self.output_dir = output_dir
        self.test_log_folder_name = test_log_folder_name
        self.win_platform = 'Windows' in platform()

    def _get_suite_names(self) -> Iterator[str]:
        """
        Get List with the current suite name and all its parents names

        *Returns:*\n
            Iterator of the current suite name and all its parents names
        """
        suite = EXECUTION_CONTEXTS.current.suite
        result = [suite.name]
        while suite.parent:
            suite = suite.parent
            result.append(suite.name)
        return reversed(result)

    @property
    def _suite_folder(self) -> str:
        """ Define variables that are initialized by a call 'TestSuite'

        *Returns:*\n
            Path to suite folder.
        """
        output = self.output_dir

        if output is None:
            output = self.bi.get_variable_value('${OUTPUT_DIR}')

        suite_name = path_join(*self._get_suite_names())

        if self.win_platform:
            # Look at MSDN knowledge base: https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath
            long_path_support_prefix = '\\\\?\\'
            output = long_path_support_prefix + output

        suite_folder = path_join(output, self.test_log_folder_name, suite_name)

        return normpath(suite_folder)

    def write_advanced_testlog(self,
                               filename: str,
                               content: Union[bytes, str],
                               content_encoding: str = 'UTF-8') -> str:
        """ Inclusion content in additional log file

        *Args:*\n
            _filename_ - name of log file;
            _content_ - content for logging;
            _content_encoding_ - encoding of content (if it's in bytes).

        *Returns:*\n
             Path to filename.

        *Example*:\n
        | Write advanced testlog   | log_for_test.log  |  test message |
        =>\n
        File ${OUTPUT_DIR}/Advanced_Logs/<TestSuite name>/<TestCase name>/log_for_test.log with content 'test message'
        """
        if isinstance(content, bytes):
            content = content.decode(content_encoding)
        test_name = self.bi.get_variable_value('${TEST_NAME}', default='')
        log_file_path = path_join(self._suite_folder, test_name, filename)
        self.os.create_file(log_file_path, content)
        return normpath(log_file_path)

    def create_advanced_logdir(self) -> str:
        """ Creating a folder hierarchy for TestSuite

        *Returns:*\n
             Path to folder.

        *Example*:\n
        | *Settings* | *Value* |
        | Library    |        AdvancedLogging |
        | Library    |       OperatingSystem |

        | *Test Cases* | *Action* | *Argument* |
        | ${ADV_LOGS_DIR}=   | Create advanced logdir            |                |
        | Create file        | ${ADV_LOGS_DIR}/log_for_suite.log |   test message |
        =>\n
        File ${OUTPUT_DIR}/Advanced_Logs/<TestSuite name>/log_for_suite.log with content 'test message'
        """
        test_name = self.bi.get_variable_value('${TEST_NAME}', default='')
        log_folder = path_join(self._suite_folder, test_name)
        old_log_level = BuiltIn().set_log_level("ERROR")
        self.os.create_directory(log_folder)
        BuiltIn().set_log_level(old_log_level)
        return normpath(log_folder)