Unable to load a file | Selenium Forum
M
Posted on 28/12/2015
Hi Ashis,
I am working on Module 42: Building framework with cucumber. When trying to load a file from OR property getting
"The method load(FileInputStream) is undefined for the type Properties. I have attached a screenshot.
Can you tell me what is the problem?

M
Replied on 29/12/2015

try something like this.

[code:2br3u3vg]
try
{
java.net.URL url = this.getClass().getResource("/some-resource.properties");

java.io.FileInputStream pin = new java.io.FileInputStream(url.getFile());

java.util.Properties props = new java.util.Properties();

props.load(pin);
}
catch(Exception ex)
{
ex.printStackTrace();
}
[/code:2br3u3vg]


M
Replied on 29/12/2015

I attached the whole project.
Now I am getting :
java.lang.NullPointerExceptionI am going toLoginURL on Mozilla

at com.qtpselenium.app.salesforce.util.WebConnector.<init>(WebConnector.java:34)
at com.qtpselenium.app.salesforce.login.LoginTest.<init>(LoginTest.java:11)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:38)
at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:30)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:35)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:38)
at cucumber.runtime.Runtime.runStep(Runtime.java:267)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:36)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:76)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:65)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:20)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:72)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:77)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:82)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Entering Loginusernamenadim_h2000@yahoo.com
Entering Loginpasspass@1234
clickin LoginButton
login--- success


M
Replied on 30/12/2015

there is no [color=#FF0000:9wdx08sq]some-resource.properties[/color:9wdx08sq]

hence its giving an null pointer exception.

Responsive image

M
Replied on 02/01/2016

so what should it be. That's what you told me


M
Replied on 03/01/2016

i got answer to the original error.

[color=#FF0000:2pavl27x]method load file input stream is undefined.[/color:2pavl27x]


there is problem is you're importing wrong class don't import this class

[quote:2pavl27x]import com.sun.xml.internal.fastinfoset.sax.Properties;
[/quote:2pavl27x]


use this one
[quote:2pavl27x]import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;


public class WebConnector {
//initialize properties file



//logging


//selenium layers- Selenium commands
//three layers: Feature files, Steps, WebConnertor

Properties OR = null;
Properties CONFIG = null;
public WebConnector()
{
if (OR==null)
//initialize OR

try

{
OR =new Properties();
FileInputStream fs =new FileInputStream(System.getProperty("user.dir")+ "//src//main//java//com//qtpselenium//app//salesforce//config//OR.properties");
OR.load(fs);
}

catch(Exception ex)
{
ex.printStackTrace();
}[/quote:2pavl27x]