Skip to content

Commit 3bc7208

Browse files
committed
Add NewSeleniumServiceV4 to support cli args for selenium version 4
1 parent e9100b7 commit 3bc7208

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

service.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,37 @@ func NewSeleniumService(jarPath string, port int, opts ...ServiceOption) (*Servi
194194
return s, nil
195195
}
196196

197+
func NewSeleniumServiceV4(jarPath string, port int, opts ...ServiceOption) (*Service, error) {
198+
s, err := newService(exec.Command("java"), "/wd/hub", port, opts...)
199+
if err != nil {
200+
return nil, err
201+
}
202+
s.cmd.Args = append(s.cmd.Args, "-jar", jarPath)
203+
if s.javaPath != "" {
204+
s.cmd.Path = s.javaPath
205+
}
206+
207+
var classpath []string
208+
if s.htmlUnitPath != "" {
209+
classpath = append(classpath, s.htmlUnitPath)
210+
}
211+
if s.geckoDriverPath != "" {
212+
classpath = append(classpath, s.geckoDriverPath)
213+
}
214+
if s.chromeDriverPath != "" {
215+
classpath = append(classpath, s.chromeDriverPath)
216+
}
217+
if len(classpath) > 0 {
218+
s.cmd.Args = append(s.cmd.Args, "--ext", strings.Join(classpath, ":"))
219+
}
220+
s.cmd.Args = append(s.cmd.Args, "standalone", "--port", strconv.Itoa(port))
221+
if err := s.start(port); err != nil {
222+
return nil, err
223+
}
224+
225+
return s, nil
226+
}
227+
197228
// NewChromeDriverService starts a ChromeDriver instance in the background.
198229
func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error) {
199230
cmd := exec.Command(path, "--port="+strconv.Itoa(port), "--url-base=wd/hub", "--verbose")

0 commit comments

Comments
 (0)