Skip to main content

Keywords lib to read a txt file

Project description

Official repository (Dictionary file)

Project logo

Dicionary file


Few lines describing your project.

Table of Contents

About

This project aims to manipulate files (txt and yaml) to save requests in a REST API. Ex.: save the requests that will be used in a POST in a .txt file, thus making the project more organized.

Prerequisites

  • generate-lib
  • Robotframework

Installing

To install the library just use command line:

pip install dictionary-file

In addition to having python installed. Obs.: You can create a python environment(recommended) or not.

Running the tests

To run the functions just import the library in your robotframework project.

*** Settings ***
Library    dictionary_file
*** Keywords ***
Library testing
    ${t}        CREATE DICT BY FILE TXT    file_name=${EMPTY}        full_path=C:\\Users\\Vericoders\\Documents\\test-lib\\dicionario.txt
    UPDATE DICTIONARY    ${t}     name=Yuri
    Log To Console    \n${t}
*** Test Cases ***
Scenario 01
    [Tags]        teste
    Library testing

The keyword (CREATE DICT FILE TXT) create a dictionary through txt file.

def create_dict_by_file_txt(self, name_file: str, full_path: str = None) -> dict:
        if full_path is None:
            arq =  open(os.path.dirname(__file__) + f"/{name_file}", 'r')
        elif full_path is not None and name_file == "":
            arq =  open(f"{full_path}", 'r')
        lines = arq.readlines()
        dict_ = dict()
        for line in lines:
            if line is not None and "=" in line:
                list_kys_values = ''.join(line.replace(' ', '')).split(',')
                for item in list_kys_values:
                    key = item.split('=')[0]
                    value = item.split('=')[1]  
                    if "@" in value:
                        value =  generate_email_random(1)
                    if self.LINE_BREAK in value: 
                        value = value.replace(self.LINE_BREAK, '')
                    if value.startswith(self.STR):
                        value = value.replace(self.STR, '').replace(')', '')
                    if value.startswith(self.INT):
                        value = int(value.replace(self.INT, '').replace(')', ''))                                                          
                    dict_.update({key: value})               
            else:
                break
        return dict_

The file .txt needs to contains some features. Example:

name=str(kaio), email=str(kaio.santiago@hotmail.com), password=int(1234), admin=str(true)

Values of dict needs to be defined type as in the example above.

  • string: str()
  • int: int(number_int)
  • bool: bool(true_or_false)

Usage

Use to take information through txt file to create dictionary. This is useful to create requisition(dictionary) to test automation API REST.

Built Using

  • Python - Programming language
  • Robot - Automation Framework

Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dictionary-file-lib-0.0.4.tar.gz (4.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page