Instantiate ZAP as a daemon prgramatically with Java

296 views
Skip to first unread message

Albert

unread,
May 9, 2016, 11:27:35 AM5/9/16
to OWASP ZAP User Group
Hi,

I am running ZAP for automated testing and I been so far successful to run my set up when I have an instance of ZAP running.
I am however now working on a test fixture that would start zap before the tests are run and tear it down at the end.

ZAP should run as a daemon in that case.

For some reason ZAP does not seem to start. Even when debugging appears as instantiated.

This is is the way I am calling it:


  clientApi = new ClientApi(host, port);

When debuging the code, an instance of clientAPI is created, listing localhost:8502 however I can't see any listening ports.

If i run the JUnit test that use ZAP they will fail with connection exception.

However if I start ZAP on that machine using the ./zap.sh and then run the JUnit tests that use zap will sucessfuly pass using the runing instance.

How can I instantiate ZAP in java programatically in daemon mode so I can use it as a fixture in Junit test?


thc...@gmail.com

unread,
May 9, 2016, 11:48:04 AM5/9/16
to zaprox...@googlegroups.com
Hi.

You should be able to achieve that with the class ProcessBuilder. [1]
For example:
ProcessBuilder pb = new ProcessBuilder("/path/to/zap.sh", "-daemon");
// Set up redirection of output...
pb.start();
// Wait for ZAP to start... for example: [2]
// Run tests...
// Shutdown ZAP with ClientApi.


[1] http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html
[2]
https://github.com/zaproxy/zaproxy-test/blob/270bc794588d8a62775137e9399001b067245f62/src-build/org/zaproxy/ant/zap/taskdefs/StopZapTimeout.java#L82

Best regards.
> --
> You received this message because you are subscribed to the Google
> Groups "OWASP ZAP User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to zaproxy-user...@googlegroups.com
> <mailto:zaproxy-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages