首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确设置Java/Selenium配置以运行自动化测试?

问如何正确设置Java/Selenium配置以运行自动化测试?
EN

Stack Overflow用户
提问于 2015-11-14 05:00:37
回答 1查看 25K关注 0票数 11

我正在尝试设置selenium webdriver,以便与带有Java的Browserstack一起工作,以实现自动化测试。我安装了Selenium for java,并从browserstack的站点https://www.browserstack.com/automate/java#configure-capabilities复制并粘贴了代码,以设置一个示例自动化测试。

我从我的终端运行javac -classpath selenium-server-standalone-2.48.2.jar JavaSample.java (JavaSample.java是带有示例测试的selenium配置代码的文件),我得到以下错误:

代码语言:javascript
复制
JavaSample.java:1: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
                      ^
JavaSample.java:2: error: package org.openqa.selenium does not exist
import org.openqa.selenium.Platform;
                      ^
JavaSample.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
                      ^
JavaSample.java:4: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebElement;
                      ^
JavaSample.java:5: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.DesiredCapabilities;
                             ^
JavaSample.java:6: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.RemoteWebDriver;
                             ^
JavaSample.java:18: error: cannot find symbol
DesiredCapabilities caps = new DesiredCapabilities();
^
symbol:   class DesiredCapabilities
location: class JavaSample
JavaSample.java:18: error: cannot find symbol
DesiredCapabilities caps = new DesiredCapabilities();
                               ^
symbol:   class DesiredCapabilities
location: class JavaSample
JavaSample.java:25: error: cannot find symbol
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
^
symbol:   class WebDriver
location: class JavaSample
JavaSample.java:25: error: cannot find symbol
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
                       ^
symbol:   class RemoteWebDriver
location: class JavaSample
JavaSample.java:27: error: cannot find symbol
WebElement element = driver.findElement(By.name("q"));
^
symbol:   class WebElement
location: class JavaSample
JavaSample.java:27: error: cannot find symbol
WebElement element = driver.findElement(By.name("q"));
                                        ^
symbol:   variable By
location: class JavaSample

我不知道该怎么做,因为我只是遵循了Browserstack上的说明,而且我对Java的了解很少。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-14 14:30:30

您必须从Selenium Downloads下载的"Selenium Client & WebDriver Language Bindings“。您可以通过单击链接here直接下载。

包括下载的ZIP文件中存在的所有JAR文件。要在Java类路径中包含多个JAR,可以检查链接here。

如果您在本地运行测试,则需要selenium-server-standalone JAR。执行命令java -jar selenium-server-standalone-2.48.2.jar将启动Selenium服务器,这是在本地启动Selenium测试所必需的。如果您在BrowserStack上运行测试,则不需要使用它。

我也推荐使用Java的IDE。最常用的推荐方法是IntelliJ Idea、Eclipse和Netbeans。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33701682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档