TestProject Forum

Can we access api in 'version 2.0's offline mode?

Can we access api in 'version 2.0’s offline mode?

Hi, if by access api you refer to invoke API calls with the restful API addon (HTTP get, post, etc) as part of your test, yes you can. basically downloaded tests will run exactly the same like tests that stored in the cloud, if addons are used the TestProject agent will make sure to download all of the dependencies including addon atutomatcily prior execution. if you are running in the completely isolated environment make sure to download your test as β€œTest Package” , by doing that all of the dependencies will be downloaded and zipped to a single file, that is capable to run completely offline, no agent registration will be required in this case as well.

how to download as "Test Package"

how the API saved test will look like as file

id: DELETED
projectId: DELETED
projectName: 2021
created: 2021-03-17T11:47:01.5576790Z
protocol: 1
tests:

  • id: zFnO_SqUzUumhDs-1HIKvg
    name: Simple API Test
    description: β€˜β€™
    platform: Web
    type: Web
    driverType: Chrome
    version: 0.1
    creationDate: 2021-03-17T09:58:16.0000000
    modificationDate: 2021-03-17T11:46:46.0000000
    settings:
    automationAssistant: true
    appId: RcyI-hGzrEaqbX9SPaHBNg
    stepSleepTime: 500
    stepTimeout: 15000
    stepSleepTiming: Before
    stepFailureBehaviorType: Abort
    stepTakeScreenshotConditionType: Failure
    application:
    id: RcyI-hGzrEaqbX9SPaHBNg
    name: Example web site
    url: https://example.testproject.io/
    platform: Web
    steps:
    • id: W3D3SGbyv02ffb_yRZF6gg
      comments: Navigates the specified URL (Auto-generated)
      enabled: true
      invertResult: false
      order: 1
      repeat: 1
      type: Action
      settings:
      sleepTime: -1
      timeout: -1
      sleepTiming: Inherit
      failureBehaviorType: Inherit
      takeScreenshotConditionType: Inherit
      action:
      id: 49c5d8d8-4ba8-42f0-823d-702e6acfb23a
      source: System
      parameterMaps:
      • name: url
        value: β€˜{{ApplicationURL}}’
        direction: Input
        conditions:
        validations:
        contexts:
    • id: EvVl-3asBE6sEnyhX0SD3g
      comments: β€˜β€™
      enabled: true
      invertResult: false
      order: 2
      repeat: 1
      type: Addon
      settings:
      sleepTime: -1
      timeout: -1
      sleepTiming: Inherit
      failureBehaviorType: Inherit
      takeScreenshotConditionType: Inherit
      action:
      id: DiRlYudmtUGjjOgGCGzRIA
      source: Store
      addonId: Ujn6E4VbkEa6QU2XChYMyQ
      parameterMaps:
      • name: uri
        value: β€˜{{tested_API}}’
        direction: Input
      • name: query
        value: β€˜{{Query_Param}}’
        direction: Input
      • name: headers
        value: β€˜β€™
        direction: Input
      • name: expectedStatus
        value: 200
        direction: Input
      • name: jsonPath
        value: β€˜{{value_to_extract}}’
        direction: Input
      • name: response
        value: β€˜β€™
        direction: Output
      • name: status
        value: β€˜β€™
        direction: Output
      • name: ignoreUntrustedCertificate
        value: β€˜β€™
        direction: Input
      • name: responseHeaders
        value: β€˜β€™
        direction: Output
      • name: jsonResponse
        value: β€˜β€™
        direction: Output
      • name: schemaPath
        value: β€˜β€™
        direction: Input
      • name: createFile
        value: β€˜β€™
        direction: Input
      • name: schemaValidationOutputFilePath
        value: β€˜β€™
        direction: Input
      • name: schemaValidationOutput
        value: β€˜β€™
        direction: Output
      • name: headerDelimiter
        value: β€˜β€™
        direction: Input
        conditions:
        validations:
        contexts:
        parameters:
    • name: ApplicationURL
      description: Auto generated application URL parameter
      value: https://example.testproject.io/
      type: Input
    • name: tested_API
      description: β€˜β€™
      value: https://api.nasa.gov/neo/rest/v1/neo/browse
      type: Input
    • name: Query_Param
      description: β€˜β€™
      value: api_key=DEMO_KEY
      type: Input
    • name: value_to_extract
      description: β€˜β€™
      value: $.near_earth_objects[0].neo_reference_id
      type: Input
      auxTests:
      elements:
      projectParameters:
      addons:
  • id: DELETED
    source: Store
    version: 1.5
    actions:
    • id: DiRlYudmtUGjjOgGCGzRIA
      name: HTTP GET Request
      description: GET {{uri}}?{{query}}
      className: io.testproject.addon.restfulapiclient.actions.GetAction
      minSdkLevel: 0
      minSdkVersion: 0.0.0
      sdkGeneration: 1
      language: Java
      hash: DELETED
1 Like

Hi Mark, thank you for you answer. Please could you let me know what would be the url to reach api in offline mode? Is it running on any particular port? To trigger tests on your server I use https://api.testproject.io/v2/projects/.... Would I need something like localhost:port/api.testproject.io/v2/projects/...?

the local agent url is http://localhost:8585 , but if you want to run your test in the offline mode why not simply use the CLI tool like this: testproject-agent run MyFirstTest.yaml ?

Awesome thank you Mark. Yes to CLI in the future but this will require rewriting what I have already written so far, so I will need to use api for now.

Would I be able using just CLI tool to check the status of recently run test? I know there is report.html, but all I need is to know if the test is successful or not.

Thank you

Hello @mkulik
For that, you still need to use our REST API, using this endpoint:
https://api.testproject.io/docs/v2/#/Reports/Reports_GetV2ProjectsByProjectIdJobsByJobIdReportsLatest

You will get it in a JSON format where you can validate the result of the test/job, if it has passed or failed.

In the future, we will provide the result of the execution locally in JSON format as well.

thank you @ran.tzur, please could you let me know if there is any timeline for this feature to be released?