Class: ZgenClient

Inherits:
Object
  • Object
show all
Defined in:
lib/zgen_client.rb

Overview

The Zgen Client main class.

Constant Summary collapse

@@users_login_endpoint =
"users/login"
@@test_execution_endpoint =
"v1/Incident/TestCaseExecution"
@@attachment_endpoint =
"v1/Incident/attachment"

Instance Method Summary collapse

Constructor Details

#initialize(api_host:, api_port:, user_email:, user_password:, user_customer_name:, proxy_host: nil, proxy_port: nil, timeout: 30, is_https: false) ⇒ ZgenClient

Returns a new instance of ZgenClient.

Parameters:

  • api_host (String)

    The host of the Knooly API such as IP address like 192.168.0.1 or knooly-clientname.keeggo.com.

  • api_port (Integer)

    The API port per example 80 (default http port) or 443 (default https port).

  • user_email (String)

    The user e-mail used to authenticate on API.

  • user_password (String)

    The user password used to authenticate on API.

  • user_customer_name (String)

    The customer name that is associated with the user_email.

  • proxy_host (String) (defaults to: nil)

    Pass the value of the proxy IP address if there is a proxy between you and the API. (Not required)

  • proxy_port (Integer) (defaults to: nil)

    The proxy port like 8080. (Not required)

  • timeout (Integer) (defaults to: 30)

    The amount of time in seconds for the client to read, write and connect to the API before timing out. (Not required)

  • is_https (true, false) (defaults to: false)

    true, if the API address URL starts with https, otherwise false. (Not required)



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/zgen_client.rb', line 24

def initialize(api_host:, api_port:, user_email:, user_password:, user_customer_name:, proxy_host: nil, proxy_port: nil, timeout: 30, is_https: false)
  @api_host = api_host
  @api_port = api_port
  @user_email = user_email
  @user_password = user_password
  @user_customer_name = user_customer_name
  @proxy_host = proxy_host
  @proxy_port = proxy_port
  @timeout = timeout
  @is_https = is_https
  @token = nil
  @user_id = nil
end

Instance Method Details

#post_attachment(test_result_id:, evidence:) ⇒ String

Send an attachment as the evidence of a test execution result that was previosly saved using #post_test_execution.

Parameters:

  • test_result_id (String)

    Test result id returned from the method #post_test_execution

  • evidence (File)

    The attachment file to send. It can be an image, pdf or video file per example.

Returns:

  • (String)

    Attachment id



64
65
66
67
68
69
70
# File 'lib/zgen_client.rb', line 64

def post_attachment(test_result_id:, evidence:)
  url = "#{build_base_url()}/#{@@attachment_endpoint}"
  headers = { :Authorization => "Bearer #{get_token()}" }
  body = { :File => evidence, :TestResultId => test_result_id }
  response = RestClient.post(url, body, headers)
  JSON.parse(response.body)["attachmentID"]
end

#post_test_execution(project_id:, execution_code:, cycle_start_date:, test_result_ok:, date:, test_result_comments: "", tags: [], incident_id: nil, status: nil, status_date: nil) ⇒ String

Create a test case result with the information passed from a test case.

Parameters:

  • project_id (Integer)

    The project id is generated when a project is registered in Knooly. For more information access Help Knooly > Projetos > Criando um projeto de teste on Knooly documentation.

  • execution_code (String)

    The execution code assigned to the scenario. This field is used in automated test integration and is available in scenario name. For more information access Help Knooly > Projetos > Adicionando cobertura ao projeto on Knooly documentation.

  • cycle_start_date (String)

    The initial date of the project cycle. It can be obtained from Knooly. For more information access Help Knooly > Projetos > Definindo os ciclos de execução on Knooly documentation.

  • test_result_ok (true, false)

    True if the scenario execution result was passed, otherwise false.

  • date (String)

    Date of scenario test execution (generated in runtime). Format: 2022-02-09 00:00:00.

  • test_result_comments (String) (defaults to: "")

    Comments to assign to test result. (Not required)

  • tags (Array<String>) (defaults to: [])

    List of tags. (Not required)

  • incident_id (Integer) (defaults to: nil)

    Incident id. (Not required)

  • status (String) (defaults to: nil)

    Status. (Not required)

  • status_date (String) (defaults to: nil)

    Status date. (Not required)

Returns:

  • (String)

    Test result id.



51
52
53
54
55
56
57
# File 'lib/zgen_client.rb', line 51

def post_test_execution(project_id:, execution_code:, cycle_start_date:, test_result_ok:, date:, test_result_comments: "", tags: [], incident_id: nil, status: nil, status_date: nil)
  url = "#{build_base_url()}/#{@@test_execution_endpoint}"
  headers = { :Authorization => "Bearer #{get_token()}", content_type: "application/json" }
  body = { projectID: project_id, executionCode: execution_code, cycleStartDate: cycle_start_date, testResultOK: test_result_ok, testerUserID: @user_id, testResultComments: test_result_comments, date: date, tags: tags, incidentID: incident_id, status: status, statusDate: status_date }.to_json
  response = RestClient.post(url, body, headers)
  JSON.parse(response.body)["testResultID"]
end