TestProject Forum
Powered by leading experts in the test automation community

Programmatically cmd start TestProject Agent

I programmatically start-up TestProject Agent on my local machine before test execution with the code below and it starts it up. How come this throws an exception failed to communicate with the agent. I’ve even extended time wait to a whole minute thinking maybe it needs time to connect. When I manually start up the Agent and kick off test as soon as it starts up after about 15-20 seconds it “communicates” fine.
Here is the exception:
io.testproject.sdk.internal.exceptions.AgentConnectException: Failed communicating with the Agent at http://localhost:8585

Here is the code:
ProcessBuilder builder = new ProcessBuilder(“cmd.exe”, “/c”, “C:/Program Files/TestProject Agent/TestProjectAgent.exe”);
try {
Process process = process = builder.start();
process.waitFor(25, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}

Thanks

Also, I forgot to mention, I exported the recorded TestProject code to run locally on my machine and not in TestProject.

Thanks,

Hello @shltrmail.

Try starting the agent with:

    Runtime.getRuntime().exec("cmd /c start cmd.exe /C\""+"C:\\Program Files\\TestProject Agent\\TestProjectAgent.exe"+"\"");

The following code snippet has worked in my case:

import io.testproject.sdk.drivers.web.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Tests {
public static void main(String[] args) throws Exception {
    Runtime.getRuntime().exec("cmd /c start cmd.exe /C\""+"C:\\Program Files\\TestProject Agent\\TestProjectAgent.exe"+"\"");
    Thread.sleep(25000);

    ChromeDriver driver = new ChromeDriver("TOKEN", new ChromeOptions());
    driver.navigate().to("https://google.com");
    Thread.sleep(5000);
    driver.quit();
    System.out.println("Test Completed Successfully");
    }
}

That works! I just add a piece of code to close out the command console that pops up which is no biggie.

Thank you very much!
Melinda

Sure, glad I could help.