试图将fileinputstream obj从函数传递到另一个函数

时间:2015-12-09 19:46:31

标签: java function selenium-webdriver fileinputstream

我想使用一个函数从属性文件中读取,而不是在不同的地方使用该文件的对象。到目前为止,我已经尝试过没有运气了。

public class all_the_functions 

 {
    public FileInputStream loadPropertiesFile(FileInputStream obj2) throws IOException
     {
       //reading from the properties file
       Properties obj = new Properties();
       FileInputStream fileobj = new FileInputStream("//Users//macuser//Desktop//selenium//project_Mat//input_properties.properties");
       obj.load(fileobj);
       return fileobj;  
     }
 }

而且在我的主要功能中,我使用以下代码

public class searchdynamic();
{
    FileInputStream Obj;
    all_the_functions func = new all_the_functions();
    func.loadPropertiesFile(Obj);     
    WebDriver driver = new FirefoxDriver();
    driver.navigate().to(Obj.getproperty("valid URL");
}

最终目标是阅读。输入文件使用该函数并对属性文件进行stroung,以便在需要从文件中读取时始终可以调用相同的函数。有人可以指点我在这里做错了吗。

感谢。

2 个答案:

答案 0 :(得分:0)

你能试试吗

public class searchdynamic();
{
    FileInputStream Obj;
    all_the_functions func = new all_the_functions();
    Obj=func.loadPropertiesFile(Obj);     
    WebDriver driver = new FirefoxDriver();
    driver.navigate().to(Obj.getproperty("valid URL");
}

答案 1 :(得分:0)

您的酒店返回的字符串是什么? " http://www ..."

理论上,这应该有用(虽然我习惯了webdriver是导航()。GoToUrl(字符串网址)。给那个镜头......

此外,关于这不是oop或编译的友好警告。以某种方式将属性与值绑定可能是一个好主意。我知道这是一个关键字驱动的框架,但更好的做法是让用户输入" Google"并将您的代码消化成类似

的内容

driver.Navigate().GoToUrl("http://google.com"); // (c#)

这样,您可以依靠正确的输入并适当地处理错误的输入。

无论如何,请尝试.Navigate()。GoToUrl()