Package io.testproject.sdk.internal.rest
Class AgentClient
- java.lang.Object
-
- io.testproject.sdk.internal.rest.AgentClient
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class AgentClient extends java.lang.Object implements java.io.Closeable
-
-
Field Summary
Fields Modifier and Type Field Description static intREPORTS_QUEUE_TIMEOUTMaximum amount of time to wait in seconds before forcibly terminating the queue.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Implementation ofClosableinterface.voidclose(boolean exiting)Close all open resources such as the reporting queue and the TCP socket open with the Agent if the process is exiting.ActionExecutionResponseexecuteProxy(ActionProxy action, int timeout)Executes a Action proxy from an Addon installed in an Account.static AgentClientgetClient(java.lang.String token, org.openqa.selenium.Capabilities capabilities)Creates (or searches for an existing) instance ofAgentClientusing provided token and capabilities.static AgentClientgetClient(java.lang.String token, org.openqa.selenium.Capabilities capabilities, ReportSettings reportSettings)Creates (or searches for an existing) instance ofAgentClientusing provided token and capabilities.static AgentClientgetClient(java.net.URL remoteAddress, java.lang.String token, org.openqa.selenium.Capabilities capabilities, ReportSettings reportSettings, boolean disableReports)Creates (or searches for an existing) instance ofAgentClientusing provided remoteAddress, token and capabilities.static AgentClientgetClient(java.net.URL remoteAddress, org.openqa.selenium.Capabilities capabilities)Creates (or searches for an existing) instance ofAgentClientusing provided remoteAddress and capabilities.static AgentClientgetClient(java.net.URL remoteAddress, org.openqa.selenium.Capabilities capabilities, ReportSettings reportSettings)Creates (or searches for an existing) instance ofAgentClientusing provided remoteAddress and capabilities.static AgentClientgetClient(org.openqa.selenium.Capabilities capabilities)Creates (or searches for an existing) instance ofAgentClientusing provided capabilities.static AgentClientgetClient(org.openqa.selenium.Capabilities capabilities, ReportSettings reportSettings)Creates (or searches for an existing) instance ofAgentClientusing provided capabilities.static AgentClientgetInstance()Get current instance of the AgentClient.java.lang.StringgetJobName()Getter forjobName.java.lang.StringgetProjectName()Getter forprojectName.ReportSettingsgetReportSetting()AgentSessiongetSession()Getter forsessionfield.booleangetSkipInferring()Getter forfield.java.lang.StringgetVersion()Getter forversionfield.static java.lang.StringgetVersion(java.net.URL remoteAddress)Retrieves the version of the target Agent.static booleanisWarned()Getter forfield.booleanreportCommand(org.openqa.selenium.remote.Command command, java.lang.Object result, boolean passed, java.lang.String screenshot)Reports a driver command execution to the Agent.booleanreportStep(StepReport report)Reports a step to the Agent.booleanreportTest(TestReport report)Reports a test to the Agent.voidupdateJobName(java.lang.String updatedJobName)Sent request to Agent API to update job name at runtime.
-
-
-
Field Detail
-
REPORTS_QUEUE_TIMEOUT
public static final int REPORTS_QUEUE_TIMEOUT
Maximum amount of time to wait in seconds before forcibly terminating the queue.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static AgentClient getInstance()
Get current instance of the AgentClient. Method is meant for internal use only.- Returns:
- current instance of AgentClient.
-
getClient
public static AgentClient getClient(org.openqa.selenium.Capabilities capabilities) throws AgentConnectException, InvalidTokenException, java.net.MalformedURLException, ObsoleteVersionException
Creates (or searches for an existing) instance ofAgentClientusing provided capabilities.- Parameters:
capabilities-Capabilitiesto be used for creatingAgentClientor finding a cached one- Returns:
- An instance of an AgentClient class.
- Throws:
AgentConnectException- if Agent is not responding or responds with an errorInvalidTokenException- if the token provided is invalidjava.net.MalformedURLException- if the Agent API base URL provided is malformedObsoleteVersionException- if the SDK version is incompatible with the Agent
-
getClient
public static AgentClient getClient(org.openqa.selenium.Capabilities capabilities, ReportSettings reportSettings) throws AgentConnectException, InvalidTokenException, java.net.MalformedURLException, ObsoleteVersionException
Creates (or searches for an existing) instance ofAgentClientusing provided capabilities.- Parameters:
capabilities-Capabilitiesto be used for creatingAgentClientor finding a cached onereportSettings-ReportSettingswith Project and Job names to report- Returns:
- An instance of an AgentClient class.
- Throws:
AgentConnectException- if Agent is not responding or responds with an errorInvalidTokenException- if the token provided is invalidjava.net.MalformedURLException- if the Agent API base URL provided is malformedObsoleteVersionException- if the SDK version is incompatible with the Agent
-
getClient
public static AgentClient getClient(java.lang.String token, org.openqa.selenium.Capabilities capabilities) throws AgentConnectException, InvalidTokenException, java.net.MalformedURLException, ObsoleteVersionException
Creates (or searches for an existing) instance ofAgentClientusing provided token and capabilities.- Parameters:
token- Development token, required to initialize a session with the Agent. If not provided, will attempt to get the value from TP_DEV_TOKEN environment variable.
It can be obtained from SDK page.capabilities-Capabilitiesto be used for creatingAgentClientor finding a cached one- Returns:
- An instance of an AgentClient class.
- Throws:
AgentConnectException- if Agent is not responding or responds with an errorInvalidTokenException- if the token provided is invalidjava.net.MalformedURLException- if the Agent API base URL provided is malformedObsoleteVersionException- if the SDK version is incompatible with the Agent
-
getClient
public static AgentClient getClient(java.lang.String token, org.openqa.selenium.Capabilities capabilities, ReportSettings reportSettings) throws AgentConnectException, InvalidTokenException, java.net.MalformedURLException, ObsoleteVersionException
Creates (or searches for an existing) instance ofAgentClientusing provided token and capabilities.- Parameters:
token- Development token, required to initialize a session with the Agent. If not provided, will attempt to get the value from TP_DEV_TOKEN environment variable.
It can be obtained from SDK page.capabilities-Capabilitiesto be used for creatingAgentClientor finding a cached onereportSettings-ReportSettingswith Project and Job names to report- Returns:
- An instance of an AgentClient class.
- Throws:
AgentConnectException- if Agent is not responding or responds with an errorInvalidTokenException- if the token provided is invalidjava.net.MalformedURLException- if the Agent API base URL provided is malformedObsoleteVersionException- if the SDK version is incompatible with the Agent
-
getClient
public static AgentClient getClient(java.net.URL remoteAddress, org.openqa.selenium.Capabilities capabilities, ReportSettings reportSettings) throws AgentConnectException, InvalidTokenException, java.net.MalformedURLException, ObsoleteVersionException
Creates (or searches for an existing) instance ofAgentClientusing provided remoteAddress and capabilities.- Parameters:
remoteAddress- Agent API base URL
If not provided, will attempt to get the value from TP_AGENT_URL environment variable.
If the environment variable is not set, default URL http://localhost:8585 is used.capabilities-Capabilitiesto be used for creatingAgentClientor finding a cached onereportSettings-ReportSettingswith Project and Job names to report- Returns:
- An instance of an AgentClient class.
- Throws:
AgentConnectException- if Agent is not responding or responds with an errorInvalidTokenException- if the token provided is invalidjava.net.MalformedURLException- if the Agent API base URL provided is malformedObsoleteVersionException- if the SDK version is incompatible with the Agent
-
getClient
public static AgentClient getClient(java.net.URL remoteAddress, org.openqa.selenium.Capabilities capabilities) throws AgentConnectException, InvalidTokenException, java.net.MalformedURLException, ObsoleteVersionException
Creates (or searches for an existing) instance ofAgentClientusing provided remoteAddress and capabilities.- Parameters:
remoteAddress- Agent API base URL
If not provided, will attempt to get the value from TP_AGENT_URL environment variable.
If the environment variable is not set, default URL http://localhost:8585 is used.capabilities-Capabilitiesto be used for creatingAgentClientor finding a cached one- Returns:
- An instance of an AgentClient class.
- Throws:
AgentConnectException- if Agent is not responding or responds with an errorInvalidTokenException- if the token provided is invalidjava.net.MalformedURLException- if the Agent API base URL provided is malformedObsoleteVersionException- if the SDK version is incompatible with the Agent
-
getClient
public static AgentClient getClient(java.net.URL remoteAddress, java.lang.String token, org.openqa.selenium.Capabilities capabilities, ReportSettings reportSettings, boolean disableReports) throws AgentConnectException, InvalidTokenException, java.net.MalformedURLException, ObsoleteVersionException
Creates (or searches for an existing) instance ofAgentClientusing provided remoteAddress, token and capabilities.- Parameters:
remoteAddress- Agent API base URL
If not provided, will attempt to get the value from TP_AGENT_URL environment variable.
If the environment variable is not set, default URL http://localhost:8585 is used.token- Development token, required to initialize a session with the Agent. If not provided, will attempt to get the value from TP_DEV_TOKEN environment variable.
It can be obtained from SDK page.capabilities-Capabilitiesto be used for creatingAgentClientor finding a cached onereportSettings-ReportSettingswith Project and Job names to reportdisableReports- True to disable automatic reporting of driver commands and tests, otherwise False.- Returns:
- An instance of an AgentClient class.
- Throws:
AgentConnectException- if Agent is not responding or responds with an errorInvalidTokenException- if the token provided is invalidjava.net.MalformedURLException- if the Agent API base URL provided is malformedObsoleteVersionException- if the SDK version is incompatible with the Agent
-
getVersion
public static java.lang.String getVersion(java.net.URL remoteAddress) throws AgentConnectException, java.net.MalformedURLExceptionRetrieves the version of the target Agent.- Parameters:
remoteAddress- Agent API base URL
If not provided, will attempt to get the value from TP_AGENT_URL environment variable.
If the environment variable is not set, default URL http://localhost:8585 is used.- Returns:
- Agent version.
- Throws:
AgentConnectException- if Agent is not responding or responds with an errorjava.net.MalformedURLException- if the Agent API base URL provided is malformed
-
getSession
public AgentSession getSession()
Getter forsessionfield.- Returns:
- value of
sessionfield
-
getVersion
public java.lang.String getVersion()
Getter forversionfield.- Returns:
- value of
versionfield
-
getProjectName
public java.lang.String getProjectName()
Getter forprojectName.- Returns:
- value of
projectNamefield
-
getReportSetting
public ReportSettings getReportSetting()
- Returns:
- value of
projectNameandjobNamefields wrapped inReportSettings
-
getSkipInferring
public boolean getSkipInferring()
Getter forfield. Used to check if the report settings were explicitly set.- Returns:
- true if the report settings were inferred, false otherwise.
-
isWarned
public static boolean isWarned()
Getter forfield.- Returns:
- true if warned once the client is null.
-
close
public void close()
Implementation ofClosableinterface. Closes all open resources such as the reporting queue without closing the TCP socket open with the agent.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
close
public void close(boolean exiting)
Close all open resources such as the reporting queue and the TCP socket open with the Agent if the process is exiting.- Parameters:
exiting- used to determine if the socket should be closed.
-
reportCommand
public boolean reportCommand(org.openqa.selenium.remote.Command command, java.lang.Object result, boolean passed, java.lang.String screenshot)Reports a driver command execution to the Agent.- Parameters:
command- Command executed by the driver.result- Command result formatted as Stringpassed- Boolean flag to indicate command successful execution or failure.screenshot- Screenshot as base64 string.- Returns:
- True if successfully reported, otherwise False.
-
reportStep
public boolean reportStep(StepReport report)
Reports a step to the Agent.- Parameters:
report- Report to submit.- Returns:
- True is successful, otherwise False.
-
reportTest
public boolean reportTest(TestReport report)
Reports a test to the Agent.- Parameters:
report- Report to submit.- Returns:
- True is successful, otherwise False.
-
executeProxy
public ActionExecutionResponse executeProxy(ActionProxy action, int timeout) throws org.openqa.selenium.WebDriverException
Executes a Action proxy from an Addon installed in an Account.- Parameters:
action- An instance of an action that extends theActionProxyclass.timeout- maximum amount of time allowed to wait for action execution to complete.- Returns:
- Execution result in form of
ActionExecutionResponse. - Throws:
org.openqa.selenium.WebDriverException- when execution fails.
-
updateJobName
public void updateJobName(java.lang.String updatedJobName)
Sent request to Agent API to update job name at runtime.- Parameters:
updatedJobName- to update original with.
-
-