Webdriver - Selenium Grid Configuration

 Webdriver - Selenium Grid Configuration

作者: Max.Bai

时间: 2014/06


1. Start Selenium Hub

java -jar selenium-server-standalone-2.<last_version>.jar-role hub

Can be check the hub status use http://127.0.0.1:4444/grid/console

2. Start Selenium Node

Start with Node contains Selenium RC and Webdriver

java -jar selenium-server-standalone-2.29.0.jar -role node -hub http://localhost:4444/grid/register

Start with Webdriver contains Webdriver

java -jar selenium-server-standalone-2.29.0.jar -role webdriver -hub http://localhost:4444/grid/register


Start with Selenium contains Selenium RC

java -jar selenium-server-standalone-2.29.0.jar -role selenium -hub http://localhost:4444/grid/register


3. Start Hub and Node with Json config

Start Hub with json config file

title HubWebDriver
java -jar selenium-server-standalone-2.29.0.jar
-role hub
-hubConfig hubconfig.json
pause

hubconfig.json

{
   "host": null,
   "port": 4444,
   "newSessionWaitTimeout": 300000,
   "servlets" : [],
   "prioritizer": null,
   "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
   "throwOnCapabilityNotPresent": true,
   "nodePolling": 5000,
   "cleanUpCycle": 5000,
   "nodeTimeout": 360000,
   "timeout": 480000,
   "browserTimeout": 0,
   "maxSession": 5
}

Start Node with json file

title NodeWebDriver
java -jar selenium-server-standalone-2.<last_version>.jar
-Dwebdriver.ie.driver="ABSOLUTE_PATH\IEDriverServer.exe"
-Dwebdriver.chrome.driver="ABSOLUTE_PATH\chromedriver.exe"
-Dwebdriver.safari.bin="ABSOLUTE_PATH\Safari.exe"
-Dwebdriver.opera.bin="ABSOLUTE_PATH\opera.exe"
-Dwebdriver.chrome.bin="ABSOLUTE_PATH\chrome.exe"
-Dwebdriver.ie.bin="ABSOLUTE_PATH\iexplore.exe"
-role node
-nodeConfig nodeconfig.json
pause

nodeconfig.json

{
   "capabilities":
   [
		{
			"seleniumProtocol": "Selenium",
			"platform": "MAC",
			"browserName": "*iexplore",
			"maxInstances": "1"
		},
		{
			"seleniumProtocol": "Selenium",
			"platform": "MAC",
			"browserName": "*firefox",
			"maxInstances": "5",
			"firefox_binary":"c:\sss\firefox.exe"
		},
	  {
		 "seleniumProtocol":"Selenium",
		 "browserName":"*firefox",
		 "maxInstances":1
	  },
	  {
		 "seleniumProtocol":"WebDriver",
		 "browserName":"firefox",
		 "maxInstances":1,
		 "firefox_binary":"c:\sss\firefox.exe"
	  },
	  {
		 "seleniumProtocol":"WebDriver",
		 "browserName":"internet explorer",
		 "maxInstances":1
	  },
	  {
		 "seleniumProtocol":"WebDriver",
		 "browserName":"chrome",
		 "maxInstances":1
		 "chrome_binary":"c:\sss\chrome.exe"
	  },
	  {
		 "seleniumProtocol":"WebDriver",
		 "browserName":"opera",
		 "maxInstances":1
	  },
	  {
		 "seleniumProtocol":"WebDriver",
		 "browserName":"safari",
		 "maxInstances":1
	  }
   ],
   "configuration":
   {
      "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
      "maxSession": 5,
      "port": 5531,
      "hubHost": "IP Address of the Hub",
      "register": true,
      "registerCycle": 5000,
      "hubPort": 4444
   }
}


How to view hub status?

http://192.168.9.106:5531/wd/hub/static/resource/hub.html


How to view node status?

http://192.168.9.63:4444/grid/console


Other settings for -browser

  • -browser < params > If -browser is not set, a node will start with 5 firefox, 1 chrome, and 1 internet explorer instance (assuming it’s on a windows box). This parameter can be set multiple times on the same line to define multiple types of browsers.

Parameters allowed for -browser: browserName={android, chrome, firefox, htmlunit, internet explorer, iphone, opera} version={browser version} firefox_binary={path to executable binary} chrome_binary={path to executable binary} maxInstances={maximum number of browsers of this type} platform={WINDOWS, LINUX, MAC}



default config json file:

