Java 如何运行 selenium-server-standalone?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28853634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 06:56:52  来源:igfitidea点击:

how to run a selenium-server-standalone?

javaseleniumjarserver

提问by Elad Benda

I'm trying to run selenium server, and get errors:

我正在尝试运行 selenium 服务器,但出现错误:

rond-macpro:selenium eladb$  java -Dwebdriver.chrome.driver=./chromedriver -r selenium-server-standalone-2.44.0.jar
Unrecognized option: -r
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

and without -r (what is it anyway?)

并且没有 -r(它到底是什么?)

rond-macpro:selenium eladb$  java -Dwebdriver.chrome.driver=./chromedriver  selenium-server-standalone-2.44.0.jar
Error: Could not find or load main class selenium-server-standalone-2.44.0.jar

how should I start the server?

我应该如何启动服务器?

how do I set a non-default port to listen to?

如何设置一个非默认端口来监听?

These two posts: 12- contradicts regarding the syntax. I think.

这两篇文章:1 2- 与语法相矛盾。我认为。

采纳答案by Saifur

java -jar seleniumjar.jar -Dwebdriver.chrome.driver=./chromedriver 

If you want to specifiy the port do

如果你想指定端口做

java -jar seleniumjar.version.jar -Dwebdriver.chrome.driver=./chromedriver -port 4545

As of 3.8.1, specifying the driver is no longer necessary:

从 3.8.1 开始,不再需要指定驱动程序:

java -jar seleniumjar.jar

回答by Giri

java -jar selenium-server-standalone-2.44.0.jar -port port_no

回答by Yash

Running Standalone Selenium Server:

运行独立Selenium 服务器

Form Jar SourceMain-Classisorg.openqa.grid.selenium.GridLauncher

形式Jar Source Main-Classorg.openqa.grid.selenium.GridLauncher

As per GridRoleclass - Selenium server can run in one of the following roles:

根据GridRole课程 - Selenium 服务器可以以以下角色之一运行:

  1. NOT_GRID[If -role option is omitted the server runs standalone not being a part of a grid]>
  2. HUB[as a hub of a Selenium grid]
  3. NODE[as a node of a Selenium grid]
  1. NOT_GRID[如果省略 -role 选项,则服务器独立运行而不是网格的一部分]>
  2. HUB[作为 Selenium 网格的枢纽]
  3. NODE[作为 Selenium 网格的节点]
D:\> java -jar selenium-server-standalone-*.jar -host 127.0.0.1 -port 4444


NOT GRID

非网格

SeleniumRemote Control (RC) requires server to be started before executing the test scripts.RC server injects Selenium core (JavaScript)into the browser. The core (daemon process) receives commands from the server by your test scripts and executes them in a browser then results to your program. But cannot handle moving mouse cursors & mobile execution.

SeleniumRemote Control ( RC) 要求在执行测试脚本之前启动服务器。RC 服务器将Selenium 核心 (JavaScript)注入浏览器。核心(守护进程)通过您的测试脚本从服务器接收命令,并在浏览器中执行它们,然后生成您的程序。但无法处理移动鼠标光标和移动执行。

Java Client Driver: Client-Configures your browser to use the Selenium Server as an HTTP proxy and passes browser commands to server through "/selenium-server/RemoteRunner.html?sessionId=1234", clients may send Driver Command requeststo selenium server over HTTP as follows:

Java 客户端驱动程序: 客户端配置您的浏览器以使用 Selenium 服务器作为 HTTP 代理,并通过 将浏览器命令传递给服务器"/selenium-server/RemoteRunner.html?sessionId=1234",客户端可以通过 HTTP 向 selenium 服务器发送驱动程序命令请求,如下所示:

Code & Requests: RC Server continuously runs. we create a daemon and from that communicate with the browser.

代码和请求:RC 服务器持续运行。我们创建了一个守护进程,并从中与浏览器通信。

Selenium daemon = new DefaultSelenium("172.16.20.156", 4464, "*firefox", "https://www.google.co.in/");
daemon.start(); -- daemon.stop(); (OR)
setUp("http://www.google.com/", "*firefox", 4454); selenium.windowMaximize();

GET:http://localhost:4454/selenium-server/driver/?cmd=open&1=https://www.google.co.in/&sessionId=9b1a232d9478497892e09cfc93cf665a
  • RC(WebDriverinterface)- IP:Port/wd/hub/static/resource/hub.html:
  • RC( :WebDriverinterface)- IP:Port/wd/hub/static/resource/hub.html

