Skip to content

Commit 495ccb7

Browse files
authored
Merge pull request #425 from rueyaa332266/update_selenium_4
Update selenium example to selenium 4.0
2 parents 802539a + 25f65c7 commit 495ccb7

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

staging/selenium/README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,10 @@ Let's run a quick Selenium job to validate our setup.
9696

9797
#### Setup Python Environment
9898

99-
First, we need to start a python container that we can attach to.
99+
First, we need to start a python container that we can attach to, then get inside this container.
100100

101101
```console
102-
kubectl run selenium-python --image=google/python-hello
103-
```
104-
105-
Next, we need to get inside this container.
106-
107-
```console
108-
export PODNAME=`kubectl get pods --selector="run=selenium-python" --output=template --template="{{with index .items 0}}{{.metadata.name}}{{end}}"`
109-
kubectl exec --stdin=true --tty=true $PODNAME bash
102+
kubectl run selenium-python --tty -i --image=python:slim bash
110103
```
111104

112105
Once inside, we need to install the Selenium library
@@ -127,14 +120,17 @@ And paste in the contents of selenium-test.py.
127120

128121
```python
129122
from selenium import webdriver
130-
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
131123

132124
def check_browser(browser):
125+
if browser == "CHROME":
126+
options = webdriver.ChromeOptions()
127+
elif browser == "FIREFOX":
128+
options = webdriver.FirefoxOptions()
133129
driver = webdriver.Remote(
134130
command_executor='http://selenium-hub:4444/wd/hub',
135-
desired_capabilities=getattr(DesiredCapabilities, browser)
131+
options=options
136132
)
137-
driver.get("http://google.com")
133+
driver.get("http://www.google.com")
138134
assert "google" in driver.page_source
139135
driver.quit()
140136
print("Browser %s checks out!" % browser)
@@ -190,7 +186,6 @@ kubectl delete deployment selenium-node-chrome
190186
kubectl delete deployment selenium-node-firefox
191187
kubectl delete deployment selenium-python
192188
kubectl delete svc selenium-hub
193-
kubectl delete svc selenium-hub-external
194189
```
195190

196191

staging/selenium/selenium-hub-deployment.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ spec:
1616
spec:
1717
containers:
1818
- name: selenium-hub
19-
image: selenium/hub:3.141
19+
image: selenium/hub:4.0
2020
ports:
2121
- containerPort: 4444
22+
- containerPort: 4443
23+
- containerPort: 4442
2224
resources:
2325
limits:
2426
memory: "1000Mi"

staging/selenium/selenium-hub-svc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ spec:
99
- port: 4444
1010
targetPort: 4444
1111
name: port0
12+
- port: 4443
13+
targetPort: 4443
14+
name: port1
15+
- port: 4442
16+
targetPort: 4442
17+
name: port2
1218
selector:
1319
app: selenium-hub
1420
type: NodePort

staging/selenium/selenium-node-chrome-deployment.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ spec:
2020
medium: Memory
2121
containers:
2222
- name: selenium-node-chrome
23-
image: selenium/node-chrome-debug:3.141
23+
image: selenium/node-chrome:4.0
2424
ports:
2525
- containerPort: 5555
2626
volumeMounts:
2727
- mountPath: /dev/shm
2828
name: dshm
2929
env:
30-
- name: HUB_HOST
30+
- name: SE_EVENT_BUS_HOST
3131
value: "selenium-hub"
32-
- name: HUB_PORT
33-
value: "4444"
32+
- name: SE_EVENT_BUS_SUBSCRIBE_PORT
33+
value: "4443"
34+
- name: SE_EVENT_BUS_PUBLISH_PORT
35+
value: "4442"
3436
resources:
3537
limits:
3638
memory: "1000Mi"

staging/selenium/selenium-node-firefox-deployment.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ spec:
2020
medium: Memory
2121
containers:
2222
- name: selenium-node-firefox
23-
image: selenium/node-firefox-debug:3.141
23+
image: selenium/node-firefox:4.0
2424
ports:
25-
- containerPort: 5900
25+
- containerPort: 5555
2626
volumeMounts:
2727
- mountPath: /dev/shm
2828
name: dshm
2929
env:
30-
- name: HUB_HOST
30+
- name: SE_EVENT_BUS_HOST
3131
value: "selenium-hub"
32-
- name: HUB_PORT
33-
value: "4444"
32+
- name: SE_EVENT_BUS_SUBSCRIBE_PORT
33+
value: "4443"
34+
- name: SE_EVENT_BUS_PUBLISH_PORT
35+
value: "4442"
3436
resources:
3537
limits:
3638
memory: "1000Mi"

staging/selenium/selenium-test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
# limitations under the License.
1616

1717
from selenium import webdriver
18-
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
1918

2019
def check_browser(browser):
20+
if browser == "CHROME":
21+
options = webdriver.ChromeOptions()
22+
elif browser == "FIREFOX":
23+
options = webdriver.FirefoxOptions()
2124
driver = webdriver.Remote(
2225
command_executor='http://selenium-hub:4444/wd/hub',
23-
desired_capabilities=getattr(DesiredCapabilities, browser)
26+
options=options
2427
)
25-
driver.get("http://google.com")
28+
driver.get("http://www.google.com")
2629
assert "google" in driver.page_source
2730
driver.quit()
2831
print("Browser %s checks out!" % browser)

0 commit comments

Comments
 (0)