当前位置: 首页 > 面试题库 >

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

戚衡
2023-03-14
问题内容

我试图设置Selenium Webdriver与Java的Browserstack一起使用,以进行自动测试。我安装了Selenium for
Java,然后从浏览器堆栈的站点https://www.browserstack.com/automate/java#configure-
capabilities
复制并粘贴了代码,以建立示例自动化测试。

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

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的了解很少。


问题答案:

您必须从Selenium Downloads下载 Java 的“
Selenium客户端和WebDriver语言绑定” 。您可以通过单击此处的链接直接下载。

包括下载的ZIP文件中存在的所有JAR文件。要在Java类路径中包含多个JAR的selenium-server-standalone JAR,如果您是在本地运行测试是必需的。执行该命令java -jar selenium-server-standalone-2.48.2.jar将启动Selenium服务器,该服务器需要在本地启动Selenium测试。如果要在BrowserStack上运行测试,则无需使用它。

还将建议使用IDE for Java。最受欢迎的是IntelliJIdea,Eclipse和Netbeans。



 类似资料:
  • 我正在尝试设置selenium网络驱动程序,以便与浏览器堆栈一起使用Java进行自动化测试。我为java安装了Selenium,并从浏览器堆栈的站点https://www.browserstack.com/automate/java#configure-capabilities复制和粘贴代码以设置示例自动化测试。 我运行了javac-classpath selenium-server-standa

  • 问题内容: 我想开始为我的Python代码编写单元测试,而py.test框架听起来比Python捆绑的unittest更好。因此,我在项目中添加了“ tests”目录,并在其中添加了test_sample.py。现在,我想配置PyCharm以运行“ tests”目录中的所有测试。 据称,PyCharm在其测试运行程序中支持py.test。您应该能够创建运行/调试配置来运行测试,并且PyCharm据

  • 问题内容: 我在Appium面临的问题是我在下面决定的。不使用SUDO,我找不到安装Appium所需组件的方法。用SUDO安装所有组件之后,然后尝试运行Appium,我得到了错误,应该在没有SUDO的情况下安装Appium和NODE。尝试在线搜索解决方案花了我一段时间,因为在使用JAVA开发测试时,几乎没有在线教程可供Appium在MAC上运行。以下是有关如何在Mac OS上设置Appium以及如

  • 问题内容: 我正在尝试运行Java程序,但是它采用默认的GMT时区而不是OS定义的时区。我的JDK版本是1.5,操作系统是Windows Server Enterprise(2007) Windows指定了中央时区,但是当我运行以下程序时,它给了我GMT时间。 这是输出 请注意,我不想从应用程序中设置时区。我希望JVM使用的时区应该是操作系统中指定的时区。(对于具有JDK 1.4版和Microso

  • 我试图完成本教程,但我认为在配置网页时遇到了一些问题。我正在一步一步地制作教程,但它不起作用。。 错误]无法执行目标com。github。eirslett:frontend maven插件:1.10.3:project shop上的webpack(webpack生成):无法运行任务:“webpack”。js'失败了。组织。阿帕奇。平民执行官。ExecuteException:进程已退出,但出现错误

  • 本文向大家介绍如何正确设置VIM自动缩进以编辑Python文件?,包括了如何正确设置VIM自动缩进以编辑Python文件?的使用技巧和注意事项,需要的朋友参考一下 要为VIM中的python文件设置autoindent,请使用以下配置: 示例 将此配置添加到主文件夹中的.vimrc文件。