selenium webdriver中的多个程序执行无效

时间:2017-09-15 07:46:00

标签: java selenium-webdriver testng

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>

现在&#34; NewTest.java&#34;类:

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");
}
}

现在&#34; NewTest2.java&#34; :

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文件时,出现以下错误消息:

错误讯息:

  

FAILED CONFIGURATION:@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)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)         at 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)         在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.run顺序(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)         at 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)         at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)         at 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)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)         at 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)         在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.run顺序(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)         at 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)         at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)         at 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)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)         at 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)         在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.run顺序(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)         at 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)         at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)         at 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)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)         at 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)         在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.run顺序(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)         at 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)         at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)         at 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
===============================================

1 个答案:

答案 0 :(得分:1)

xml文件中删除以下行。因为你的班级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内执行脚本之前,请更正这些设置。

  

转到设置 - &gt;互联网选项 - &gt;安全标签 - &gt;做这个选项   启用所有四个区域。 (启用保护模式)

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

enter image description here

您的执行代码将是这样的。

enter image description here

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

1)BeforeTest方法
2)Gmail
3)雅虎 4)AfterTest方法