SeleniumGrid 4 – Jaeger (Enable Tracing)

Selenium Grid Enable Jaeger Steps (Windows)

1. Download ElasticSearch and Jaeger

1) The 7.x version I use (Elasticsearch 7.16.3 | Elastic), start up

2) Download Jaeger (Windows Service Deployment – Jaeger documentation)

3) Start the following 3 cmd commands

jaeger-agent.exe –reporter.grpc.host-port=localhost:14250

set SPAN_STORAGE_TYPE=elasticsearch

jaeger-collector.exe –es.server-urls=http://localhost:9200

set SPAN_STORAGE_TYPE=elasticsearch

jaeger-query.exe –es.server-urls=http://localhost:9200

4) Open Jaeger UI [Port: 16686; URL: http://localhost:16686/search]

2. Download Selenium-Server-4.9.0, start Hub and Grid

1) Download address (Release Selenium 4.9.0 SeleniumHQ/selenium GitHub)

2) Start Hub

java -Dotel.traces.exporter=jaeger -Dotel.exporter.jaeger.endpoint=http://localhost:14250 -Dotel.resource.attributes=service.name=selenium-grid-hub -jar selenium-server-4.9.0 .jar –ext tracing-lib hub –healthcheck-interval 600

Notes: –ext tracing-lib Here tracing-lib is a folder, which is all the lib files of the following two dependencies

Rely on 2 dependencies: io.opentelemetry:opentelemetry-exporter-jaeger:1.22.0 io.grpc:grpc-netty:1.45.0

3) Start Node

java -Dotel.traces.exporter=jaeger -Dotel.exporter.jaeger.endpoint=http://localhost:14250 -Dotel.resource.attributes=service.name=selenium-grid-node-1 -jar selenium-server-4.9 .0.jar –ext tracing-lib node –config .\config.toml

The config.toml file is as follows

[node]
detect-drivers = false
port = 5555
grid-url = “http://192.168.1.4:4444”

[[node.driver-configuration]]
display-name = “Chrome”
stereotype = “{“browserName”: “chrome”, “browserVersion”: “112”, “platformName”: “Windows”, “goog:chromeOptions”: {\ “binary”: “C:\Program Files\Google\Chrome\Application\chrome.exe”}}”
webdriver-executable = “C:\tools\chromedriver.exe”

[events]
publish = “tcp://192.168.1.4:4442”
subscribe = “tcp://192.168.1.4:4443”

4) Selenium Grid starts as follows

3. Execute Selenium Test

Simple Demo: Open Baidu search

package org.selenium.test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.net.URL;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class BaiduSearchPage {
    WebDriver driver;

    @FindBy(id = "kw")
    WebElement searchInput;

    @FindBy(id = "su")
    @CacheLookup
    WebElement searchButton;

    public BaiduSearchPage(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public void inputText(String search) {
        searchInput. sendKeys(search);
    }

    public void clickButton() {
        searchButton. click();
    }

    public static void main(String[] args) throws Exception {
        WebDriver driver = null;
        try {
            BaiduSearchPage searchPage;
            driver = new RemoteWebDriver(new URL("http://192.168.1.4:4444"), new ChromeOptions());
            driver.manage().window().maximize();
            driver.get("http://www.baidu.com");
            searchPage = new BaiduSearchPage(driver);
            searchPage. inputText("selenium");
            searchPage. clickButton();
            TimeUnit. SECONDS. sleep(5);
        } finally {
            if (Objects. nonNull(driver)) {
                driver. quit();
            }
        }


    }

}

4. View the Trace of Selenium on Jaeger