[英]FAILED CONFIGURATION: @BeforeTest beforeTest . MAVEN; TestNG, Selenium
Hi I'm trying to run Selenium script with Maven, TestNG in Eclipse.嗨,我正在尝试使用 Maven 和 TestNG 在 Eclipse 中运行 Selenium 脚本。 First I right click on my project and select TestNG |
首先,我右键单击我的项目并选择 TestNG | Convert to TestNG(testing.xml is created).
转换为TestNG(创建testing.xml)。 Then I go to the Run Configurations and create a new launch TestNGl and click Run.
然后我转到运行配置并创建一个新的启动 TestNGl 并单击运行。 When run it I got this error:
运行它时,我收到此错误:
[RemoteTestNG] detected TestNG version 6.11.0 FAILED CONFIGURATION: @BeforeTest beforeTest java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; [RemoteTestNG] 检测到 TestNG 版本 6.11.0 失败配置:@BeforeTest beforeTest java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver .
有关更多信息,请参阅https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver 。 The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:754) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at test.java.NewTest.beforeTest(NewTest.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
最新版本可以从http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:754) at org.openqa.selenium.remote 下载。 service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java) :137) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329) 在 org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) 在 org.openqa。 selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at test.java.NewTest.beforeTest(NewTest.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl) .java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) at org.testng.TestRunner.beforeRun(TestRunner.java:626) at org.testng.TestRunner.run(TestRunner.java:594) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org
在 java.lang.reflect.Method.invoke(Method.java:498) 在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) 在 org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) ) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) 在 org.testng.TestRunner.beforeRun(TestRunner.java:626)在 org.testng.TestRunner.run(TestRunner.java:594) 在 org.testng.SuiteRunner.runTest(SuiteRunner.java:380) 在 org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) 在 org.testng。 SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.run(SuiteRunnerWorker) .java:86) 在 org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) 在 org.testng.TestNG.runSuitesLocally(TestNG.java:1226) 在 org.testng.TestNG.runSuites(TestNG.java:1144)在组织.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org. testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
SKIPPED CONFIGURATION: @AfterTest afterTest SKIPPED: f java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;跳过配置:@AfterTest afterTest 跳过:f java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver .
有关更多信息,请参阅https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver 。 The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:754) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at test.java.NewTest.beforeTest(NewTest.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
最新版本可以从http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:754) at org.openqa.selenium.remote 下载。 service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java) :137) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329) 在 org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) 在 org.openqa。 selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at test.java.NewTest.beforeTest(NewTest.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl) .java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) at org.testng.TestRunner.beforeRun(TestRunner.java:626) at org.testng.TestRunner.run(TestRunner.java:594) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org
在 java.lang.reflect.Method.invoke(Method.java:498) 在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) 在 org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) ) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) 在 org.testng.TestRunner.beforeRun(TestRunner.java:626)在 org.testng.TestRunner.run(TestRunner.java:594) 在 org.testng.SuiteRunner.runTest(SuiteRunner.java:380) 在 org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) 在 org.testng。 SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.run(SuiteRunnerWorker) .java:86) 在 org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) 在 org.testng.TestNG.runSuitesLocally(TestNG.java:1226) 在 org.testng.TestNG.runSuites(TestNG.java:1144)在组织.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org. testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
=============================================== Default test Tests run: 1, Failures: 0, Skips: 1 ============================================== 默认测试 测试运行:1,失败:0,跳过:1
=============================================== Default suite Total tests run: 1, Failures: 0, Skips: 1 ================================================ 默认套件总数测试运行:1,失败:0,跳过:1
I have the following code:我有以下代码:
package test.java;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import junit.framework.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class NewTest {
private WebDriver driver;
@Test
public void f() {
// TODO Auto-generated method stub
String exePath = "/Users/********/Downloads/chromedriver";
System.setProperty("webdriver.chrome.driver", exePath);
//WebDriver driver = new ChromeDriver();
driver.get("https://www.apple.com/");
String title = driver.getTitle();
Assert.assertTrue(title.contains("Apple"));
}
@BeforeTest
public void beforeTest() {
driver = new ChromeDriver();
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
And following 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
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TestMaven</groupId>
<artifactId>TestMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</dependency>
</dependencies>
</project>
You need to set property in @beforeTest method bec.您需要在 @beforeTest 方法 bec 中设置属性。 it will run before @Test.
它将在@Test 之前运行。
In your case you are trying to create driver instance before setting it property.在您的情况下,您尝试在设置其属性之前创建驱动程序实例。
Try below code :-试试下面的代码:-
@BeforeTest
public void beforeTest() {
String exePath = "/Users/********/Downloads/chromedriver/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
driver = new ChromeDriver();
}
package test.java;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import junit.framework.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class NewTest {
private WebDriver driver;
@Test
public void f() {
driver.get("https://www.apple.com/");
String title = driver.getTitle();
Assert.assertTrue(title.contains("Apple"));
}
@BeforeTest
public void beforeTest() {
String exePath = "/Users/********/Downloads/chromedriver/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
driver = new ChromeDriver();
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
Hi I'm trying to run Selenium script with Maven, TestNG in Eclipse.I got stuck as i got the below error: [RemoteTestNG] detected TestNG version 6.11.0 FAILED CONFIGURATION: @BeforeMethod setup java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; 嗨,我正在尝试在Eclipse中使用Maven,TestNG运行Selenium脚本。由于出现以下错误,我被卡住了:[RemoteTestNG]检测到TestNG版本6.11.0失败:@BeforeMethod setup java.lang.IllegalStateException:的路径驱动程序可执行文件必须由webdriver.chrome.driver系统属性设置; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver .
有关更多信息,请参见https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver 。 The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
可以从http://chromedriver.storage.googleapis.com/index.html下载最新版本。
TestCase is:
package com.amazon.qa.testcases;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.amazon.qa.base.TestBase;
import com.amazon.qa.pages.LoginPage;
public class LoginTest extends TestBase{
LoginPage loginpage;
public LoginTest() {
super();
}
@BeforeMethod
public void setup()
{
initialization();
loginpage=new LoginPage();
}
@Test(priority=1)
public void loginPageTitle()
{
String title=loginpage.ValidateLoginPageTitle();
Assert.assertEquals(title, "Amazon.com:Online shopping");
}
@Test(priority=2)
public void loginTest()
{
loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
}
@AfterMethod
public void teardown()
{
driver.quit();
}
}
POM file:
<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>AmazonTestAutomation</groupId>
<artifactId>AmazonTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AmazonTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.5</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.141.5</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16-beta2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>openxml4j</artifactId>
<version>1.0-beta</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>openxml4j</artifactId>
<version>1.0-beta</version>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.30</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>
Worked for me when i removed .exe
extension from the path.当我从路径中删除
.exe
扩展名时为我工作。 For example:例如:
System.setProperty("webdriver.chrome.driver", "/Users/***/***/chromedriver");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.