简体   繁体   English

强制在网格中不使用Selenium RC

[英]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. 我要提供一个Selenium网格,并要强制我们的开发人员不再使用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 从我了解到的RC已被弃用的方面来看,在客户端上,您需要导入旧版代码: https : //seleniumhq.github.io/selenium/docs/api/java/deprecated-list.html

But what if a developer uses the old RC calls ? 但是,如果开发人员使用旧的RC调用怎么办? I found no way to disable support for RC on the hub. 我发现没有办法在集线器上禁用对RC的支持。 I made my attempts on Selenium 3.4.0 我尝试了硒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 在测试项目中,创建一个新包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) 现在,将类DefaultRemoteProxy复制到您创建的该程序包中(这将导致Java现在开始利用您的DefaultRemoteProxy版本而不是Selenium代码库中可用的版本)
  • Now within the copied version of DefaultRemoteProxy alter its constructor to as shown below. 现在,在复制的DefaultRemoteProxy版本中,将其构造函数更改为如下所示。
  • 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) 从测试项目中创建一个uber jar,以便可以将其用作Selenium独立jar(或)
    • 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) 从您的项目中创建一个jar,将其放入Selenium独立jar的CLASSPATH中,然后使用java -cp (随意选择适合您的选项)
  • 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. 此后,您应该能够阻止人们将其节点注册到协议为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. 不利的一面是,您需要确保不断监控Selenium代码库中org.openqa.grid.selenium.proxy.DefaultRemoteProxy的内容,并不断更新本地版本,否则您可能会遇到这种情况不同步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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