RWDCode & Requests:

RWD代码和请求

WebDriver nativeDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4454/wd/hub"), DesiredCapabilities.firefox());

Requests:
http://127.0.0.1:4454/wd/hub/session
    /123...[SESSIONID]
        /url
        { "url" : "http://demo.opencart.com/index.php?route=account/login" }


        /execute
        { "script" : "document.querySelectorAll( arguments[0] )[0].click();", "args" : ['input.btn'] }


Grid: [ - IP:Port/grid/console]

网格: [- IP:Port/grid/console]

HUBGrid HUB Running as a standalone server:Hub is a central point which distributing tests on several node-machines, which are registered to it for parallel execution.

HUB Grid HUB Running as a standalone server:Hub 是一个中心点,它在多个节点机器上分发测试,这些节点机器注册到它以并行执行。

java -jar selenium-server-standalone-2.53.0.jar -host 127.0.0.1 -port 4454 -role hub -log "D:\HUB_Log.txt"

NODE[RC] has to post a request to HUB in order to register with it, by this URL - IP:Port//grid/register.

NODE [RC] 必须通过此 URL 向 HUB 发布请求才能注册IP:Port//grid/register

java -jar selenium-server-standalone-2.53.0.jar -host 127.0.0.1 -port 4458 -role node 
-hub http://127.0.0.1:4454/grid/register -hubHost 127.0.0.1 -hubPort 4454 
-browser browserName=firefox,version=24.0, maxinstance=1,platform=WINDOWS7 
-browser  browserName=chrome,version=53.0,platform=WINDOWS 
-Dwebdriver.chrome.driver=D:\Drivers\chromedrivers\2.24\chromedriver.exe

Running as a grid node:browser Instance INFO: browserName=chrome, version=53.0, maxinstance=1, platform=WINDOWS Command Line parameters with System Propertyvalues -Dproperty=value -Dchrome=driverAddress(If value is a string that contains spaces, you must enclose the string in double quotes)

Running as a grid node:浏览器实例信息:browserName=chrome, version=53.0, maxinstance=1, platform=WINDOWS Command Line parameters with System Propertyvalues -Dproperty=value -D chrome= driverAddress(如果值是包含空格的字符串,则必须将字符串括起来双引号)

Node registration with a JSON configuration file registerNode.json.

使用JSON 配置文件进行registerNode.json节点注册。

D:\SeleniumJar_Source>java -jar selenium-server-standalone-2.53.0.jar -role node 
-hub http://127.0.0.1:4454/grid/register 
-nodeConfig registerNode.json 
-Dwebdriver.chrome.driver="D:\Drivers\chromedrivers\2.24\chromedriver.exe" 
-Dwebdriver.ie.driver="D:\Drivers\IEDrivers\iedriver64\IEDriverServer.exe" 
-Dwebdriver.firefox.logfile="D:\FirefoxInstance.txt" 
-Dwebdriver.chrome.logfile="D:\ChromeInstance.txt" 
-Dwebdriver.ie.logfile="D:\IEInstance.txt"


WebDriverdoesn't require any server start before start execution. You can see that WebDriveracts just as a normal Java library does: it's entirely self-contained, and you don't need to remember to start any additional processes or run any installers before using it.

WebDriver在开始执行之前不需要任何服务器启动。您可以看到WebDriver就像一个普通的 Java 库一样:它是完全独立的,在使用它之前您不需要记住启动任何额外的进程或运行任何安装程序。

WebDriver driver = new FirefoxDriver();


Selenium Server

硒服务器

@see

@看

回答by Yan Khonski

I would like to add more webdrivers to @Saifur answer. https://stackoverflow.com/a/28854250/4587961

我想在@Saifur 答案中添加更多网络驱动程序。 https://stackoverflow.com/a/28854250/4587961

java   -Dwebdriver.ie.driver=./IEDriverServer32.exe -Dwebdriver.chrome.driver=./chromedriver.exe -jar selenium.jar -port 4545

Note, for IE you run 32 bit version of the driver. And it works. I created a bat file and put it inside of the selenium folder where I also put drivers.

请注意,对于 IE,您运行的是 32 位版本的驱动程序。它有效。我创建了一个 bat 文件并将其放在 selenium 文件夹中,我也在其中放置了驱动程序。