hub 端
$ java -jar selenium-server-standalone-3.141.59.jar -role hub

node 端(hub 与 node 都在同一台机器上,系统为 Mac)
$ java -jar selenium-server-standalone-3.141.59.jar -role node -nodeConfig node.json

node.json

{
  "capabilities":
  [
    {
      "browserName": "firefox",
      "marionette": true,
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": -1,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://localhost:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

python 代码

from selenium import webdriver

import time

dc = {"platformName": "MAC"}

driver = webdriver.Remote(command_executor="http://127.0.0.1:4444/wd/hub", desired_capabilities=dc)

driver.get("http://www.baidu.com")
time.sleep(1)

driver.quit()

报错

Traceback (most recent call last):
  File "/Users/jiangyd/PycharmProjects/untitled15/w.py", line 10, in <module>
    driver=webdriver.Remote(command_executor="http://127.0.0.1:4444/wd/hub",desired_capabilities=dc)
  File "/Users/jiangyd/PycharmProjects/untitled15/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Users/jiangyd/PycharmProjects/untitled15/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Users/jiangyd/PycharmProjects/untitled15/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/jiangyd/PycharmProjects/untitled15/venv/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to create session from {
  "desiredCapabilities": {
    "platformName": "mac",
    "server:CONFIG_UUID": "56d4aa32-30c9-4e9b-bb8c-40c4c0975363"
  },
  "capabilities": {
    "firstMatch": [
      {
        "platformName": "mac",
        "server:CONFIG_UUID": "56d4aa32-30c9-4e9b-bb8c-40c4c0975363"
      }
    ]
  }
}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'jiangyd.local', ip: '10.100.64.189', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_151'
Driver info: driver.version: unknown
Stacktrace:
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4 (NewSessionPipeline.java:76)
    at java.util.Optional.orElseThrow (Optional.java:290)
    at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5 (NewSessionPipeline.java:75)
    at java.util.Optional.orElseGet (Optional.java:267)
    at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession (NewSessionPipeline.java:73)
    at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute (BeginSession.java:65)
    at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0 (WebDriverServlet.java:235)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)

Process finished with exit code 1

hub 的日志

15:31:18.891 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {platformName: mac}
15:31:18.891 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=56d4aa32-30c9-4e9b-bb8c-40c4c0975363, seleniumProtocol=WebDriver, marionette=true, browserName=firefox, maxInstances=5, platformName=MAC, platform=MAC}

node 没有日志

实际指定浏览器是可以的,firefox,chrome 都可以

from selenium import webdriver

import time

dc = {"browserName": "firefox"}
#dc = {"browserName": "chrome"} 

driver = webdriver.Remote(command_executor="http://127.0.0.1:4444/wd/hub", desired_capabilities=dc)

driver.get("http://www.baidu.com")
time.sleep(1)

driver.quit()

我想的是,这个 node 注册了两个浏览器,我想都运行不知道可行吗


↙↙↙阅读原文可查看相关链接,并与作者交流