{
  "capabilities":
      [
        {
          "browserName": "*firefox",
          "maxInstances": 5,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "*googlechrome",
          "maxInstances": 5,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "*iexplore",
          "maxInstances": 1,
          "seleniumProtocol": "Selenium"
        },
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5555,
    "host": ip,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": ip
  }
}

{
  "host": null,
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "prioritizer": null,
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "throwOnCapabilityNotPresent": true,
  "nodePolling": 5000,

  "cleanUpCycle": 5000,
  "timeout": 300000,
  "browserTimeout": 0,
  "maxSession": 5,
  "jettyMaxThreads":-1
}


Grid parameter:

role = <hub|node> (default is no grid, just run an RC/webdriver server). When launching a node, the parameters will be forwarded to the server on the node, so you can use something like -role node -trustAllSSLCertificates. In that case, the SeleniumServer will be launch with the trustallSSLCertificates option.

# hub config
host = (hub & node) <IP | hostname> : usually not needed and determined automatically. For exotic network configuration, network with VPN, specifying the host might be necessary.
port = (hub & node) <xxxx> : the port the remote/hub will listen on. Default to 4444.


throwOnCapabilityNotPresent = (hub) <true | false> default to true. If true, the hub will reject test requests right away if no proxy is currently registered that can host that capability.Set it to false to have the request queued until a node supporting the capability is added to the grid.
newSessionWaitTimeout = (hub) <XXXX>. Default to no timeout ( -1 ) the time in ms after which a new test waiting for a node to become available will time out.When that happens, the test will throw an exception before starting a browser.

capabilityMatcher = (hub) a class implementing the CapabilityMatcher interface. Defaults to org.openqa.grid.internal.utils.DefaultCapabilityMatcher. Specify the logic the hub will follow to define if a request can be assigned to a node.Change this class if you want to have the matching process use regular expression instead of exact match for the version of the browser for instance. All the nodes of a grid instance will use the same matcher, defined by the registry.
prioritizer = (hub) a class implementing the Prioritizer interface. Default to null ( no priority = FIFO ).Specify a custom prioritizer if you need the grid to process the tests from the CI, or the IE tests first for instance.
servlets = (hub & node) <com.mycompany.MyServlet,com.mycompany.MyServlet2> to register a new servlet on the hub/node. The servlet will accessible under the path /grid/admin/MyServlet /grid/admin/MyServlet2


grid1Yml = (hub) a YML file following grid1 format.
hubConfig = (hub) a JSON file following grid2 format that defines the hub properties.
nodeConfig = (node) a JSON file following grid2 format that defines the node properties.


# config that will be inherited by the proxy and used for the node management.
cleanupCycle = (node) <XXXX> in ms. How often a proxy will check for timed out thread.
timeout = (node) <XXXX> the timeout in seconds before the hub automatically ends a test that hasn't had any activity in the last X seconds. The browser will be released for another test to use. This typically takes care of the client crashes.
browserTimeout= (hub/node) The timeout in seconds a browser can hang
hub = (node) <http://localhost:4444/grid/register> : the url that will be used to post the registration request. This option takes precedence over -hubHost and -hubPort options.
hubHost = (node) <IP | hostname> : the host address of a hub the registration request should be sent to. Default to localhost. Option -hub takes precedence over this option.
hubPort = (node) <xxxx> : the port listened by a hub the registration request should be sent to. Default to 4444. Option -hub takes precedence over this option.
proxy = (node) the class that will be used to represent the node. By default org.openqa.grid.selenium.proxy.DefaultRemoteProxy.
maxSession = (node) max number of tests that can run at the same time on the node, independently of the browser used.
registerCycle = (node) how often in ms the node will try to register itself again.Allow to restart the hub without having to restart the nodes.
nodePolling = (node) in ms. Interval between alive checks of node how often the hub checks if the node is still alive.
unregisterIfStillDownAfter = (node) in ms. If the node remains down for more than unregisterIfStillDownAfter millisec, it will disappear from the hub.Default is 1min.
downPollingLimit = (node) node is marked as down after downPollingLimit alive checks.
nodeStatusCheckTimeout = (node) in ms. Connection and socket timeout which is used for node alive check.


Relate page:

https://code.google.com/p/selenium/wiki/Grid2

https://code.google.com/p/selenium/source/browse/java/server/src/org/openqa/grid/common/defaults/DefaultNode.json

https://code.google.com/p/selenium/source/browse/java/server/src/org/openqa/grid/common/defaults/DefaultHub.json




