2017-02-02 44 views
1

我是相當新的SeleniumTestNG所以請與我裸露...... 我收到以下錯誤,當我試圖運行我的腳本org.testng.TestNGException:無法實例

org.testng.TestNGException:無法實例類產生的原因: java.lang.reflect.InvocationTargetException產生的原因: java.lang.IllegalStateException:到驅動程序可執行文件的路徑 必須由webdriver.ie.driver系統設置屬性;

package EDRTermsPackge; 

import org.testng.annotations.Test; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.Keys; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.ie.InternetExplorerDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 
import org.testng.annotations.BeforeClass; 
import org.testng.annotations.BeforeMethod; 

public class ContactInformationTesting { 

//For use of IE only; Please enable for IE Browser 
WebDriver driver = new InternetExplorerDriver(); 

@BeforeMethod 
public void beforeMethod() { 
    //Using or Launching Internet Explorer 
    String exePath = "\\Users\\jj85274\\Desktop\\IEDriverServer.exe"; 

    //For use of IE only; Please enable for IE Browser 
    System.setProperty("webdriver.ie.driver", exePath); 
} 

@Test 
public void OpenPage_Login() { 
    driver.get("http://cp-qa.harriscomputer.com/"); 
} 
} 
+1

請把你的代碼的輸出中列出的目錄之一做到這一點在Windows – acikojevic

+0

剛剛發佈我的代碼。謝謝 –

+1

@JJWhispers - 我相信你應該更新你的問題的源代碼,而不是發佈代碼作爲你自己的問題的答案之一。我編輯了你的問題,包括你共享的源代碼(我清理了註釋掉代碼) –

回答

2

你應該首先設置爲驅動的路徑,然後實例IEDriver,您不能使用new InternetExplorerDriver();System.setProperty("webdriver.ie.driver", exePath);

在你的情況,你可以做這樣的事情(無需@BeforeMethod到做如此簡單的屬性設置):

public class ContactInformationTesting { 

    //Using or Launching Internet Explorer 
    String exePath = "\\Users\\jj85274\\Desktop\\IEDriverServer.exe"; 

    //For use of IE only; Please enable for IE Browser 
    System.setProperty("webdriver.ie.driver", exePath); 

    //For use of IE only; Please enable for IE Browser 
    WebDriver driver = new InternetExplorerDriver(); 

@Test 
public void OpenPage_Login() { 
    driver.get("http://cp-qa.harriscomputer.com/"); 
} 
+0

您應該添加修復問題的代碼。 – juherr

+0

進出口收到此錯誤消息的變化對令牌 語法錯誤結果,刪除這些令牌 –

+0

公共類ContactInformationTesting { \t \t //使用或啓動Internet Explorer的 \t字符串exePath =「\\ \\用戶jj85274 \\ \\桌面IEDriverServer.exe「; \t \t System.setProperty(「webdriver.ie.driver」,exePath); //僅限使用IE;請啓用IE瀏覽器 \t \t WebDriver driver = new InternetExplorerDriver(); //僅限使用IE;請啓用IE瀏覽器 \t @Test 公共無效OpenPage_Login(){ \t \t driver.get(「HTTP://cp-qa.harriscomputer。COM /「);} –

0

字符串exePath = 「\用戶\ jj85274 \桌面\ IEDriverServer.exe」;

這行提示就好像您試圖從網絡驅動器設置IEDriverServer二進制文件。是這樣嗎 ?我不確定是否可以直接通過Java代碼訪問網絡路徑。

我建議您不要試圖在您的源代碼中爲每個測試添加IEDriverServer.exe路徑,而應該在您的PATH變量中包含此二進制文件。您可以通過刪除此exe成在下面的命令

在Windows echo %PATH%

在非Windows echo $PATH