使用Selenium Grid在MacOS Mojave上运行Safari

时间:2019-01-31 14:36:57

标签: java selenium selenium-webdriver selenium-grid safaridriver

我正在尝试使用Selenium Grid进行基本测试,以在MacOS上启动Safari。

我已经注册了该节点,该节点在我的集线器中显示如下。

Hub Confirmating node is up

  • browserTimeout:0
  • 调试:错误
  • 主机:10.120.45.211
  • 端口:5558
  • 角色:节点
  • 超时:1800
  • cleanUpCycle:5000
  • maxSession:5
  • 功能:功能{浏览器名称:Safari,maxInstances:1 平台:MAC,平台名称:MAC,硒协议:WebDriver, 服务器:CONFIG_UUID:1ba7b7b4-556c-430a-ab84-157 ...}
  • downPollingLimit:2
  • 中心:http://10.120.45.245:4444/grid/register
  • id:http://10.120.45.211:5558
  • nodePolling:5000
  • nodeStatusCheckTimeout:5000
  • 代理:org.openqa.grid.selenium.proxy.DefaultRemoteProxy
  • 注册:true
  • registerCycle:5000
  • remoteHost:http://10.120.45.211:5558
  • unregisterIfStillDownAfter:60000

我了解到SafariDriver现在可以直接在macOS中使用,我正在使用这些步骤来确保其正确设置。

(如果尚未这样做),请使“开发”菜单可用。选择Safari>首选项,然后在“高级”选项卡上,选择“在菜单栏中显示“开发”菜单。”有关详细信息,请参阅Safari帮助。 选择“开发>允许远程自动化”。 授权safaridriver启动承载本地Web服务器的XPC服务。为此,请手动运行一次/ usr / bin / safaridriver并按照身份验证提示进行操作。

这是我的JAVA代码:

//tr[td[contains(text(),'Physical Street Address')]]/td//input[contains(@id, 'part1')]

运行程序时,我收到以下消息。

package SeleniumGrid;

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class SafariRemoteAccess {

    public static void main(String[] args) throws MalformedURLException {

        DesiredCapabilities dc = new DesiredCapabilities();
        dc.setBrowserName("Safari");

        //Point to hub
        WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);

        // Go to website via NODE
        driver.get("https://www.hsbc.co.uk/");
        driver.quit();
    }
}

更新

这是用于在MacOS机器上设置NODE的代码:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
  "desiredCapabilities": {
    "browserName": "Safari",
    "server:CONFIG_UUID": "1ba7b7b4-556c-430a-ab84-1574fc7ea584"
  },
  "capabilities": {
    "firstMatch": [
      {
        "browserName": "Safari",
        "server:CONFIG_UUID": "1ba7b7b4-556c-430a-ab84-1574fc7ea584"
      }
    ]
  }
}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'Mishal-Shahs-MacBook-Pro.local', ip: 'fe80:0:0:0:c9b:214f:9f0:2788%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '1.8.0_202'
Driver info: driver.version: unknown
Command duration or timeout: 198 milliseconds**
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at SeleniumGrid.SafariRemoteAccess.main(SafariRemoteAccess.java:17)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
  "desiredCapabilities": {
    "browserName": "Safari",
    "server:CONFIG_UUID": "1ba7b7b4-556c-430a-ab84-1574fc7ea584"
  },
  "capabilities": {
    "firstMatch": [
      {
        "browserName": "Safari",
        "server:CONFIG_UUID": "1ba7b7b4-556c-430a-ab84-1574fc7ea584"
      }
    ]
  }
}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'Mishal-Shahs-MacBook-Pro.local', ip: 'fe80:0:0:0:c9b:214f:9f0:2788%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '1.8.0_202'
Driver info: driver.version: unknown
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'LAPTOP-1MOS5JFR', ip: '10.120.45.245', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_192'
Driver info: driver.version: unknown
    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)

1 个答案:

答案 0 :(得分:0)

从错误堆栈跟踪中还不清楚 Selenium Grid 是否在 Mac OS X 上,并且要启动 Selenium Node 使用命令:

java -Dwebdriver.safari.driver=/System/Library/CoreServices/SafariSupport.bundle/Contents/MacOS/safaridriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -hub 10.120.45.245:4444/grid/register -port 5558 -browser "browserName=Safari, platform=MAC, platformName=MAC, maxInstances=1"

为什么您会看到错误日志(与 Selenium Grid 有关):

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'Mishal-Shahs-MacBook-Pro.local', ip: 'fe80:0:0:0:c9b:214f:9f0:2788%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '1.8.0_202'
Driver info: driver.version: unknown

然后再次(第一组与 Mac OS X 相关,第二组与 Windows 10 相关):

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'Mishal-Shahs-MacBook-Pro.local', ip: 'fe80:0:0:0:c9b:214f:9f0:2788%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.2', java.version: '1.8.0_202'
Driver info: driver.version: unknown
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'LAPTOP-1MOS5JFR', ip: '10.120.45.245', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_192'
Driver info: driver.version: unknown

但是,您用来启动 Selenium Grid Node 的命令容易出错,因为它同时包含以下两者:

  • platform = MAC
  • platformName = MAC

假定正在从 Windows 10 框中启动 Selenium Grid Node ,命令应为:

java -Dwebdriver.safari.driver=C:\path\to\safaridriver.exe -jar selenium-server-standalone-3.141.59.jar -role node -hub 10.120.45.245:4444/grid/register -port 5558 -browser "browserName=safari, platform=WINDOWS, maxInstances=1"

注意:确保在 Windows 10 中安装了 Safari 浏览器。