本文介绍了如何正确设置Java/Selenium配置以运行自动化测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置硒Web驱动程序,以便与带有Java的Browserstack一起使用,以进行自动测试.我安装了Selenium for Java,然后从浏览器堆栈的网站 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是带有硒配置代码和示例测试的文件),并且出现以下错误:

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.

推荐答案

您必须从硒下载.您可以通过点击链接此处.

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.

还建议使用IDE for Java.最受欢迎的是 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配置以运行自动化测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 18:33