简体   繁体   中英

Enforce not using Selenium RC in a grid

I am to provide a Selenium grid and would like to enforce that our developers no longer use the RC API. From what I learnt RC is deprecated and on the client side you need to import the legacy code: https://seleniumhq.github.io/selenium/docs/api/java/deprecated-list.html

But what if a developer uses the old RC calls ? I found no way to disable support for RC on the hub. I made my attempts on Selenium 3.4.0

There is no direct way of doing this. But here's a hack of how this can be done.

  • In your test project, create a new package org.openqa.grid.selenium.proxy
  • Now copy the class DefaultRemoteProxy into this package that you created (This would cause Java to now start utilising your version of DefaultRemoteProxy instead of what is available in the Selenium codebase)
  • Now within the copied version of DefaultRemoteProxy alter its constructor to as shown below.
  • Use one of the below mechanism to create an artifact which would be used to start your Hub.
    • Create an uber jar out of your test project so that it can be used as your Selenium standalone jar (or)
    • Create a jar out of your project, drop it in the CLASSPATH of Selenium standalone jar and then use java -cp (Feel free to choose whichever option works for you)
  • Use the artifact created above, start off the hub.

After this, you should be able to prevent people from registering their nodes to your hub wherein the protocol is Selenium RC.

public DefaultRemoteProxy(RegistrationRequest request, Registry registry) {
    super(request, registry);
    for (TestSlot slot : getTestSlots()) {
        if (slot.getProtocol() == SeleniumProtocol.Selenium) {
            throw new IllegalStateException("Selenium RC Protocol is NOT supported.");
        }
    }

    pollingInterval = config.nodePolling != null ? config.nodePolling : DEFAULT_POLLING_INTERVAL;
    unregisterDelay = config.unregisterIfStillDownAfter != null ? config.unregisterIfStillDownAfter : DEFAULT_UNREGISTER_DELAY;
    downPollingLimit = config.downPollingLimit != null ? config.downPollingLimit : DEFAULT_DOWN_POLLING_LIMIT;
}

This should help you achieve what you are after.

The flip side of this is that you would need to make sure you are constantly monitoring the contents of org.openqa.grid.selenium.proxy.DefaultRemoteProxy in the Selenium codebase and keep updating your local version else you may run into a situation wherein things go out of sync.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM