Selenium webdriver Selenium Web驱动程序属性文件读取

Selenium webdriver Selenium Web驱动程序属性文件读取,selenium-webdriver,webdriver,Selenium Webdriver,Webdriver,我有一个属性文件,其中存储了IE驱动程序的路径 编写一个类文件来读取路径和控制台中的打印 我有另一个包,在@before方法中运行浏览器 System.getProperty("SelfConfig.Properties","pathname") 或 我的主要意图是,在从属性文件调用方法之前,我不想硬编码路径 我是新手,请帮忙解决 问候 abdul我创建了一个文件readproperties.java文件,并添加了以下代码props=newproperties(); FileInputStre

我有一个属性文件,其中存储了IE驱动程序的路径

编写一个类文件来读取路径和控制台中的打印

我有另一个包,在@before方法中运行浏览器

System.getProperty("SelfConfig.Properties","pathname")

我的主要意图是,在从属性文件调用方法之前,我不想硬编码路径

我是新手,请帮忙解决

问候
abdul

我创建了一个文件readproperties.java文件,并添加了以下代码props=newproperties(); FileInputStream fis=新的FileInputStream(“c:/systemconfig.properties”)


我可以建议您使用下一个属性阅读器

public class PropReader
{
    private static Properties propertyFile;
    private static String propertyFilename = "./src/main/resources/testdata.properties";
    public static String getStringPropValue(String key)
    {
        Properties prop = new Properties();
        InputStream input = null;
        String result = "";
        try
        {
            prop.load(new FileInputStream(propertyFilename));
            result = prop.getProperty(key);
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            if (input != null)
            {
                try
                {
                    input.close();
                }
                catch (IOException e)
                {
                    //Reporter.log("Error while reading config: " + e.getMessage(), 2, true);
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
}

我创建了一个readproperties.java文件,并添加了以下代码props=newproperties();FileInputStream fis=新的FileInputStream(“c:/jdbc.properties”)//从属性文件props.load(fis)加载属性;System.setProperty(“webdriver.ie.driver”,路径名)driver=newInternetExplorerDriver();无法解析给定IE驱动程序pathname=“c://IE.exe路径但在@beforetest props中仍不工作的属性文件
    //Reading properties file in Java example
    Properties props = new Properties();
    FileInputStream fis = new FileInputStream("c:/jdbc.properties");

    //loading properites from properties file
    props.load(fis);

    //reading proeprty
    String pathname = props.getProperty("jdbc.pathname");

    System.setProperty("webdriver.ie.driver",pathname)

    driver = new InternetExplorerDriver();
//loading properites from properties file
props.load(fis);   ......................................................................i have another jave file calling @beforetest for browser and given this                                                             String pathname = props.getProperty("jdbc.pathname");

System.setProperty("webdriver.ie.driver",pathname)

driver = new InternetExplorerDriver();    property file given the path of the IE Driver pathname ="c://IE.exe but not working still in @beforetest props cannot be resolved  
public class PropReader
{
    private static Properties propertyFile;
    private static String propertyFilename = "./src/main/resources/testdata.properties";
    public static String getStringPropValue(String key)
    {
        Properties prop = new Properties();
        InputStream input = null;
        String result = "";
        try
        {
            prop.load(new FileInputStream(propertyFilename));
            result = prop.getProperty(key);
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            if (input != null)
            {
                try
                {
                    input.close();
                }
                catch (IOException e)
                {
                    //Reporter.log("Error while reading config: " + e.getMessage(), 2, true);
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
}