【发布时间】:2018-02-24 08:06:38
【问题描述】:
selenium WebDriver 中的多个程序执行不起作用。我编写了一个 testNG xml 文件和 2 个 java 类。我试图从 xml 文件中运行这两个 java 类。但它不起作用。
XML 代码:
<suite name="Suite">
<test name="SIT">
<classes>
<class name="testng1.NewTest"/>
<class name="testng1.NewTest2"/>
</classes>
</test>
</suite>
现在是“NewTest.java”类:
package testng1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class NewTest {
public static WebDriver driver;
@BeforeTest
public void launch()
{
System.setProperty("WebDriver.ie.driver", "C:\\Users\\rprem\\Downloads\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
System.out.println("BeforeTest Method");
}
@Test
public void gmail()
{
driver.get("https://gmail.com");
System.out.println("Gmail was launched");
}
@AfterTest
public void quit()
{
driver.quit();
System.out.println("AfterTest Method");
}
}
现在“NewTest2.java”:
package testng1;
import org.testng.annotations.Test;
public class NewTest2 extends NewTest
{
@Test
public void yahoo()
{
driver.get("https://yahoo.com");
System.out.println("yahoo site was opened");
}
}
当我使用 testng 运行 xml 文件时,我收到以下错误消息:
错误信息:
配置失败:@BeforeTest 启动 java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.ie.driver系统属性设置;更多 信息,见 https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver。 最新版本可以从 http://selenium-release.storage.googleapis.com/index.html 在 com.google.common.base.Preconditions.checkState(Preconditions.java:738) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) 在 org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32) 在 org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) 在 org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:210) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:154) 在 testng1.NewTest.launch(NewTest.java:13) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 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) 在 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) 在 org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) 在 org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) 在 org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
SKIPPED CONFIGURATION: @AfterTest quit SKIPPED: gmail java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more信息,见 https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver。 最新版本可以从 http://selenium-release.storage.googleapis.com/index.html 在 com.google.common.base.Preconditions.checkState(Preconditions.java:738) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) 在 org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32) 在 org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) 在 org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:210) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:154) 在 testng1.NewTest.launch(NewTest.java:13) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 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) 在 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) 在 org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) 在 org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) 在 org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
SKIPPED: gmail java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more信息,见 https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver。 最新版本可以从 http://selenium-release.storage.googleapis.com/index.html 在 com.google.common.base.Preconditions.checkState(Preconditions.java:738) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) 在 org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32) 在 org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) 在 org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:210) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:154) 在 testng1.NewTest.launch(NewTest.java:13) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 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) 在 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) 在 org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) 在 org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) 在 org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
SKIPPED: yahoo java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more信息,见 https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver。 最新版本可以从 http://selenium-release.storage.googleapis.com/index.html 在 com.google.common.base.Preconditions.checkState(Preconditions.java:738) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) 在 org.openqa.selenium.ie.InternetExplorerDriverService.access$000(InternetExplorerDriverService.java:32) 在 org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) 在 org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:210) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:154) 在 testng1.NewTest.launch(NewTest.java:13) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 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) 在 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) 在 org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) 在 org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) 在 org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
===============================================
testng1
Tests run: 3, Failures: 0, Skips: 3
Configuration Failures: 1, Skips: 1
===============================================
===============================================
practice by packages
Total tests run: 3, Failures: 0, Skips: 3
Configuration Failures: 1, Skips: 1
===============================================
【问题讨论】:
-
谢谢苏达。它现在工作正常,但“gmail”方法被执行了两次。我不明白为什么?
标签: java selenium-webdriver testng