Class TestingbotREST

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class TestingbotREST
    extends java.lang.Object
    implements java.io.Closeable
    Java client for the TestingBot REST API. See testingbot.com/support/api for the full reference; the project README has a usage overview.

    Thread safety. Instances are thread-safe: they wrap a single shared CloseableHttpClient with bounded connect/socket timeouts. Create one instance per credential pair and reuse it across threads rather than constructing one per request.

    Lifecycle. The class implements Closeable; call close() (or use try-with-resources) when you are done to release pooled connections.

    Usage.

     try (TestingbotREST api = new TestingbotREST(KEY, SECRET)) {
         TestingbotTestCollection tests = api.getTests(0, 10);
         for (TestingbotTest t : tests.getData()) {
             System.out.println(t.getSessionId() + ": " + t.getStatusMessage());
         }
     }
     

    Errors. Every API method throws TestingbotApiException on a 4xx/5xx response — the exception carries the HTTP status and raw response body via TestingbotApiException.getStatusCode() and TestingbotApiException.getResponseBody() — and TestingbotUnauthorizedException on a 401. Both are unchecked runtime exceptions. Methods that return boolean return false only on a local transport or parse failure; HTTP-level failures propagate as exceptions.

    Most methods listed below were added in 1.1.0 as part of the full OpenAPI coverage; see the project CHANGELOG/release notes for the pre-1.1.0 baseline.

    Since:
    1.0
    Author:
    TestingBot
    • Field Detail

      • key

        protected java.lang.String key
        The key to use when performing HTTP requests to the TestingBot REST API.
      • secret

        protected java.lang.String secret
        The secret key to use when performing HTTP requests to the TestingBot REST API.
    • Constructor Detail

      • TestingbotREST

        public TestingbotREST​(java.lang.String key,
                              java.lang.String secret)
        Constructs a new instance of the TestingBotREST class.
        Parameters:
        key - The key to use when performing HTTP requests to the TestingBot REST API
        secret - The access key to use when performing HTTP requests to the TestingBot REST API
    • Method Detail

      • close

        public void close()
        Releases the underlying HTTP client and its connections. Call this when you are done with the client. Safe to call multiple times.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • updateTest

        public boolean updateTest​(TestingbotTest test)
        Updates a Test with sessionID (Selenium sessionID)
        Parameters:
        test - The meta-data to send to the TestingBot API in a TestingBotTest class. See https://testingbot.com/support/api#updatetest
        Returns:
        Boolean success response The API response
      • updateTest

        public boolean updateTest​(java.lang.String sessionID,
                                  java.util.Map<java.lang.String,​java.lang.Object> details)
        Updates a Test with sessionID (Selenium sessionID)
        Parameters:
        sessionID - The sessionID retrieved from Selenium WebDriver/RC
        details - The meta-data to send to the TestingBot API. See https://testingbot.com/support/api#updatetest
        Returns:
        Boolean success response The API response
      • stopTest

        public boolean stopTest​(java.lang.String sessionID)
        Stops a Test with sessionID (Selenium sessionID)
        Parameters:
        sessionID - The sessionID retrieved from Selenium WebDriver/RC
        Returns:
        Boolean response The API response
      • deleteTest

        public boolean deleteTest​(java.lang.String sessionID)
        Deletes a Test with sessionID (Selenium sessionID)
        Parameters:
        sessionID - The sessionID of the test to delete from TestingBot
        Returns:
        Boolean success
      • getBrowsers

        public java.util.ArrayList<TestingbotBrowser> getBrowsers()
        Gets list of available browsers from TestingBot
        Returns:
        ArrayList containing TestingbotBrowser objects.
      • getTests

        public TestingbotTestCollection getTests​(int offset,
                                                 int count)
        Get latest tests
        Parameters:
        offset - where to begin
        count - number of tests
        Returns:
        TestingbotTestCollection
      • getTest

        public TestingbotTest getTest​(java.lang.String sessionID)
        Gets information from TestingBot for a test with sessionID
        Parameters:
        sessionID - The sessionID retrieved from Selenium WebDriver/RC
        Returns:
        TestingbotTest
      • getUserInfo

        public TestingbotUser getUserInfo()
        Gets information from TestingBot for your user account
        Returns:
        response The API response
      • updateUserInfo

        public boolean updateUserInfo​(TestingbotUser testingbotUser)
        Updates information for a TestingBot User
        Parameters:
        testingbotUser - the user you are updating
        Returns:
        boolean success
      • getTunnels

        public java.util.ArrayList<TestingbotTunnel> getTunnels()
        Gets assigned tunnels for your account on TestingBot
        Returns:
        response The API response
      • deleteTunnel

        public boolean deleteTunnel​(java.lang.String tunnelID)
        Deletes a Tunnel with tunnel ID
        Parameters:
        tunnelID - The tunnelID of the tunnel to delete from TestingBot
        Returns:
        boolean
      • getTestsForBuild

        public TestingbotTestBuildCollection getTestsForBuild​(java.lang.String buildIdentifier)
        Gets tests for a specific build from TestingBot
        Parameters:
        buildIdentifier - the identifier (string) for the build
        Returns:
        response The API response
      • getBuilds

        public TestingbotBuildCollection getBuilds​(int offset,
                                                   int count)
        Get test builds
        Parameters:
        offset - where to begin
        count - number of builds
        Returns:
        TestingbotBuildCollection
      • deleteBuild

        public boolean deleteBuild​(java.lang.String buildId)
        Delete a specific build
        Parameters:
        buildId - the build identifier you want to delete
        Returns:
        boolean
      • uploadToStorage

        public TestingbotStorageUploadResponse uploadToStorage​(java.io.File file)
        Upload file to TestingBot Storage
        Parameters:
        file - The path to the local file you want to upload
        Returns:
        TestingbotStorageUploadResponse
      • uploadToStorage

        public TestingbotStorageUploadResponse uploadToStorage​(java.lang.String url)
        Upload file to TestingBot Storage
        Parameters:
        url - to the file (apk/ipa)
        Returns:
        TestingbotStorageUploadResponse
      • getStorageFile

        public TestingBotStorageFile getStorageFile​(java.lang.String appUrl)
        Retrieves meta-data from a TestingBot Storage file
        Parameters:
        appUrl - of the file
        Returns:
        TestingBotStorageFile file
      • getStorageFiles

        public TestingBotStorageFileCollection getStorageFiles​(int offset,
                                                               int count)
        Retrieves meta-data for TestingBot Storage files
        Parameters:
        offset - where to begin
        count - number of files
        Returns:
        TestingBotStorageFileCollection files
      • getAvailableDevices

        public java.util.List<TestingbotDevice> getAvailableDevices​(int offset,
                                                                    int count)
        Retrieves available Real Mobile Devices on TestingBot
        Parameters:
        offset - where to begin
        count - number of devices
        Returns:
        List containing TestingbotDevice objects.
      • getDevices

        public java.util.List<TestingbotDevice> getDevices​(int offset,
                                                           int count)
        Retrieves Real Mobile Devices on TestingBot This includes devices not currently available
        Parameters:
        offset - where to begin
        count - number of real devices
        Returns:
        List containing TestingbotDevice objects.
      • getDevice

        public TestingbotDevice getDevice​(int deviceId)
        Retrieves Real Mobile Devices on TestingBot
        Parameters:
        deviceId - - id of the Device
        Returns:
        TestingbotDevice device
      • deleteStorageFile

        public boolean deleteStorageFile​(java.lang.String appUrl)
        Delete a file previously uploaded TestingBot Storage
        Parameters:
        appUrl - of the file
        Returns:
        boolean success
      • getTests

        public TestingbotTestCollection getTests​(int offset,
                                                 int count,
                                                 java.util.Map<java.lang.String,​java.lang.String> filters)
        Get latest tests, with optional server-side filters (e.g. since, browser_id, group, build, skip_fields).
        Parameters:
        offset - where to begin
        count - number of tests
        filters - additional query filters (may be null or empty)
        Returns:
        TestingbotTestCollection
      • iterateTests

        public java.lang.Iterable<TestingbotTest> iterateTests​(int pageSize)
        Lazily iterates over all tests, paging through the API behind the scenes. Iteration stops when the API returns a page smaller than pageSize.

        Each call to Iterable.iterator() starts a fresh walk from offset 0.

        Parameters:
        pageSize - the number of tests to fetch per request (must be > 0)
        Returns:
        an Iterable that walks every test in the account
      • iterateTests

        public java.lang.Iterable<TestingbotTest> iterateTests​(int pageSize,
                                                               java.util.Map<java.lang.String,​java.lang.String> filters)
        Lazily iterates over all tests matching the given filters, paging behind the scenes.
        Parameters:
        pageSize - the number of tests to fetch per request (must be > 0)
        filters - optional server-side filters (may be null)
        Returns:
        an Iterable that walks every matching test
      • createTest

        public boolean createTest​(java.util.Map<java.lang.String,​java.lang.Object> testFields)
        Creates a new test on TestingBot. See https://testingbot.com/support/api

        The fields are sent as Rails-style test[key] parameters. Common keys: name, success, status_message, build, extra.

        Parameters:
        testFields - the test fields to set
        Returns:
        boolean success
        Since:
        1.1.0
      • getDevices

        public java.util.List<TestingbotDevice> getDevices​(java.lang.String platform,
                                                           java.lang.Boolean web)
        Retrieves Real Mobile Devices on TestingBot, filtered by platform.
        Parameters:
        platform - one of Android, iOS, REAL_ANDROID, REAL_IOS (may be null)
        web - when non-null, filters on web-testing capable devices
        Returns:
        List containing TestingbotDevice objects.
      • getAvailableDevices

        public java.util.List<TestingbotDevice> getAvailableDevices()
        Retrieves the currently available Real Mobile Devices on TestingBot.
        Returns:
        List containing TestingbotDevice objects.
      • getTunnel

        public TestingbotTunnel getTunnel()
        Gets the currently active tunnel for your account.
        Returns:
        TestingbotTunnel
      • getTunnel

        public TestingbotTunnel getTunnel​(int tunnelId)
        Gets a specific tunnel by its id.
        Parameters:
        tunnelId - the id of the tunnel
        Returns:
        TestingbotTunnel
      • createTunnel

        public TestingbotTunnel createTunnel()
        Creates (boots) a new tunnel.
        Returns:
        TestingbotTunnel
      • deleteTunnel

        public boolean deleteTunnel()
        Stops the currently active tunnel for your account.
        Returns:
        boolean success
      • isTunnelAlive

        public boolean isTunnelAlive()
        Checks whether the tunnel is alive.
        Returns:
        boolean alive
      • getJob

        public TestingbotJob getJob​(java.lang.String jobId)
        Gets the status of a job (e.g. a Codeless test run).
        Parameters:
        jobId - the id of the job
        Returns:
        TestingbotJob
      • getUserKeys

        public com.google.gson.JsonElement getUserKeys()
        Retrieves your API key and secret.
        Returns:
        the raw JSON response
      • getIpRanges

        public com.google.gson.JsonElement getIpRanges()
        Retrieves the TestingBot IP ranges for firewall whitelisting.
        Returns:
        the raw JSON response
      • getTeam

        public TestingbotTeam getTeam()
        Gets your team's concurrency information.
        Returns:
        TestingbotTeam
      • createTeamMember

        public TestingbotTeamMember createTeamMember​(java.util.Map<java.lang.String,​java.lang.Object> params)
        Creates a new user in your team.

        Required keys: email, password. Optional keys: first_name, last_name, concurrency (max parallel VM sessions), concurrencyPhysical (max parallel physical-device sessions).

        Parameters:
        params - the new user's attributes
        Returns:
        TestingbotTeamMember
        Since:
        1.1.0
      • getTeamMember

        public TestingbotTeamMember getTeamMember​(int userId)
        Gets a specific team user.
        Parameters:
        userId - the id of the team user
        Returns:
        TestingbotTeamMember
      • updateTeamMember

        public TestingbotTeamMember updateTeamMember​(int userId,
                                                     java.util.Map<java.lang.String,​java.lang.Object> params)
        Updates a team user.
        Parameters:
        userId - the id of the team user
        params - the attributes to update
        Returns:
        TestingbotTeamMember
      • getTeamMemberClientKey

        public com.google.gson.JsonElement getTeamMemberClientKey​(int userId)
        Gets the client key of a team user.
        Parameters:
        userId - the id of the team user
        Returns:
        the raw JSON response
      • resetTeamMemberKeys

        public TestingbotTeamCredentialReset resetTeamMemberKeys​(int userId)
        Resets the API keys of a team user.
        Parameters:
        userId - the id of the team user
        Returns:
        TestingbotTeamCredentialReset
      • createScreenshots

        public TestingbotScreenshot createScreenshots​(java.util.Map<java.lang.String,​java.lang.Object> params)
        Captures a new screenshot batch.

        Required keys: url (page URL), resolution (e.g. "1920x1080"), browsers (a List<String>; each entry is a browser_id or a "browser version os" triple). Optional keys: wait_time (seconds to wait after page load), fullpage (capture the entire scrollable page), callback_url (POST callback when the batch completes).

        Parameters:
        params - the screenshot batch parameters
        Returns:
        TestingbotScreenshot
        Since:
        1.1.0
      • getScreenshot

        public TestingbotScreenshot getScreenshot​(int screenshotId)
        Gets a specific screenshot batch.
        Parameters:
        screenshotId - the id of the screenshot batch
        Returns:
        TestingbotScreenshot
      • updateManualSession

        public boolean updateManualSession​(int sessionId,
                                           java.util.Map<java.lang.String,​java.lang.Object> fields)
        Updates a manual session.

        Fields are sent as Rails-style manual_session[key] parameters. Keys: name, success (boolean), status_message.

        Parameters:
        sessionId - the numeric manual-session id
        fields - the fields to update
        Returns:
        boolean success
        Since:
        1.1.0
      • pingManualSession

        public boolean pingManualSession​(java.util.List<java.lang.Integer> sessionIds)
        Sends a keepalive ping for the given manual sessions.
        Parameters:
        sessionIds - the numeric ids of the manual sessions to ping
        Returns:
        boolean success
      • createLabTest

        public TestingbotLabCreateAck createLabTest​(java.util.Map<java.lang.String,​java.lang.Object> testFields)
        Creates a new Codeless test.

        The fields are sent as Rails-style test[key] parameters. Keys: name, url (target URL, required unless a file is uploaded), cron (cron expression for scheduled runs), screenshot (boolean — take screenshots every step), video (boolean), idletimeout (seconds), screenresolution (e.g. "1920x1080"), ai_prompt (instruction for the AI test agent).

        Parameters:
        testFields - the test attributes
        Returns:
        TestingbotLabCreateAck (includes lab_test_id)
        Since:
        1.1.0
      • getLabTest

        public TestingbotLabTest getLabTest​(int labTestId)
        Gets a specific Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        Returns:
        TestingbotLabTest
      • updateLabTest

        public boolean updateLabTest​(int labTestId,
                                     java.util.Map<java.lang.String,​java.lang.Object> testFields)
        Updates a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        testFields - the attributes to update (sent as test[...])
        Returns:
        boolean success
      • deleteLabTest

        public boolean deleteLabTest​(int labTestId)
        Deletes a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        Returns:
        boolean success
      • getLabTestSteps

        public TestingbotLabTestStepCollection getLabTestSteps​(int labTestId)
        Gets the steps of a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        Returns:
        TestingbotLabTestStepCollection
      • setLabTestSteps

        public boolean setLabTestSteps​(int labTestId,
                                       java.util.List<java.lang.String> steps)
        Replaces the steps of a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        steps - the ordered list of steps
        Returns:
        boolean success
      • getLabTestBrowsers

        public java.util.List<TestingbotBrowser> getLabTestBrowsers​(int labTestId)
        Gets the browsers configured for a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        Returns:
        List containing TestingbotBrowser objects.
      • setLabTestBrowsers

        public boolean setLabTestBrowsers​(int labTestId,
                                          java.lang.String browserIds)
        Updates the browsers a Codeless test runs on.
        Parameters:
        labTestId - the id of the Codeless test
        browserIds - comma-separated list of browser_ids
        Returns:
        boolean success
      • triggerLabTest

        public TestingbotLabRunAck triggerLabTest​(int labTestId)
        Runs a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        Returns:
        TestingbotLabRunAck
      • stopLabTest

        public boolean stopLabTest​(int labTestId)
        Stops a running Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        Returns:
        boolean success
      • addLabTestAlert

        public boolean addLabTestAlert​(int labTestId,
                                       java.util.Map<java.lang.String,​java.lang.Object> params)
        Adds an alert to a Codeless test.

        Required keys:

        • kind — one of "EMAIL", "API", "SMS".
        • level"IMMEDIATELY" or "DAILY".
        • content — destination (email address, callback URL, or phone number).
        Parameters:
        labTestId - the id of the Codeless test
        params - the alert parameters
        Returns:
        boolean success
        Since:
        1.1.0
      • updateLabTestAlert

        public boolean updateLabTestAlert​(int labTestId,
                                          java.util.Map<java.lang.String,​java.lang.Object> params)
        Updates the alert of a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        params - the alert parameters
        Returns:
        boolean success
      • createLabTestReport

        public boolean createLabTestReport​(int labTestId,
                                           java.util.Map<java.lang.String,​java.lang.Object> params)
        Creates a report for a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        params - the report parameters
        Returns:
        boolean success
      • updateLabTestReport

        public boolean updateLabTestReport​(int labTestId,
                                           java.util.Map<java.lang.String,​java.lang.Object> params)
        Updates a report for a Codeless test.
        Parameters:
        labTestId - the id of the Codeless test
        params - the report parameters
        Returns:
        boolean success
      • scheduleLabTest

        public boolean scheduleLabTest​(int labTestId,
                                       java.util.Map<java.lang.String,​java.lang.Object> params)
        Sets or updates the schedule of a Codeless test.

        Keys:

        • type — preset: "once", "daily", "weekly", or "custom" (use cronFormat).
        • day — date (YYYY-MM-DD) for once, or weekday for weekly.
        • hour — time (HH:MM) for once, daily, or weekly.
        • cronFormat — raw 5-field cron expression (used when type=custom).
        Parameters:
        labTestId - the id of the Codeless test
        params - the schedule parameters
        Returns:
        boolean success
        Since:
        1.1.0
      • triggerAllLabTests

        public TestingbotLabRunAck triggerAllLabTests()
        Runs all Codeless tests.
        Returns:
        TestingbotLabRunAck
      • createLabSuite

        public TestingbotLabSuiteCreateAck createLabSuite​(java.util.Map<java.lang.String,​java.lang.Object> suiteFields)
        Creates a new Codeless test suite.

        The fields are sent as Rails-style suite[key] parameters. Required key: name. Optional keys: cron, screenshot (boolean), video (boolean), idletimeout (seconds), screenresolution (e.g. "1920x1080").

        Parameters:
        suiteFields - the suite attributes
        Returns:
        TestingbotLabSuiteCreateAck (includes suite_id)
        Since:
        1.1.0
      • getLabSuite

        public TestingbotLabSuite getLabSuite​(int suiteId)
        Gets a specific Codeless test suite.
        Parameters:
        suiteId - the id of the suite
        Returns:
        TestingbotLabSuite
      • deleteLabSuite

        public boolean deleteLabSuite​(int suiteId)
        Deletes a Codeless test suite.
        Parameters:
        suiteId - the id of the suite
        Returns:
        boolean success
      • getLabSuiteTests

        public TestingbotLabTestCollection getLabSuiteTests​(int suiteId)
        Gets the tests in a Codeless suite.
        Parameters:
        suiteId - the id of the suite
        Returns:
        TestingbotLabTestCollection
      • addLabSuiteTests

        public boolean addLabSuiteTests​(int suiteId,
                                        java.lang.String testIds)
        Adds tests to a Codeless suite.
        Parameters:
        suiteId - the id of the suite
        testIds - comma-separated list of Codeless test ids
        Returns:
        boolean success
      • removeLabSuiteTest

        public boolean removeLabSuiteTest​(int suiteId,
                                          int testId)
        Removes a test from a Codeless suite.
        Parameters:
        suiteId - the id of the suite
        testId - the id of the test to remove
        Returns:
        boolean success
      • getLabSuiteBrowsers

        public java.util.List<TestingbotBrowser> getLabSuiteBrowsers​(int suiteId)
        Gets the browsers configured for a Codeless suite.
        Parameters:
        suiteId - the id of the suite
        Returns:
        List containing TestingbotBrowser objects.
      • setLabSuiteBrowsers

        public boolean setLabSuiteBrowsers​(int suiteId,
                                           java.lang.String browserIds)
        Updates the browsers a Codeless suite runs on.
        Parameters:
        suiteId - the id of the suite
        browserIds - comma-separated list of browser_ids
        Returns:
        boolean success
      • triggerLabSuite

        public TestingbotLabRunAck triggerLabSuite​(int suiteId)
        Runs a Codeless suite.
        Parameters:
        suiteId - the id of the suite
        Returns:
        TestingbotLabRunAck
      • getAuthenticationHash

        public java.lang.String getAuthenticationHash​(java.lang.String identifier)
        Calculates the authentication hash for a specific identifier (sessionId/build-identifier) https://testingbot.com/support/other/sharing
        Parameters:
        identifier - the sessionId or buildIdentifier
        Returns:
        String hash
      • getAuthenticationHash

        public java.lang.String getAuthenticationHash()
        Calculates the authentication hash for the current user https://testingbot.com/support/other/sharing
        Returns:
        String hash