問題描述
我正在嘗試設置 selenium webdriver 以與帶有 Java 的 Browserstack 一起使用以進行自動化測試.我為 Java 安裝了 Selenium,并從 browserstack 的站點 https://www 復制并粘貼了代碼.browserstack.com/automate/java#configure-capabilities 設置一個示例自動化測試.
I am trying to set up selenium webdriver to work together with Browserstack with Java for automated testing. I installed the Selenium for java and I copied and pasted the code from browserstack's site https://www.browserstack.com/automate/java#configure-capabilities to set up an example automation test.
我從終端運行了 javac -classpath selenium-server-standalone-2.48.2.jar JavaSample.java
(JavaSample.java 是帶有示例測試的 selenium 配置代碼的文件)和我收到以下錯誤:
I ran javac -classpath selenium-server-standalone-2.48.2.jar JavaSample.java
from my terminal (JavaSample.java is the file with the selenium configuration code with the sample test) and I get the following error:
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 的背景很少.
I'm not sure how to go about this being as I just followed the instructions on Browserstack and I have very little background in Java.
推薦答案
您必須從 Selenium 下載.您可以點擊此處.
You will have to download the "Selenium Client & WebDriver Language Bindings" for Java from Selenium Downloads. You can download directly by clicking the link here.
包括下載的 ZIP 文件中存在的所有 JAR 文件.要在 Java 類路徑中包含多個 JAR,您可以查看此處的鏈接.
Include all the JAR files that are present in the downloaded ZIP file. To include multiple JARs in Java classpath, you can check the link here.
如果您在本地運行測試,則需要 selenium-server-standalone JAR
.執行命令 java -jar selenium-server-standalone-2.48.2.jar
將啟動一個 Selenium 服務器,它需要在本地啟動 Selenium 測試.如果您在 BrowserStack 上運行測試,則不需要使用它.
The selenium-server-standalone JAR
is required if you are running your tests locally. Executing the command java -jar selenium-server-standalone-2.48.2.jar
will start a Selenium server, which required to launch Selenium tests locally. You need not use it, if you are running tests on BrowserStack.
還建議使用適用于 Java 的 IDE.最普遍推薦的是 IntelliJ Idea、Eclipse 和 Netbeans.
Would also recommend using an IDE for Java. The most commonly recommended ones are IntelliJ Idea, Eclipse, and Netbeans.
這篇關于如何正確設置 Java/Selenium 配置以運行自動化測試?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!