From b48f2b7e2ae94994d939b8b298dab1c8a64cb592 Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Tue, 11 Jan 2022 10:36:15 -0300 Subject: [PATCH] AutoIt client 1st version. --- api/autoit/cli.py | 38 +++++++++++++++++++++++++++--- api/autoit/features/steps/steps.py | 31 +++++++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/api/autoit/cli.py b/api/autoit/cli.py index 7e39eec..24a4dfb 100644 --- a/api/autoit/cli.py +++ b/api/autoit/cli.py @@ -13,10 +13,10 @@ class AutoIt: """ ep: str = "" - def __init__(self): + def __init__ (self): self.ep = "https://localhost:8443" - def __request_raw_post__(self, path: str, data: str): + def __request_raw_post__ (self, path: str, data: str = ""): """ ## HTTP RAW POST @@ -38,4 +38,36 @@ class AutoIt: if res.headers.get("Content-Type") != None and res.headers.get("Content-Type").find("json") != -1: return json.loads(res.text) else: - return res.text \ No newline at end of file + return res.text + + def test (self): + """ + ## AutoIt test + Este método é utilizado para testar se o AutoIt está corretamente instalado na máquina do usuário, além de garantir que o serviço também está instalado e funcionando corretamente. + + --- + #### Parâmetros: + --- + + --- + #### Retorna: + -> "Autoit Svc Ok" caso tudo esteja funcionando corretamente. + """ + + return self.__request_raw_post__ ("/ipc/autoit/test") + + def do (self, command: str): + """ + ## AutoIt Do + Realiza algum comando Autoit passado como parâmetro. + + --- + #### Parâmetros: + - command: Comando autoit que se deseja executar + + --- + #### Retorna: + -> O retorno do comando, se houver. + """ + + return self.__request_raw_post__ ("/ipc/autoit/do", command) diff --git a/api/autoit/features/steps/steps.py b/api/autoit/features/steps/steps.py index a1f9eee..5b1271c 100644 --- a/api/autoit/features/steps/steps.py +++ b/api/autoit/features/steps/steps.py @@ -1,3 +1,32 @@ +from typing import Text from behave import * -from cli import AutoIt \ No newline at end of file +from cli import AutoIt + +# ================================== AutoIt Test ================================== +@given(u'the AutoIt client') +def step_impl(context): + context.client = AutoIt() + +@when(u'the test method is called') +def step_impl(context): + context.test_return = context.client.test() + +@then(u'the string "Autoit Svc Ok" must be returned') +def step_impl(context): + assert context.test_return == "Autoit Svc Ok", "There is something wrong with your AutoIt." + + +# ================================== AutoIt Do ================================== +@when(u'the do method is called with "ClipPut ( "test" )"') +def step_impl(context): + context.do_return = context.client.do('ClipPut ( "test" )') + +@then(u'the string "test" must me recorded on ClipBoard') +def step_impl(context): + print (f""" + ----------------- + {context.client.do ( "ClipGet ( )" )} + ----------------- + """) + assert context.client.do( "ClipGet ()" ) == "", "Something went wrong with the ClipPut method." \ No newline at end of file