英文:
problem in executing selenium standalone jar
问题
Hi I am beginner in Java selenium, i have problem in executing selenium standalone jar I am using
eclipse version 4.15, JDk 14.0, selenium 3.14
**error got**
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Java-selenium\selenium-server-standalone-3.141.59.jar
package SeleniumPractice;
import org.openqa.selenium.chrome.ChromeDriver;//error importing org.openqa.selenium.chrome.ChromeDriver not accessible
public class launchBrowser {
public static void main(String[] args) {
//launch chrome browser
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
ChromeDriver driver = new ChromeDriver();//Error: cannot b resolved
}
}
英文:
Hi I am beginner in Java selenium, i have problem in executing selenium standalone jar I am using
eclipse version 4.15, JDk 14.0, selenium 3.14
error got
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Java-selenium\selenium-server-standalone-3.141.59.jar
package SeleniumPractice;
import org.openqa.selenium.chrome.ChromeDriver;//error importing org.openqa.selenium.chrome.ChromeDriver not accessible
public class launchBrowser {
public static void main(String[] args) {
//launch chrome browser
System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
ChromeDriver driver = new ChromeDriver();//Error: cannot b resolved
}
}
答案1
得分: 1
如果您正在导入一个JAR包,那么包含.jar
文件的文件夹必须包含在您项目的CLASSPATH中。在这个讨论串中,您可以找到在Eclipse中设置项目类路径的说明。
您还应该考虑使用包管理器来管理依赖,例如Maven。Eclipse对Maven提供了很好的支持,您可以在这里找到详细信息。虽然这是一个Ubuntu教程,而您可能正在使用Windows,但这里的所有重要内容都是相同的。
如果您有任何其他问题,请在此回答下发表评论,我会相应地进行编辑。
如果您想尝试使用Maven,我附上了一个示例pom.xml
文件,这是用于运行Selenium测试的Maven项目的配置文件。要使用这个设置运行测试,您需要进入包含pom.xml
文件的文件夹,在此文件夹中运行命令mvn clean test
。
在使用该文件之前,请替换或删除:
com.example.your.domain
作为 groupIdyour-app-name
作为 artifactId,<repositories>
部分(因为我为一些内容使用私有仓库)- 任何不适合您的内容 - 请注意,Java版本设置为
1.8
,Selenium由TestNG框架管理,由Surefire插件执行,您不需要这个设置。
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.your.domain</groupId>
<artifactId>your-app-name</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>reporter</name>
<value>listenReport.Reporter</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
<!-- <repositories>
<repository>
You might have to add a custom repo.
</repository>
</repositories>-->
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>
英文:
If you are importing a JAR package, then the folder containing the .jar
file has to be included in the CLASSPATH of your project. In this thread you can find instructions for setting a project classpath in Eclipse.
You should also consider using a package manager for managing dependencies, for example Maven. Eclipse provides great support for Maven, you can find details here. It is Ubuntu tutorial while you are probably using Windows, but everything important is the same here.
If you'll have any additional questions, comment this answer and I'll edit it accordingly.
In case you wanted to try Maven, I've attached an example of a pom.xml
file - configuration file for Maven projects - that I use for running Selenuim tests. To run the tests using this setup, you need to go to the folder with the pom.xml
file. In this folder run command mvn clean test
Before using the file, replace or remove:
com.example.your.domain
as groupIdyour-app-name
as artifactId,- the
<repositories>
section (since I use a private repo for a few things) - anything that doesn't fit you - notice that Java version is set to
1.8
and Selenium is managed by TestNG framework, which is executed by Surefire plugin, you don't need this setup.
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.your.domain</groupId>
<artifactId>your-app-name</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>reporter</name>
<value>listenReport.Reporter</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
<!-- <repositories>
<repository>
You might have to add a custom repo.
</repository>
</repositories>-->
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论