<think>好的,我现在需要解决用户遇到的npm依赖冲突问题。用户运行npm install时遇到了ERESOLVE错误,具体是因为项目中同时安装了selenium-webdriver@4.30.0和karma-selenium-webdriver-launcher@0.0.4,而后者要求selenium-webdriver@^2.44.0。这导致依赖版本不兼容。 首先,我得分析问题根源。用户可能在项目中同时使用了需要新版本selenium-webdriver的包和一个旧版本的karma插件,而这两个包对selenium-webdriver的版本要求冲突。这时候,npm无法自动解决这种冲突,所以报错。 接下来,我需要考虑解决方案。常见的解决方法包括升级依赖包到兼容版本、降级不兼容的包、或者使用--legacy-peer-deps或--force参数强制安装。但用户可能更倾向于长期解决方案,而不是临时绕过问题。 首先,检查是否有karma-selenium-webdriver-launcher的更新版本支持selenium-webdriver@4.x。如果存在,升级该插件是最直接的解决办法。如果不存在,可能需要寻找替代插件或手动修改依赖。 如果无法升级插件,另一个办法是降级selenium-webdriver到2.44.0,但这可能会影响其他依赖需要新版本的包,导致更多问题。因此需要权衡。 此外,用户可能使用了npm的peerDependencies,而karma-selenium-webdriver-launcher@0.0.4声明了peerDependencey为selenium-webdriver@^2.44.0。这时候,如果项目中安装了更高版本的selenium-webdriver,npm会报错,因为peerDependencies需要满足版本范围。 可能的解决方案包括: 1. 使用--legacy-peer-deps参数安装,忽略peerDependencies的冲突。但这可能导致运行时错误,因为依赖版本不匹配。 2. 修改package.json中的依赖版本,确保所有依赖的版本范围兼容。例如,将selenium-webdriver改为^2.44.0,但需要检查其他依赖是否兼容旧版本。 3. 寻找替代的karma插件,比如karma-selenium-webdriver-launcher的更新版本或其他支持新selenium-webdriver的插件。 4. 如果项目允许,移除不需要的依赖,避免冲突。 用户可能希望得到具体的步骤,比如如何检查是否有可用的更新版本,或者如何修改依赖版本。同时,需要提醒用户潜在的风险,比如降级可能导致其他包不兼容,或者使用--force可能引入运行时错误。 最后,需要确保用户理解每种解决方案的优缺点,并根据他们的具体情况选择最合适的方法。</think>该错误是由于 `karma-selenium-webdriver-launcher@0.0.4` 依赖的 `selenium-webdriver@^2.44.0` 与当前安装的 `selenium-webdriver@4.30.0` 版本冲突导致的。以下是解决方案及原理说明: --- ### **解决方案** #### 1. **升级依赖包(推荐)** - **检查 `karma-selenium-webdriver-launcher` 是否有更新版本**: ```bash npm info karma-selenium-webdriver-launcher ``` 如果存在支持 `selenium-webdriver@4.x` 的版本(如 `karma-selenium-webdriver-launcher@1.0.0+`),则升级: ```bash npm install karma-selenium-webdriver-launcher@latest ``` #### 2. **降级 `selenium-webdriver`(临时方案)** - 如果无法升级 `karma-selenium-webdriver-launcher`,可降级 `selenium-webdriver` 到 `2.44.0`: ```bash npm install selenium-webdriver@2.44.0 ``` - **注意**:此操作可能影响其他依赖 `selenium-webdriver@4.x` 的模块,需确保项目兼容性。 #### 3. **使用 `--legacy-peer-deps` 或 `--force` 强制安装** - **临时绕过冲突**(不推荐长期使用): ```bash npm install --legacy-peer-deps # 或 npm install --force ``` - **风险**:可能导致运行时错误,因为依赖版本不匹配。 #### 4. **替换依赖包** - 如果 `karma-selenium-webdriver-launcher` 无更新版本,可改用兼容 `selenium-webdriver@4.x` 的替代插件,例如: ```bash npm uninstall karma-selenium-webdriver-launcher npm install karma-selenium-standalone-launcher ``` --- ### **验证修复** 1. 检查依赖树是否正常: ```bash npm ls selenium-webdriver ``` 2. 确保所有依赖的版本范围兼容。 --- ### **注意事项** - **peerDependencies 机制**:`karma-selenium-webdriver-launcher` 声明了 `peerDependencies`,要求项目中安装的 `selenium-webdriver` 版本必须满足 `^2.44.0`。若版本不匹配,npm 会报错。 - **长期维护建议**:优先升级依赖包以解决版本冲突,避免使用 `--force` 或 `--legacy-peer-deps` 作为长期方案。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值