Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 我们是否需要在每次创建新类时将webdriver路径添加到pom文件中_Selenium - Fatal编程技术网

Selenium 我们是否需要在每次创建新类时将webdriver路径添加到pom文件中

Selenium 我们是否需要在每次创建新类时将webdriver路径添加到pom文件中,selenium,Selenium,我已经创建了一个新类并在那里添加了这一部分,但是我得到了一个错误。同一个片段在另一个类上运行 package BeginnerPrograms; import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.WebDriverManager; public class WebLocators { public static void main(String[] args) {

我已经创建了一个新类并在那里添加了这一部分,但是我得到了一个错误。同一个片段在另一个类上运行

package BeginnerPrograms;

import org.openqa.selenium.chrome.ChromeDriver;

import io.github.bonigarcia.wdm.WebDriverManager;


public class WebLocators {

    public static void main(String[] args) {
        ChromeDriver driver = new ChromeDriver();   
        driver.get("http://www.developer.salesforce.com/signup");

    }

}

收到错误:
必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径

否,您不需要将
WebDriver
路径添加到POM文件中

如果您正在使用TestNG或在您的
TestBase
类中,只需在
@BeforeSuite
中声明

并在任何地方使用driver实例

TestNG示例:

@BeforeSuite
public void setUpSuite() { 
System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe")
}
public class TestBase{
  
    public TestBase(){
       System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe")
       //Your other constructor stuff here.  
      }
  }
仅Java示例:

@BeforeSuite
public void setUpSuite() { 
System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe")
}
public class TestBase{
  
    public TestBase(){
       System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe")
       //Your other constructor stuff here.  
      }
  }
在您的
TestClass
中,按如下方式使用它:

public class TestClass extends TestBase{

public void someTestMethod(){
   new TestBase();
//proceed with your test case here
}
}