コード例 #1
0
class ArchiveKeywords(object):
    ROBOT_LIBRARY_SCOPE = 'Global'

    def __init__(self):
        self.oslib = BuiltIn().get_library_instance("OperatingSystem")
        self.collections = Collections()

    def extract_zip_file(self, zfile, dest=None):
        if dest:
            self.oslib.create_directory(dest)
            self.oslib.directory_should_exist(dest)

        cwd = os.getcwd()
        os.chdir(dest)

        unzipper = Unzip()

        try:
            unzipper.extract(zfile, dest)
        except:
            raise
        finally:
            os.chdir(cwd)

    def archive_should_contain_file(self, zfile, filename):
        self.oslib.file_should_exist(zfile)

        z = zipfile.ZipFile(zfile)
        self.collections.list_should_contain_value(z.namelist(), filename)
コード例 #2
0
 def _check_changed_variable(self, data):
     try:
         js = data['variable_change']
         from robot.libraries.BuiltIn import BuiltIn
         vars = BuiltIn().get_variables()
         for key in js.keys():
             if key in vars:
                 if len(js[key]) > 1:
                     from robot.libraries.Collections import Collections
                     if len(js[key]) == 2:
                         if isinstance(vars[key], dict):
                             Collections().set_to_dictionary(
                                 vars[key], js[key][0], js[key][1])
                         else:
                             Collections().set_list_value(
                                 vars[key], js[key][0], js[key][1])
                     else:
                         nestedList = vars[key]
                         newValue = ''
                         newValueIndex = 0
                         indexList = 1
                         for value in js[key]:
                             if indexList < (len(js[key]) - 1):
                                 nestedList = Collections().get_from_list(
                                     nestedList, int(value))
                                 indexList = indexList + 1
                             elif indexList == (len(js[key]) - 1):
                                 newValueIndex = int(value)
                                 indexList = indexList + 1
                             elif indexList == len(js[key]):
                                 newValue = value
                         Collections().set_list_value(
                             nestedList, newValueIndex, newValue)
                 else:
                     BuiltIn().set_test_variable(key, js[key][0])
     except Exception as e:
         self._print_error_message('Setting variables error: ' + str(e) +
                                   ' Received data:' + str(data))
コード例 #3
0
 def __init__(self):
     self.oslib = OperatingSystem()
     self.collections = Collections()
コード例 #4
0
class ArchiveKeywords(object):
    ROBOT_LIBRARY_SCOPE = 'Global'

    tars = ['.tar', '.tar.bz2', '.tar.gz', '.tgz', '.tz2']

    zips = [
        '.docx', '.egg', '.jar', '.odg', '.odp', '.ods', '.xlsx', '.odt',
        '.pptx', 'zip'
    ]

    def __init__(self):
        self.oslib = OperatingSystem()
        self.collections = Collections()

    def extract_zip_file(self, zfile, dest=None):
        ''' Extract a ZIP file

        `zfile` the path to the ZIP file

        `dest` optional destination folder. It will be created if It doesn't exist.
        '''

        if dest:
            self.oslib.create_directory(dest)
            self.oslib.directory_should_exist(dest)

        cwd = os.getcwd()

        unzipper = Unzip()

        # Dont know why I a have `gotta catch em all` exception handler here
        try:
            unzipper.extract(zfile, dest)
        except:
            raise
        finally:
            os.chdir(cwd)

    def extract_tar_file(self, tfile, dest=None):
        ''' Extract a TAR file

        `tfile` the path to the TAR file

        `dest` optional destination folder. It will be created if It doesn't exist.
        '''
        if dest:
            self.oslib.create_directory(dest)

        self.oslib.file_should_exist(tfile)

        untarrer = Untar()
        untarrer.extract(tfile, dest)

    def archive_should_contain_file(self, zfile, filename):
        ''' Check if a file exists in the ZIP file without extracting it

        `zfile` the path to the ZIP file

        `filename` name of the file to search for in `zfile`
        '''
        self.oslib.file_should_exist(zfile)

        files = []
        if zipfile.is_zipfile(zfile):
            files = zipfile.ZipFile(zfile).namelist()
        else:
            files = tarfile.open(name=zfile).getnames()
        files = [os.path.normpath(item) for item in files]

        self.collections.list_should_contain_value(files, filename)
