Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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
Java 声明属性文件并初始化类中的Webdriver对象。我想在同一个包或其他包中使用此Webdriver对象_Java_Webdriver_Selenium Webdriver - Fatal编程技术网

Java 声明属性文件并初始化类中的Webdriver对象。我想在同一个包或其他包中使用此Webdriver对象

Java 声明属性文件并初始化类中的Webdriver对象。我想在同一个包或其他包中使用此Webdriver对象,java,webdriver,selenium-webdriver,Java,Webdriver,Selenium Webdriver,我已经在一个类中声明了属性文件并初始化了Webdriver对象。现在我想在同一个包或其他包中的任何地方使用这个Webdriver对象。怎么做 请查找以下代码: public class Config { public static Properties config =null; public static Properties OR = null; public static WebDriver driver = null ; public static Logger APPLICATION_

我已经在一个类中声明了属性文件并初始化了Webdriver对象。现在我想在同一个包或其他包中的任何地方使用这个Webdriver对象。怎么做

请查找以下代码:

public class Config
{
public static Properties config =null;
public static Properties OR = null;
public static WebDriver driver = null ;
public static Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");

@SuppressWarnings("unused")
public void initialization() throws IOException
{
    // creating properties files storing the ID's and xpaths
    APPLICATION_LOGS.debug("Starting the test suite");
    APPLICATION_LOGS.debug("Loading config files");
    config = new Properties();
    //FileInputStream fp = new FileInputStream("./config.properties");
    FileInputStream fp = new FileInputStream(System.getProperty("user.dir")+"\\src\\com\\ode\\utility\\config.properties");
    config.load(fp);
    APPLICATION_LOGS.debug("Loading Object XPATHS");
    OR = new Properties();
    //FileInputStream fp1 = new FileInputStream("./OR.properties");
    FileInputStream fp1 = new FileInputStream(System.getProperty("user.dir")+"\\src\\com\\ode\\utility\\OR.properties");
    OR.load(fp1);

    APPLICATION_LOGS.debug("Starting the driver");
    driver = new InternetExplorerDriver();

    driver.get(config.getProperty("Testwebsite"));
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
}
我不知道怎么用这个。。。帮我解决这个问题


非常感谢您的帮助。

因为您可能会在相同和不同的包中的不同类中使用驱动程序,那么在一个类中初始化驱动程序怎么样?无论哪个类需要驱动程序,只要扩展该类,这样当测试用例运行访问不同类中的不同方法时,这里会使用相同的驱动程序参考吗

public class A {

public static WebDriver driver = new ......();

}

public class B extends A {
  //members and attributes of class B
}

public class C extends A {
  //members and attributes of class C

}

在我正在开发的测试框架中,我所做的是创建了基类:

BasePage.java
BaseTest.java
BaseElement.java


以及初始化BaseTest类中的webdriver对象。我遵循PageObject模式。因此,我创建的任何pageobject类都会扩展其中的BasePage类。我编写的任何测试类(带注释的TestNG测试方法)都会扩展BaseTest类。因此,在BaseTest类中初始化的驱动程序对象可以通过其构造函数在子类以及PageObject类中传递。那就行了。

谢谢你的回复Sotirios。谢谢你的回复。将尝试