I want to have a selenium grid using example provided in the repository:
# To execute this docker-compose yml file use `docker-compose -f docker-compose-v3-full-grid.yml up`
# Add the `-d` flag at the end for detached execution
# To stop the execution, hit Ctrl+C, and then `docker-compose -f docker-compose-v3-full-grid.yml down`
version: "3"
services:
selenium-event-bus:
image: selenium/event-bus:4.1.1-20211217
container_name: selenium-event-bus
ports:
- "4442:4442"
- "4443:4443"
- "5557:5557"
selenium-sessions:
image: selenium/sessions:4.1.1-20211217
container_name: selenium-sessions
ports:
- "5556:5556"
depends_on:
- selenium-event-bus
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
selenium-session-queue:
image: selenium/session-queue:4.1.1-20211217
container_name: selenium-session-queue
ports:
- "5559:5559"
depends_on:
- selenium-event-bus
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
selenium-distributor:
image: selenium/distributor:4.1.1-20211217
container_name: selenium-distributor
ports:
- "5553:5553"
depends_on:
- selenium-event-bus
- selenium-sessions
- selenium-session-queue
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_SESSIONS_MAP_HOST=selenium-sessions
- SE_SESSIONS_MAP_PORT=5556
- SE_SESSION_QUEUE_HOST=selenium-session-queue
- SE_SESSION_QUEUE_PORT=5559
selenium-router:
image: selenium/router:4.1.1-20211217
container_name: selenium-router
ports:
- "4444:4444"
depends_on:
- selenium-distributor
- selenium-sessions
- selenium-session-queue
environment:
- SE_DISTRIBUTOR_HOST=selenium-distributor
- SE_DISTRIBUTOR_PORT=5553
- SE_SESSIONS_MAP_HOST=selenium-sessions
- SE_SESSIONS_MAP_PORT=5556
- SE_SESSION_QUEUE_HOST=selenium-session-queue
- SE_SESSION_QUEUE_PORT=5559
chrome:
image: selenium/node-chrome:4.1.1-20211217
shm_size: 2gb
depends_on:
- selenium-event-bus
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
edge:
image: selenium/node-edge:4.1.1-20211217
shm_size: 2gb
depends_on:
- selenium-event-bus
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
firefox:
image: selenium/node-firefox:4.1.1-20211217
shm_size: 2gb
depends_on:
- selenium-event-bus
environment:
- SE_EVENT_BUS_HOST=selenium-event-bus
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
This opens the selenium grid with the view of the different nodes on http://127.0.0.1:4444/ui/index.html#/
:
Now I want to execute a test using a code I'm not sure where I copied it, but is not mine:
import os
import datetime
import time
import unittest
from selenium import webdriver
class Example(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities={
'browserName': 'firefox',
'javascriptEnabled': True
}
)
self.driver.get('https://google.es/')
def test_something(self):
dt_format = '%Y%m%d_%H%M%S'
cdt = datetime.datetime.fromtimestamp(time.time()).strftime(dt_format)
current_location = os.getcwd()
img_folder = current_location + '/images/'
if not os.path.exists(img_folder):
os.mkdir(img_folder)
picture = img_folder + cdt + '.png'
self.driver.save_screenshot(picture)
print('Waiting 160sec...')
time.sleep(160)
print('Done waiting...')
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main(verbosity=1)
The code works as expected as a screenshot of the google page is saved. But I'd like to check the browser in this waiting time, so I added to chrome the ports:
ports:
- 5900:5900
And I'm able to open a VNC connection with VNC Viewer with the OS of the node, but I'm not able to see the browser that is running my test.
The url from the selenium grid to each node is also not working
How can I access the specific browser of my test?
The test says
desired_capabilities={
'browserName': 'firefox',
'javascriptEnabled': True
}
while you mentioned you "added to chrome the ports", so I suspect you were looking at the wrong node.
I recommend you open all the VNC ports for all nodes, as described here.
I also recommend noVNC.