I am working on trying to use selenium as a sidecar container for an application. In the application code I have tried the following:
URL remoteUrl = new URL("http://localhost:4444/wd/hub");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage");
log.info("starting web driver");
WebDriver driver = new RemoteWebDriver(remoteUrl, options);
I have also tried
URL remoteUrl = new URL("http://remote-chrome-webdriver.default.svc.cluster.local:4444/wd/hub");
and
URL remoteUrl = new URL("http://remote-chrome-webdriver:4444/wd/hub");
And all of these options have yielded a ConnectException.
My yaml defines the selenium container like this:
initContainers:
- name: wait-for-chrome
image: busybox:latest
imagePullPolicy: IfNotPresent
command: ['sh', '-c', 'until curl -f http://remote-chrome-webdriver:4444/wd/hub/status; do echo "Waiting fro remote-chrome-webdriver..."; sleep 5; done;']
resources:
{{- toYaml .Values.resources | nindent 12 }}
- name: remote-chrome-webdriver
image: xxxxxxxxxx/selenium/standalone-chrome:4.23.1
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 4444
protocol: TCP
restartPolicy: Always
env:
- name: "xxxxx_APPLICATION_CREDENTIALS"
value: {{ .Values.env.xxxxxxxxxxx}}
envFrom:
- secretRef:
name: xxxxxx
volumeMounts:
- name: xxxxxx
readOnly: true
mountPath: "/etc/xxxxx"
resources:
{{- toYaml .Values.resources | nindent 12}}
Where I have redacted some sensitive information.
What is the proper syntax to use in java code to allow the application to connect to the selenium sidecar?
The correct syntax in the code to reach the selenium standalone running in the kubernetes cluster was
http://remote-chrome-webdriver.default.svc:80/wd/hub
Also we had to create a Kubernetes service to expose this selenium to other workloads in the cluster
apiVersion: v1
kind: Service
metadata:
name: remote-chrome-webdriver
labels:
app: remote-chrome-webdriver
spec:
selector:
app: remote-chrome-webdriver
ports:
- protocol: TCP
port: 80
targetPort: 4444
type: LoadBalancer