Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium grid missing configuration for custom capabilities mutators #7478

Closed
JonathanHallKJR opened this issue Aug 8, 2019 · 5 comments
Closed
Labels

Comments

@JonathanHallKJR
Copy link

馃殌 Feature Proposal

Grid already allows configuration of a Custom Matcher in the hub's config json but if that custom matcher wants to make use of extension capabilities as part of the processing (allowed by w3c specification) but there is no configuration also allow a Capabilities Mutator.

Motivation

Selenium Grid appears to passes intermediary extension capabilities through to the nodes which is a violation of the w3c specification for New Session

If the remote end is an intermediary node, it may use the result of the capabilities processing algorithm to route the new session request to the appropriate endpoint node.
An intermediary node is free to define extension capabilities to assist in this process, however, these specific capabilities must not be forwarded to the endpoint node.

Suggested fix

Selenium Grid does appears have mechanism to change capabilities with Capabilities Mutator, but it isn't configurable like the Capabilities Matcher.

I think it would be possible to use the existing CapabilitiesMutator logic:

  • org.openqa.selenium.remote.server.NewSessionPipeline#addCapabilitiesMutator
  • org.openqa.selenium.remote.server.NewSessionPipeline#createNewSession

Suggest adding new config option for customMutator like existing org.openqa.grid.internal.utils.configuration.GridHubConfiguration#capabilityMatcher

Then when creating the NewSessionPipeline org.openqa.selenium.remote.server.SeleniumServer#createPipeline if the configuration is instance of GridHubConfiguration then register the customerMutator

@diemol
Copy link
Member

diemol commented Aug 8, 2019

@JonathanHallKJR can you provide an example with code of what you mean?

@JonathanHallKJR
Copy link
Author

@diemol My suggested fix was based on browsing the code so I haven't attempted to implement it and I may have missed something tracing the program flow.

Essentially the proposal is to add to config for the hub a capabilityMutator that can work in conjunction with the capabilityMatcher to remove capabilities before they're forwarded to the endpoint node.

This is required by the w3c web driver specification if the intermediary node (grid hub)'s capabilityMatcher relies on custom extension capabilities to route the request.

The mock up below hasn't been compiled but hopefully conveys enough of the intent.

Example

Start the hub java -jar selenium-server-standalone-3.141.59.jar -role hub -hubConfig hubConfig.json with a capabilityMutator configured.

{
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets": [],
  "withoutServlets": [],
  "custom": {},
  "capabilityMatcher": "hudson.plugins.selenium.JenkinsCapabilityMatcher",
  "capabilityMutator": "package.for.my.example.MyCapabilityFilter", // added 
  "throwOnCapabilityNotPresent": true,
  "cleanUpCycle": 5000,
  "role": "hub",
  "debug": false,
  "browserTimeout": 0,
  "timeout": 1800
}

鈩癸笍 Investigating an issue with JenkinsCapabilityMatcher forwarding the custom jenkins:label extension capability to IEDriverServer prompted this feature request

The mutator class would then be given access to change the capabilities just before their forwarded to hubs during the NewSessionPipeline#createNewSession

package package.for.my.example;

import java.util.*;
import java.util.function.Function;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;

public class MyCapabilityFilter implements Function<Capabilities, Capabilities> {

    // todo: Could also add constructor like org.openqa.grid.selenium.node.ChromeMutator that would make this 
	// 		 configurable through the hubConfig.json
	//       for the example the filter is hard coded.
    static final String EXTENSION_CAPABILITY_PREFIX = "jenkins:";

    @Override
    public Capabilities apply(Capabilities capabilities) {
        Map<String, Object> toReturn = new HashMap<>(capabilities.asMap());
        List<String> toRemove = new LinkedList<>();

        // find all capabilities starting with filtered prefix.
        for (String k : toReturn.keySet()) {
            if (k.startsWith(EXTENSION_CAPABILITY_PREFIX)) {
                toRemove.add(k);
            }
        }

        // Remove all matches
        for (String r : toRemove) {
            toReturn.remove(r);
        }

        return new ImmutableCapabilities(toReturn);
    }

}

@diemol
Copy link
Member

diemol commented Sep 23, 2021

Revisiting this since the code for Grid 3 is not in trunk anymore and we are soon releasing formally the Grid.

A SlotMatcher is the one in charge of matching requests with Slots and it is possible to configure it via https://www.selenium.dev/documentation/grid/configuring_components/cli_options/#distributor (--slot-matcher).

There is a SessionCapabilitiesMutator now that enhances capabilities when they drivers are customised, for example: https://www.selenium.dev/documentation/grid/configuring_components/toml_options/#configuring-and-customising-drivers

Not sure if all this would already cover this use case. @JonathanHallKJR, what do you think?

@diemol
Copy link
Member

diemol commented Nov 28, 2021

Closing as we did not get more feedback.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants