2017-03-25 3 views
0

TestNGとJava Seleniumを使用しない場合はすべていいです。 Java SeleniumでTestNGを使用すると、このエラーが発生します。TestNG Selenium Java - java.lang.IllegalStateException:webdriver.chrome.driverシステムプロパティによってドライバの実行可能ファイルへのパスを設定する必要があります。

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html 

ドライバに実行可能なパスを既に設定していますが、コンパイラはまだ文句を言います。なにか提案を?ありがとう。

package testSuite; 
 

 
import java.io.FileInputStream; 
 
import java.io.FileNotFoundException; 
 
import java.io.FileOutputStream; 
 
import java.io.IOException; 
 
import java.sql.Driver; 
 
import java.util.Properties; 
 

 
import org.openqa.selenium.WebDriver; 
 
import org.openqa.selenium.chrome.ChromeDriver; 
 
//import org.junit.Test; 
 
import org.testng.annotations.AfterMethod; 
 
import org.testng.annotations.AfterTest; 
 
import org.testng.annotations.BeforeMethod; 
 
import org.testng.annotations.BeforeSuite; 
 
import org.testng.annotations.BeforeTest; 
 
import org.testng.annotations.Test; 
 

 
public class testNG 
 
{ 
 
\t 
 
\t @Test 
 
\t public void login() throws IOException { 
 
\t \t System.setProperty("WebDriver.Chrome.Driver", "C:\\Users\\Desktop\\chromedriver_win32\\chromedriver.exe"); 
 
\t \t WebDriver driver = null; 
 
\t \t Properties prop = new Properties(); 
 
\t \t FileInputStream file = new FileInputStream("C:\\Users\\workspace\\Selenium\\src\\testSuite\\config.properties"); 
 
\t \t prop.load(file); 
 
\t \t 
 
\t \t System.out.println(prop.getProperty("username")); 
 
\t \t 
 
\t \t if(prop.getProperty("browser").equals("chrome")) { 
 
\t \t \t System.out.println("OKOK"); 
 
\t \t \t driver = new ChromeDriver(); 
 
\t \t \t 
 
\t \t } 
 
\t \t driver.get(prop.getProperty("url")); 
 
\t \t 
 
\t } 
 
    }

これは私の性質は、私は問題を発見した

username = 56987 
password = 1234 
url = www.google.com 
browser = chrome 
+0

私は今、チェックすることはできませんが、私の頭の上からそれはあなたが設定されていない方法ですドライバへのパス。なぜTestNGが機能しないのでしょうか? 'ChromeOptions'インスタンスを作成し、そのパスを設定し、そのインスタンスをドライバインスタンスに設定する必要があります。コンストラクタの引数として、またはセッタを介して覚えていません。 – SantiBailors

答えて

2

ファイルです。 小さな小さな間違い。

それは下ケースwebdriver.chrome.driver

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Desktop\\chromedriver_win32\\chromedriver.exe"); 

代わりの

System.setProperty("WebDriver.Chrome.Driver", "C:\\Users\\Desktop\\chromedriver_win32\\chromedriver.exe"); 

小文字または大文字に注意する必要がある必要があります。ありがとう。

+0

さらに、あなたのURLには 'http://' – kushal

1

パスをハードコードしないでください。

System.getProperty( "user.dir")を使用して、作業ディレクトリに直接移動することができます。

はい、webdriver.chrome.driverを小文字で使用してください。

System.setProperty("webdriver.chrome.driver", 
       System.getProperty("user.dir")+ "/chromedriver.exe"); 
1

コマンドラインからTestNGのスクリプトを実行している場合は、あなたが追加する必要があるかもしれません、次のSWITCH-

-Dwebdriver.chrome.driver=<path to chromedriver.exe>\chromedriver.exe 
関連する問題

 関連する問題