2017-09-15 86 views
1

在Selenium WebDriver中執行多個程序不起作用。我寫了一個testNG xml文件和2個java類。我試圖從xml文件中運行這兩個java類。但它不起作用。在selenium webdriver中執行多個程序不起作用

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」:

當我跑了使用XML文件testng,我收到下面的錯誤信息:

錯誤消息:

失敗配置:@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) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) at org.openqa.selenium.ie.InternetExplorerDriv呃。(InternetExplorerDriver.java:210) 在org.openqa.selenium.ie.InternetExplorerDriver。(InternetExplorerDriver.java:154) 在testng1.NewTest.launch(NewTest.java:13) 在sun.reflect.NativeMethodAccessorImpl。 invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(方法.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) 在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) 在有機testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocall y(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG。java:1144) at 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) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) at org.openqa.selenium.ie.InternetExplorerDriv呃。(InternetExplorerDriver.java:210) 在org.openqa.selenium.ie.InternetExplorerDriver。(InternetExplorerDriver.java:154) 在testng1.NewTest.launch(NewTest.java:13) 在sun.reflect.NativeMethodAccessorImpl。 invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(方法.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) 在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) 在有機testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocall y(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG。運行(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) at org.openqa.selenium.ie.InternetExplorerDriverService.access $ 000(InternetExplorerDriverService。java:32) at org.openqa.selenium.ie.InternetExplorerDriverService $ Builder.findDefaultExecutable(InternetExplorerDriverService.java:167) at 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(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62 ) at sun.reflect.Delega tingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498) 在org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) 在有機testg.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) at 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) 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) 在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) at 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) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:288) at org.openqa.selenium.ie.InternetExplorerDriv呃。(InternetExplorerDriver.java:210) 在org.openqa.selenium.ie.InternetExplorerDriver。(InternetExplorerDriver.java:154) 在testng1.NewTest.launch(NewTest.java:13) 在sun.reflect.NativeMethodAccessorImpl。 invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(方法.java:498) at 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.runSuit E(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 
=============================================== 
+0

檢查了這一點後,https://stackoverflow.com/questions/34946478/how-to-set-路徑到可執行-IE-11驅動程序 –

+0

感謝蘇哈。現在的工作很好,但「Gmail的」方法獲取執行兩次。我不明白爲什麼? –

回答

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你的腳本之前,請糾正狄氏設置。

進入設置 - > Internet選項 - >安全選項卡 - >使此選項 啓用所有四個區域。 (啓用保護模式)

請參考下圖像來改變這種設置。

enter image description here

你執行的代碼會是這樣。

enter image description here

執行: - 如果你運行上面的XML文件,你的代碼將執行這個樣子。

1)在測試方法
2)的Gmail
3)雅虎
4)測試方法

+0

HI Janish,是的,我試過了。但還是同樣的結果。 Gmail是運行兩次 –

+0

嘗試通過xml文件來運行你的腳本。 –

+0

沒有it..but相同的結果。一些我在哪裏丟失邏輯 –

相關問題