selenium-Setting up your own


title: “Setting up your own”
weight: 2

Different Modes of Grid setup in Selenium 4:

  • Standalone
  • Hub and Node
  • Distributed
  • Docker

Standalone Mode:

The new Selenium Server Jar contains everything you’d need to run a grid. It is also the easiest mode to spin up a Selenium Grid. By default the server will be listening on http://localhost:4444, and that’s the URL you should point your RemoteWebDriver tests. The server will detect the available drivers that it can use from the System PATH

java -jar selenium-server-4.0.0-alpha-6.jar standalone

Hub and Node Mode:

Start the Hub:

java -jar selenium-server-4.0.0-alpha-6.jar hub

Register a Node:

java -jar selenium-server-4.0.0-alpha-6.jar node --detect-drivers

Query Selenium Grid:

In Selenium 4, we’ve also added GraphQL, a new way to query the necessary data easily and get exactly the same.

curl -X POST -H "Content-Type: application/json" --data '{ "query": "{grid{uri}}" }' -s http://localhost:4444/graphql | jq .



Distributed Mode:

  • Step 1: Firstly, start the Event Bus, it serves as a communication path to other Grid components in subsequent steps.

    java -jar selenium-server-4.0.0-alpha-6.jar  event-bus
    
  • Step 2: Start the session map, which is responsible for mapping session IDs to the node the session is running on:

        java -jar selenium-server-4.0.0-alpha-6.jar sessions
    
  • Step 3: Start the Distributor. All the nodes are attached as part of Distributor process. It is responsible for assigning a node, when a create session request in invoked.

        java -jar selenium-server-4.0.0-alpha-6.jar distributor --sessions http://localhost:5556 --bind-bus false
    
  • Step 4: Next step is to start the Router, an address that you’d expose to web

        java -jar selenium-server-4.0.0-alpha-6.jar router --sessions http://localhost:5556 --distributor http://localhost:5553
    
  • Step 5: Finally, add a Node

        java -jar selenium-server-4.0.0-alpha-6.jar node --detect-drivers
    

Start Standalone Grid via Docker Images

You can just start a node by the following command:

    java -jar selenium-server-4.0.0-alpha-1.jar node -D selenium/standalone-firefox:latest '{"browserName": "firefox"}'

You can start the Selenium server and delegate it to docker for creating new instances:

     java -jar selenium-server-4.0.0-alpha-6.jar standalone -D selenium/standalone-firefox:latest '{"browserName": "firefox"}' --detect-drivers false

官方链接为:https://www.selenium.dev/documentation/en/grid/grid_4/setting_up_your_own_grid