Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 我的硒测试不起作用,问题出在哪里?_Selenium_Selenium Grid - Fatal编程技术网

Selenium 我的硒测试不起作用,问题出在哪里?

Selenium 我的硒测试不起作用,问题出在哪里?,selenium,selenium-grid,Selenium,Selenium Grid,我想使用selenium grid,这是我的步骤: 启动Selenium网格中心: java-jar-selenium-server-standalone-3.141.59.jar-ro-hub 启动Selenium节点: java-jar-selenium-server-standalone-3.141.59.jar-ro-node-hub-browser browserName=chrome Java代码: 但是,当我在IDE中运行此程序时,我发现测试部件从未到达,似乎处于前一步,只是停留在

我想使用selenium grid,这是我的步骤:

  • 启动Selenium网格中心: java-jar-selenium-server-standalone-3.141.59.jar-ro-hub
  • 启动Selenium节点: java-jar-selenium-server-standalone-3.141.59.jar-ro-node-hub-browser browserName=chrome
  • Java代码:
  • 但是,当我在IDE中运行此程序时,我发现测试部件从未到达,似乎处于前一步,只是停留在最后一步:

    driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
    
    我只在控制台上看到:

    Oct 05, 2019 10:08:15 AM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
    
    在selenim集线器控制台中:

    10:09:16.438 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, platform: MAC, version: }
    10:09:16.443 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=952f43b8-f264-48b3-aa6f-eff6ff59b16e, seleniumProtocol=WebDriver, browserName=chrome, platformName=MAC, platform=MAC}
    
    Got a request to create a new session: Capabilities {browserName: chrome, platform: MAC}
    10:30:12.334 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=4b8d38ff-8be6-4894-8c17-8fe334c7c3bc, seleniumProtocol=WebDriver, browserName=chrome, maxInstances=5, platformName=MAC, platform=MAC}
    10:30:28.926 INFO [RequestHandler.process] - Error forwarding the new session Error forwarding the request Failed to connect to /10.1.3.246:14786
    org.openqa.grid.internal.exception.NewSessionException: Error forwarding the request Failed to connect to /10.1.3.246:14786
        at org.openqa.grid.web.servlet.handler.RequestHandler.forwardNewSessionRequestAndUpdateRegistry(RequestHandler.java:94)
        at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:114)
        at org.openqa.grid.web.servlet.Driver
    
    然后永远不要到达测试部分

    请帮忙告诉我这里发生了什么事

    我正在使用mac,因此
    chromedriver--version
    提供:

    ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442})
    
    我在与selenium-server-standaralon-3.141.jar文件夹相同的文件夹中运行此命令,这是java junit的错误:

    org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。所需能力=能力[{browserName=chrome,版本=,平台=MAC}],所需能力=能力[{}] 构建信息:版本:'3.0.1',修订版:'1969d75',时间:'2016-10-18 09:49:13-0700' 系统信息:主机:'Franks MacBook Pro.local',ip:'192.168.0.103',os.name:'Mac os X',os.arch:'x86_64',os.version:'10.14.6',java.version:'1.8.0_171' 驱动程序信息:Driver.version:RemoteWebDriver

    我按照如下说明操作,但在启动java junit时,我从selenium server hub控制台得到了错误:

    10:09:16.438 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: chrome, platform: MAC, version: }
    10:09:16.443 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=952f43b8-f264-48b3-aa6f-eff6ff59b16e, seleniumProtocol=WebDriver, browserName=chrome, platformName=MAC, platform=MAC}
    
    Got a request to create a new session: Capabilities {browserName: chrome, platform: MAC}
    10:30:12.334 INFO [TestSlot.getNewSession] - Trying to create a new session on test slot {server:CONFIG_UUID=4b8d38ff-8be6-4894-8c17-8fe334c7c3bc, seleniumProtocol=WebDriver, browserName=chrome, maxInstances=5, platformName=MAC, platform=MAC}
    10:30:28.926 INFO [RequestHandler.process] - Error forwarding the new session Error forwarding the request Failed to connect to /10.1.3.246:14786
    org.openqa.grid.internal.exception.NewSessionException: Error forwarding the request Failed to connect to /10.1.3.246:14786
        at org.openqa.grid.web.servlet.handler.RequestHandler.forwardNewSessionRequestAndUpdateRegistry(RequestHandler.java:94)
        at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:114)
        at org.openqa.grid.web.servlet.Driver
    
    我在将chromedriver复制到与selenium jar文件夹相同的文件夹后看到了这个错误

    在Java控制台中,我看到:

    Oct 08, 2019 10:30:12 AM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
    Oct 08, 2019 10:31:28 AM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Falling back to original OSS JSON Wire Protocol.
    Oct 08, 2019 10:32:44 AM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Falling back to straight W3C remote end connection
    
    org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, platform=MAC}], required capabilities = Capabilities [{}]
    Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
    System info: host: 'my.local', ip: '10.1.2.137', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_171'
    Driver info: driver.version: RemoteWebDriver
    
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
        at com.datavisor.e2e.TestGrid.setup(TestGrid.java:41)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
        at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    
    2019年10月8日上午10:30:12 org.openqa.selenium.remote.ProtocolHandshake-createSession
    信息:正在尝试双方言会话,假设远程端的Postel定律成立
    2019年10月8日上午10:31:28 org.openqa.selenium.remote.ProtocolHandshake createSession
    信息:回到原来的OSS JSON Wire协议。
    2019年10月8日上午10:32:44 org.openqa.selenium.remote.ProtocolHandshake createSession
    信息:退回到直接的W3C远程端连接
    org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。所需能力=能力[{browserName=chrome,platform=MAC}],所需能力=能力[{}]
    构建信息:版本:'3.0.1',修订版:'1969d75',时间:'2016-10-18 09:49:13-0700'
    系统信息:主机:'my.local',ip:'10.1.2.137',os.name:'Mac os X',os.arch:'x86_64',os.version:'10.14.6',java.version:'1.8.0_171'
    驱动程序信息:Driver.version:RemoteWebDriver
    位于org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
    位于org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    位于org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    位于org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
    位于org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:128)
    位于org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:155)
    位于com.datavisor.e2e.TestGrid.setup(TestGrid.java:41)
    在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
    位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
    位于java.lang.reflect.Method.invoke(Method.java:498)
    位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:50)
    位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:47)
    位于org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    位于org.junit.internal.runners.statements.runafter.evaluate(runafter.java:27)
    位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    位于org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    位于org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    位于org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    访问org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    位于org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    位于org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    位于org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    位于com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    位于com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    位于com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    位于com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    

    可能是版本问题?

    您使用的是Junit吗?如果是这样,请检查Junit错误跟踪以了解以下错误

    org.openqa.selenium.SessionNotCreatedException:无法创建新服务:ChromeDriverService 构建信息:版本:“3.141.59”,修订版:“e82be7d358”,时间:“2018-11-14T08:25:53”

    如果这是您得到的错误

    我相信您的浏览器会话在执行时从未创建过-看起来您在节点计算机上没有可执行的驱动程序。在selenium-server-standalone-3.141.59的同一文件夹中保留驱动程序可执行文件(如果您使用的是chrome浏览器,请选择支持浏览器版本的适当驱动程序版本)

    或者,在启动节点时尝试添加-Dwebdriver.chrome.driver=chromedriver参数。你的全部指挥权将是

    java -jar -Dwebdriver.chrome.driver=chromedriver selenium-server-standalone-3.141.59.jar -role node -hub http://localhost:4444/grid/register -browser browserName=chrome
    

    您的命令是
    -ro
    ,您的意思可能是
    -role

    尝试以下步骤:

  • 打开命令行:
  • 如果成功,您将获得以下日志:

    [Hub.start] - Selenium Grid hub is up and running
    [Hub.start] - Nodes should register to http://somethingIP:4444/grid/register/
    [Hub.start] - Clients should connect to http://somethingIP:4444/wd/hub
    
    The node is registered to the hub and ready to use
    
  • 打开另一个命令行(或新选项卡):
  • The node is registered to the hub and ready to use
    import java.net.MalformedURLException;
    import java.net.URL;
    
    import org.junit.After;
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.Platform;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    
    public class TestGrid {
        private RemoteWebDriver driver;
        private DesiredCapabilities capabilities = new DesiredCapabilities();
        private String nodeUrl;
    
        @Before
        public void setUp() throws MalformedURLException {
            nodeUrl = "http://localhost:4444/wd/hub";
            capabilities.setBrowserName("chrome");
            capabilities.setPlatform(Platform.MAC);
            driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);   
        }
    
        @Test
        public void simpleTest() {
            driver.get("https://www.edureka.co");
            Assert.assertEquals("Instructor-Led Online Training with 24X7 Lifetime Support | Edureka", driver.getTitle());
        }
    
        @After
        public void afterTest() {
            driver.quit();
        }
    }