コード例 #5
0
import itertools
from SeleniumLibrary import SeleniumLibrary
from robot.libraries.BuiltIn import BuiltIn
from robot.api.deco import keyword
from robot.libraries.Collections import Collections
from time import time
from robot.utils import is_string

zoomba = BuiltIn()
zoomba_collections = Collections()

SCREENSHOT_COUNTER = itertools.count()


class GUILibrary(SeleniumLibrary):
    """Zoomba GUI Library

    This class inherits from the SeleniumLibrary Class, and expands it with some commonly used keywords. For more information on SeleniumLibrary please visit: https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html
    """

    def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Save Selenium Screenshot',
                 screenshot_root_directory=None, plugins=None, event_firing_webdriver=None):
        """GUILibrary can be imported with several optional arguments.

        - ``timeout``:
          Default value for `timeouts` used with ``Wait ...`` keywords.
        - ``implicit_wait``:
          Default value for `implicit wait` used when locating elements.
        - ``run_on_failure``:
          Default action for the `run-on-failure functionality`.
        - ``screenshot_root_directory``:
コード例 #6
0
class ArchiveKeywords(object):
    ROBOT_LIBRARY_SCOPE = 'Global'

    tars = ['.tar', '.tar.bz2', '.tar.gz', '.tgz', '.tz2']

    zips = ['.docx', '.egg', '.jar', '.odg', '.odp', '.ods', '.xlsx', '.odt',
            '.pptx', 'zip']

    def __init__(self):
        self.oslib = OperatingSystem()
        self.collections = Collections()

    def extract_zip_file(self, zfile, dest=None):
        ''' Extract a ZIP file

        `zfile` the path to the ZIP file

        `dest` optional destination folder. Assumes current working directory if it is none
               It will be created if It doesn't exist.
        '''
        
        if dest:
            self.oslib.create_directory(dest)
            self.oslib.directory_should_exist(dest)
        else:
            dest = os.getcwd()
       
        cwd = os.getcwd()

        unzipper = Unzip()

        # Dont know why I a have `gotta catch em all` exception handler here
        try:
            unzipper.extract(zfile, dest)
        except:
            raise
        finally:
            os.chdir(cwd)

    def extract_tar_file(self, tfile, dest=None):
        ''' Extract a TAR file

        `tfile` the path to the TAR file

        `dest` optional destination folder. Assumes current working directory if it is none
               It will be created if It doesn't exist.
        '''
        if dest:
            self.oslib.create_directory(dest)
        else:
            dest = os.getcwd()
            
        self.oslib.file_should_exist(tfile)

        untarrer = Untar()
        untarrer.extract(tfile, dest)

    def archive_should_contain_file(self, zfile, filename):
        ''' Check if a file exists in the ZIP file without extracting it

        `zfile` the path to the ZIP file

        `filename` name of the file to search for in `zfile`
        '''
        self.oslib.file_should_exist(zfile)

        files = []
        if zipfile.is_zipfile(zfile):
            files = zipfile.ZipFile(zfile).namelist()
        else:
            files = tarfile.open(name=zfile).getnames()
        files = [os.path.normpath(item) for item in files]

        self.collections.list_should_contain_value(files, filename)

    def create_tar_from_files_in_directory(self, directory, filename):
        ''' Take all files in a directory and create a tar package from them

        `directory` Path to the directory that holds our files

        `filename` Path to our destination TAR package.
        '''
        if not directory.endswith("/"):
            directory = directory + "/"
        tar = tarfile.open(filename, "w")
        files = os.listdir(directory)
        for name in files:
            tar.add(directory + name, arcname=name)
        tar.close()
		
    def create_zip_from_files_in_directory(self, directory, filename):
        ''' Take all files in a directory and create a zip package from them

        `directory` Path to the directory that holds our files

        `filename` Path to our destination ZIP package.
        '''
        if not directory.endswith("/"):
            directory = directory + "/"
        zip = zipfile.ZipFile(filename, "w")
        files = os.listdir(directory)
        for name in files:
            zip.write(directory + name, arcname=name)
        zip.close()
コード例 #7
0
 def validate_array_response_contain_keys(self, response, *keys):
     for i in range(len(response)):
         for key in keys:
             Collections().dictionary_should_contain_key(
                 response["{}".format(i + 1)], key)
コード例 #8
0
 def validate_output_should_contain_keys(self, dictionary, *keys):
     for key in keys:
         Collections().dictionary_should_contain_key(dictionary, key)
コード例 #9
0
 def __init__(self):
     self.oslib = OperatingSystem()
     self.collections = Collections()
コード例 #10
0
class ArchiveKeywords(object):
    ROBOT_LIBRARY_SCOPE = 'Global'

    tars = ['.tar', '.tar.bz2', '.tar.gz', '.tgz', '.tz2']

    zips = ['.docx', '.egg', '.jar', '.odg', '.odp', '.ods', '.xlsx', '.odt',
            '.pptx', 'zip']

    def __init__(self):
        self.oslib = OperatingSystem()
        self.collections = Collections()

    def extract_zip_file(self, zfile, dest=None):
        ''' Extract a ZIP file

        `zfile` the path to the ZIP file

        `dest` optional destination folder. Assumes current working directory if it is none
               It will be created if It doesn't exist.
        '''
        
        if dest:
            self.oslib.create_directory(dest)
            self.oslib.directory_should_exist(dest)
        else:
            dest = os.getcwd()
       
        cwd = os.getcwd()

        unzipper = Unzip()

        # Dont know why I a have `gotta catch em all` exception handler here
        try:
            unzipper.extract(zfile, dest)
        except:
            raise
        finally:
            os.chdir(cwd)

    def extract_tar_file(self, tfile, dest=None):
        ''' Extract a TAR file

        `tfile` the path to the TAR file

        `dest` optional destination folder. Assumes current working directory if it is none
               It will be created if It doesn't exist.
        '''
        if dest:
            self.oslib.create_directory(dest)
        else:
            dest = os.getcwd()
            
        self.oslib.file_should_exist(tfile)

        untarrer = Untar()
        untarrer.extract(tfile, dest)

    def archive_should_contain_file(self, zfile, filename):
        ''' Check if a file exists in the ZIP file without extracting it

        `zfile` the path to the ZIP file

        `filename` name of the file to search for in `zfile`
        '''
        self.oslib.file_should_exist(zfile)

        files = []
        if zipfile.is_zipfile(zfile):
            files = zipfile.ZipFile(zfile).namelist()
        else:
            files = tarfile.open(name=zfile).getnames()
        files = [os.path.normpath(item) for item in files]

        self.collections.list_should_contain_value(files, filename)

    def create_tar_from_files_in_directory(self, directory, filename):
        ''' Take all files in a directory and create a tar package from them

        `directory` Path to the directory that holds our files

        `filename` Path to our destination TAR package.
        '''
        if not directory.endswith("/"):
            directory = directory + "/"
        tar = tarfile.open(filename, "w")
        files = os.listdir(directory)
        for name in files:
            tar.add(directory + name, arcname=name)
        tar.close()
		
    def create_zip_from_files_in_directory(self, directory, filename):
        ''' Take all files in a directory and create a zip package from them

        `directory` Path to the directory that holds our files

        `filename` Path to our destination ZIP package.
        '''
        if not directory.endswith("/"):
            directory = directory + "/"
        zip = zipfile.ZipFile(filename, "w")
        files = os.listdir(directory)
        for name in files:
            zip.write(directory + name, arcname=name)
        zip.close()
コード例 #11
0
class ArchiveKeywords(object):
    ROBOT_LIBRARY_SCOPE = 'Global'

    tars = ['.tar', '.tar.bz2', '.tar.gz', '.tgz', '.tz2']

    zips = ['.docx', '.egg', '.jar', '.odg', '.odp', '.ods', '.xlsx', '.odt',
            '.pptx', 'zip']

    def __init__(self):
        self.oslib = OperatingSystem()
        self.collections = Collections()

    def extract_zip_file(self, zfile, dest=None):
        ''' Extract a ZIP file

        `zfile` the path to the ZIP file

        `dest` optional destination folder. It will be created if It doesn't exist.
        '''

        if dest:
            self.oslib.create_directory(dest)
            self.oslib.directory_should_exist(dest)

        cwd = os.getcwd()

        unzipper = Unzip()

        # Dont know why I a have `gotta catch em all` exception handler here
        try:
            unzipper.extract(zfile, dest)
        except:
            raise
        finally:
            os.chdir(cwd)

    def extract_tar_file(self, tfile, dest=None):
        ''' Extract a TAR file

        `tfile` the path to the TAR file

        `dest` optional destination folder. It will be created if It doesn't exist.
        '''
        if dest:
            self.oslib.create_directory(dest)

        self.oslib.file_should_exist(tfile)

        untarrer = Untar()
        untarrer.extract(tfile, dest)

    def archive_should_contain_file(self, zfile, filename):
        ''' Check if a file exists in the ZIP file without extracting it

        `zfile` the path to the ZIP file

        `filename` name of the file to search for in `zfile`
        '''
        self.oslib.file_should_exist(zfile)

        files = []
        if zipfile.is_zipfile(zfile):
            files = zipfile.ZipFile(zfile).namelist()
        else:
            files = tarfile.open(name=zfile).getnames()

        self.collections.list_should_contain_value(files, filename)
コード例 #12
0
class ArchiveKeywords:
    ROBOT_LIBRARY_SCOPE = 'Global'

    compressions = {
        "stored": zipfile.ZIP_STORED,
        "deflated": zipfile.ZIP_DEFLATED,
        "bzip2": zipfile.ZIP_BZIP2,
        "lzma": zipfile.ZIP_LZMA
    }

    tars = ['.tar', '.tar.bz2', '.tar.gz', '.tgz', '.tz2']

    zips = [
        '.docx', '.egg', '.jar', '.odg', '.odp', '.ods', '.xlsx', '.odt',
        '.pptx', 'zip'
    ]

    def __init__(self):
        self.oslib = OperatingSystem()
        self.collections = Collections()

    def extract_zip_file(self, zip_file, dest=None):
        """ Extract a ZIP file

        `zip_file` the path to the ZIP file

        `dest` optional destination folder. Assumes current working directory if it is none
               It will be created if It doesn't exist.
        """

        if dest:
            self.oslib.create_directory(dest)
            self.oslib.directory_should_exist(dest)
        else:
            dest = os.getcwd()

        cwd = os.getcwd()

        # Dont know why I a have `gotta catch em all` exception handler here
        try:
            Unzip().extract(zip_file, dest)
        except:
            raise
        finally:
            os.chdir(cwd)

    def extract_tar_file(self, tar_file, dest=None):
        """ Extract a TAR file

        `tar_file` the path to the TAR file

        `dest` optional destination folder. Assumes current working directory if it is none
               It will be created if It doesn't exist.
        """
        if dest:
            self.oslib.create_directory(dest)
        else:
            dest = os.getcwd()

        self.oslib.file_should_exist(tar_file)

        Untar().extract(tar_file, dest)

    def archive_should_contain_file(self, zip_file, filename):
        """ Check if a file exists in the ZIP file without extracting it

        `zip_file` the path to the ZIP file

        `filename` name of the file to search for in `zip_file`
        """
        self.oslib.file_should_exist(zip_file)

        files = zipfile.ZipFile(zip_file).namelist() if zipfile.is_zipfile(
            zip_file) else tarfile.open(zip_file).getnames()

        files = [os.path.normpath(item) for item in files]

        self.collections.list_should_contain_value(files, filename)

    def create_tar_from_files_in_directory(self,
                                           directory,
                                           filename,
                                           sub_directories=True):
        """ Take all files in a directory and create a tar package from them

        `directory` Path to the directory that holds our files

        `filename` Path to our destination TAR package.

        `sub_directories` Shall files in sub-directories be included - True by default.        
        """
        tar = tarfile.open(filename, "w")

        files = return_files_lists(directory, sub_directories)
        for filepath, name in files:
            tar.add(filepath, arcname=name)

        tar.close()

    @classmethod
    def create_zip_from_files_in_directory(cls,
                                           directory,
                                           filename,
                                           sub_directories=False,
                                           compression="stored"):
        """ Take all files in a directory and create a zip package from them

        `directory` Path to the directory that holds our files

        `filename` Path to our destination ZIP package.

        `sub_directories` Shall files in sub-directories be included - False by default.

        `compression` stored (default; no compression), deflated, bzip2 (with python >= 3.3), lzma (with python >= 3.3)
        """

        if cls.compressions.get(compression) is None:
            raise ValueError("Unknown compression method")
        comp_method = cls.compressions.get(compression)

        the_zip = zipfile.ZipFile(filename, "w", comp_method)

        files = return_files_lists(directory, sub_directories)
        for filepath, name in files:
            the_zip.write(filepath, arcname=name)

        the_zip.close()
コード例 #13
0
 def __init__(self):
     self.oslib = BuiltIn().get_library_instance("OperatingSystem")
     self.collections = Collections()