Skip to content

Commit 2f7bc88

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

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

service.go

+32
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,38 @@ 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+
fmt.Println("Selenium Args:", s.cmd.Args)
222+
if err := s.start(port); err != nil {
223+
return nil, err
224+
}
225+
226+
return s, nil
227+
}
228+
197229
// NewChromeDriverService starts a ChromeDriver instance in the background.
198230
func NewChromeDriverService(path string, port int, opts ...ServiceOption) (*Service, error) {
199231
cmd := exec.Command(path, "--port="+strconv.Itoa(port), "--url-base=wd/hub", "--verbose")

0 commit comments

Comments
 (0)