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

2024-01-02

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

I ran 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 Client & WebDriver Language Bindings”Java from 硒下载 http://www.seleniumhq.org/download。您可以点击链接直接下载here http://selenium-release.storage.googleapis.com/2.48/selenium-java-2.48.2.zip.

包括下载的 ZIP 文件中存在的所有 JAR 文件。要在 Java 类路径中包含多个 JAR,您可以检查链接here https://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath.

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

还建议使用 Java IDE。最常推荐的是智能理念 https://www.jetbrains.com/idea/, Eclipse https://eclipse.org/ide/, and Netbeans https://netbeans.org/features/java/.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何正确设置 Java/Selenium 配置来运行自动化测试? 的相关文章

随机推荐