How to properly set up Java/Selenium configuration to run automated tests?

南笙酒味 提交于 2019-12-12 08:45:42

问题


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.

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

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.


回答1:


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.

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.

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.

Would also recommend using an IDE for Java. Most preferably Eclipse or Netbeans.



来源:https://stackoverflow.com/questions/33701682/how-to-properly-set-up-java-selenium-configuration-to-run-automated-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!