diff --git a/service.go b/service.go index 25ea516..33295da 100644 --- a/service.go +++ b/service.go @@ -18,6 +18,8 @@ import ( // ServiceOption configures a Service instance. type ServiceOption func(*Service) error +const InvalidPid = -1 + // Display specifies the value to which set the DISPLAY environment variable, // as well as the path to the Xauthority file containing credentials needed to // write to that X server. @@ -164,6 +166,15 @@ func (s Service) FrameBuffer() *FrameBuffer { return s.xvfb } +//PID returns the service pid +func (s Service) PID() int { + if s.cmd != nil { + return s.cmd.Process.Pid + } + + return InvalidPid +} + // NewSeleniumService starts a Selenium instance in the background. func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Service, error) { s, err := newService(exec.Command("java"), "/wd/hub", port, opts...)