【问题标题】:Multiple program execution in selenium webdriver is not workingselenium webdriver中的多个程序执行不起作用
【发布时间】: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
===============================================

【问题讨论】:

标签: java selenium-webdriver testng


【解决方案1】:

从您的 xml 文件中删除以下行。因为你的 Class NewTest2 extends NewTest 所以,这里不用写了。

<class name="testng1.NewTest"/>

用这个替换你的 xml 文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite guice-stage="DEVELOPMENT" name="Test">
 <test verbose="2" name="Dummy">    
    <classes>
             <class name="testng1.NewTest2"/> 
    </classes>
 </test> 
</suite>

IE Browser 中执行您的脚本之前,请更正这些设置。

转到设置 -> Internet 选项 -> 安全选项卡 -> 设置此选项 为所有四个区域启用。 (启用保护模式)

请参阅下图以更改此设置。

你的执行代码会是这样的。

执行:- 如果您在 xml 文件上运行,您的代码将以这种方式执行。

1) 测试前方法
2) 邮箱
3) 雅虎
4) 后测方法

【讨论】:

  • 嗨 Janish,是的,我试过了。但还是一样的结果。 GMAIL 正在运行两次
  • 尝试通过xml文件运行你的脚本。
  • 做到了..但结果相同。一些我缺少逻辑的地方
  • 请请求您将您的 xml 文件替换为 my 并尝试使用 xml 文件运行您的测试用例。它肯定会为你工作。 :)
  • 您好,我的代码已经完成,我也更新了我的答案。请检查我的答案并更新我。现在我的脚本可以在所有浏览器中运行。
猜你喜欢
  • 2012-04-22
  • 2019-06-14
  • 2021-11-21
  • 2013-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-29
  • 2018-01-22
相关资源
最近更新 更多