您好我想在Eclipse中使用Maven,TestNG運行Selenium腳本。 首先我右鍵單擊我的項目並選擇TestNG |轉換爲TestNG(創建testing.xml)。然後我轉到運行配置並創建一個新的啓動TestNGl並單擊運行。當運行它,我得到這個錯誤:FAILED CONFIGURATION:@BeforeTest beforeTest。 MAVEN; TestNG,硒
[RemoteTestNG]檢測TestNG的版本6.11.0 配置失敗:@BeforeTest beforeTest java.lang.IllegalStateException:到驅動程序可執行文件的路徑必須由webdriver.chrome設置。驅動系統屬性;有關更多信息,請參閱https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver。最新版本可從http://chromedriver.storage.googleapis.com/index.html 下載,位於com.google.common.base.Preconditions.checkState(Preconditions.java:754) ,位於org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) 在org.openqa.selenium.chrome.ChromeDriverService.access $ 000(ChromeDriverService.java:32) 在org.openqa.selenium.chrome.ChromeDriverService $ Builder.findDefaultExecutable(ChromeDriverService.java:137) 在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:2 7) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在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.TestR unner.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) 在org.testng.SuiteRunner.run(SuiteRunner.java:289) 在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 在org.testng.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) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemote TestNG.run(AbstractRemoteTestNG.java:114) 在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) 在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
脫機配置:@AfterTest afterTest 已跳過:f java.lang.IllegalStateException:驅動程序可執行文件的路徑必須由webdriver.chrome.driver系統屬性設置;有關更多信息,請參閱https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver。最新版本可從http://chromedriver.storage.googleapis.com/index.html 下載,位於com.google.common.base.Preconditions.checkState(Preconditions.java:754) ,位於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) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.jav一: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) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) at org.testng.TestRunner.beforeRun(TestRunner.java:626) at org.testng.TestRunner。運行(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) 在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 在org.testng.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) 在org.testng.TestNG.run(TestNG.java:1115) 在有機test.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
============================================== = 默認測試 試驗運行:1,故障:0,跳過:1次
配置失敗:1,跳過:1
================== ============================= 默認套件 總測試運行:1,失敗:0,跳過:1
配置故障:1,跳過:1
我有以下代碼:
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();
}
}
而且下面的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>
我嘗試,但得到了同樣的錯誤:配置失敗:@BeforeTest beforeTest java.lang.IllegalStateException:到驅動程序可執行文件的路徑必須由webdriver.chrome.driver系統屬性設置; – EnislavMollov
String exePath =「/ Users/********/Downloads/chromedriver」Ur的路徑應該是chromedriver.exe ..參考syntx String exePath =「/ Users/******** /下載/ chromedriver/chromedriver.exe「; –
chromedriver不是* .exe文件。它說'Unix可執行文件' – EnislavMollov