Java Selenium Webdriver在打开Firefox时失败
我正在学习如何使用Maven for Selenium Webdriver创建一个新项目。我创建了一个pom.xml文件和一个包含测试的基本测试文件 这是: pom.xmlJava Selenium Webdriver在打开Firefox时失败,java,maven,selenium,selenium-webdriver,Java,Maven,Selenium,Selenium Webdriver,我正在学习如何使用Maven for Selenium Webdriver创建一个新项目。我创建了一个pom.xml文件和一个包含测试的基本测试文件 这是: pom.xml <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 h
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CleanSubmission</groupId>
<artifactId>CleanSubmission</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>CleanSubmissions</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.github.yev</groupId>
<artifactId>screenshot</artifactId>
<version>0.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.13</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.13</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xvfb</id>
<phase>test-compile</phase>
<goals>
<goal>xvfb</goal>
</goals>
<configuration>
<displayPropertiesFile>2.3</displayPropertiesFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
但总有一个错误
java.lang.NullPointerException:COS2Clean.CleanSubmissions.ClearSubmissionTest.Testno1(ClearSubmissionTest.java:21)处为null
它指向行driver.get(baseUrlAdmin)代码>。
我一直在寻找答案,包括更新Selenium,选择FirefoxWebDriver作为二进制文件,但所有方法都失败了
在我进行调试时,我发现问题出在org.apache.maven.plugin.MojoFailureException
上,而不是我的代码,因此pom.xml文件中肯定缺少一些内容-目前我还不知道还有什么地方可能出错…您已经在第8行课后将webdriver实例声明为“driver”。在Before注释的setUp方法中,再次声明实例
只需使用下面的inside setUp()并尝试:-
driver = new FirefoxDriver();
您已经在第8行的课后将webdriver实例声明为“driver”。在Before注释的setUp方法中,再次声明实例
只需使用下面的inside setUp()并尝试:-
driver = new FirefoxDriver();
使用以下代码更新CleanSubmissionTest.java文件
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ClearSubmissionTest{
public WebDriver driver;
String baseUrlAdmin = "http://www.google.pl/";
@BeforeTest
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
@Test
public void Testno1() throws Exception {
driver.get(baseUrlAdmin);
Thread.sleep(5000);
}
@AfterTest
public void tearDown() throws Exception {
driver.close();
}
}
如果您仍然面临任何问题,请使用以下代码更新您的依赖项和插件,然后重试
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.github.yev</groupId>
<artifactId>screenshot</artifactId>
<version>0.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
</plugin>
</plugins>
</pluginManagement>
</build>
org.testng
testng
6.9.10
org.seleniumhq.selenium
硒爪哇
3.3.0
org.seleniumhq.selenium
selenium firefox驱动程序
3.3.1
com.github.yev
截图
0.2
org.codehaus.mojo
execmaven插件
1.2.1
JAVA
org.apache.maven.plugins
maven surefire插件
2.13
我在我的机器上测试了它,它工作正常,请告诉我它是否适合您使用以下代码更新您的CleanSubmissionTest.java文件
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ClearSubmissionTest{
public WebDriver driver;
String baseUrlAdmin = "http://www.google.pl/";
@BeforeTest
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
@Test
public void Testno1() throws Exception {
driver.get(baseUrlAdmin);
Thread.sleep(5000);
}
@AfterTest
public void tearDown() throws Exception {
driver.close();
}
}
如果您仍然面临任何问题,请使用以下代码更新您的依赖项和插件,然后重试
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.github.yev</groupId>
<artifactId>screenshot</artifactId>
<version>0.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
</plugin>
</plugins>
</pluginManagement>
</build>
org.testng
testng
6.9.10
org.seleniumhq.selenium
硒爪哇
3.3.0
org.seleniumhq.selenium
selenium firefox驱动程序
3.3.1
com.github.yev
截图
0.2
org.codehaus.mojo
execmaven插件
1.2.1
JAVA
org.apache.maven.plugins
maven surefire插件
2.13
我在我的机器上测试了它,工作正常,让我知道它是否适合你在插件和检查之前,你能在build标签中剪切和粘贴依赖项吗?当然。现在依赖项在build标记中,但我得到一个错误cvc复杂类型。2.4.a:发现以元素“dependencies”开头的无效内容。“{”之一http://maven.apache.org/POM/4.0.0:sourceDirectory,“http://maven.apache.org/POM/ 4.0.0“:scriptSourceDirectory,”http://maven.apache.org/POM/4.0.0“:testSourceDirectory(…)”应为。
(我需要剪切整个消息,太长了)。我试图将其放入
标记中,但它并没有改变错误消息My bad,我从未查看过nullpointerexception,将依赖项还原到原始位置您可以在插件之前剪切并粘贴build标记中的依赖项并检查吗?当然。现在依赖项位于build标记中,但我遇到了一个错误cvc complex-类型.2.4.a:找到以元素“dependencies”开头的无效内容。“{”http://maven.apache.org/POM/4.0.0:sourceDirectory,“http://maven.apache.org/POM/ 4.0.0“:scriptSourceDirectory,”http://maven.apache.org/POM/4.0.0“:testSourceDirectory(…)”应为。
(我需要剪切整个消息,太长了)。我试图将它放在
标记中,但它没有改变错误消息My bad,我从未查看过nullpointerexception,将依赖项还原到原始位置。如果您描述了您所更改的内容,那么OP和其他读者就不必逐行查看您所更改的内容。哈,这很有效,谢谢!我可以看到,在pom中有一个问题:)对于其他读者,我在应用代码后也遇到了一个gecko错误,解决方法可以在这里找到:如果你描述了你所做的更改,那么OP和其他读者就不必逐行查看你所做的更改了。哈,这很有效,谢谢!我可以在pom中看到这一点作为一个问题:)对于其他读者,我在应用该代码后也遇到了一个gecko错误,解决方法可以在这里找到:我一直认为这种错误不应该停止整个过程…我现在可以看到Eclipse将这一行显示为警告。感谢您的回答:)我一直认为这种错误不应该停止整个过程…我现在可以看到Eclipse将这一行显示为警告。谢谢您的回答:)