简体   繁体   English

缺少 JAR 用于从 Java 启动 Selenium 服务器

[英]Missing JAR for starting Selenium server from Java

I'm completely new to Selenium, and I'm using version 2.0rc2.我对 Selenium 完全陌生,我使用的是 2.0rc2 版本。 I've seen a lot of resources showing how to start the server programmatically through Java, but what has me confused is that the two JARs for Selenium 2.0rc2 do not have the package org.openqa.selenium.server.SeleniumServer I need to import in order to do this. I've seen a lot of resources showing how to start the server programmatically through Java, but what has me confused is that the two JARs for Selenium 2.0rc2 do not have the package org.openqa.selenium.server.SeleniumServer I need to import为此。

Has this been deprecated in place of something different in 2.0?这是否已被弃用以代替 2.0 中的不同内容? If so, how do I start the server from Java?如果是这样,我如何从 Java 启动服务器? If not, why is that import not there?如果没有,为什么那个进口不存在?

Here it is, add this to your CLASSPATH:在这里,将其添加到您的 CLASSPATH:

http://repo1.maven.org/maven2/org/seleniumhq/selenium/selenium-server/2.0rc2/selenium-server-2.0rc2.jar http://repo1.maven.org/maven2/org/seleniumhq/selenium/selenium-server/2.0rc2/selenium-server-2.0rc2.Z68995488DBF432492DAC404

If you are using maven, simply add to your pom.xml :如果您使用的是 maven,只需添加到您的pom.xml

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-server</artifactId>
  <version>2.0rc2</version>
</dependency>

BTW org.openqa.selenium.server.SeleniumServer is a class located inside org.openqa.selenium.server package. BTW org.openqa.selenium.server.SeleniumServer is a class located inside org.openqa.selenium.server package.

It depends what it is you want to do.这取决于你想做什么。 The easiest way for you to get set up is to download the standalone-jar and add it to your buildpath.最简单的设置方法是下载standalone-jar 并将其添加到您的构建路径中。 This will add the selenium stuff as well as all its dependencies.这将添加 selenium 内容及其所有依赖项。

Now you can actually already start off very very simply.现在您实际上已经可以非常非常简单地开始了。 This is a very decent place to get started but the examples there are using older APIs.是一个非常不错的起点,但那里的示例使用的是较旧的 API。 Actions should now be done with advanced user interactions .现在应该通过高级用户交互来完成操作。

To understand what SeleniumServer is for you must understand there are two ways to use Selenium.要了解 SeleniumServer 的用途,您必须了解使用 Selenium 的两种方法。 You can either use the 'client' which are language bindings which deal with browser launching, etc. An example of this is:您可以使用“客户端”,它们是处理浏览器启动等的语言绑定。一个例子是:

WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.co.uk");
driver.quit();

This should launch an instance of internet explorer, go to google and immediately exit.这应该会启动一个 Internet Explorer 实例 go 到谷歌并立即退出。 The 'server' side of the code is where you can launch an instance of a server on a machine and have your code connect to it.代码的“服务器”端是您可以在机器上启动服务器实例并让您的代码连接到它的地方。 This can be done programmatically but also more easily via the command line.这可以通过编程方式完成,但也可以通过命令行更轻松地完成。 The JAR you downloaded can be invoked with 'java -jar' as well as providing the Selenium API.您下载的 JAR 可以使用“java -jar”调用,并提供 Selenium API。 For example if you went to a command prompt and did:例如,如果您转到命令提示符并执行以下操作:

java -jar selenium.jar .... 

Assuming you gave valid arguments it would kick off a server instance which waits for code to connect to it.假设您提供了有效的 arguments 它将启动一个等待代码连接到它的服务器实例。 I'm actually not 100% sure whether this is for SeleniumRC (1.0 API) or WebDriver (2.0 API).我实际上不是 100% 确定这是否适用于 SeleniumRC (1.0 API) 或 WebDriver (2.0 API)。

To answer your question directly I just downloaded the standalone which does contain SeleniumServer.为了直接回答您的问题,我刚刚下载了包含 SeleniumServer 的独立版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM