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
}
}