EvilZone

Programming and Scripting => Web Oriented Coding => : sc13nt1st May 14, 2014, 07:17:33 AM

: Javascript to read from a text file and save to variable - code not working
: sc13nt1st May 14, 2014, 07:17:33 AM
Hey all  ;D

Man javascript is something else!

I am writing web app tests using selenium and I am planning on having a text file that has information. Is it possible for javascript to read from a text file and take the information ex. usernames and passwords and save it to a variable that can be used in a test?

:
import System.IO;
var file = "info.txt";

function Start () {

    var sr = new StreamReader(Application.dataPath + "/" + file);
    var fileContents = sr.ReadToEnd();
    sr.Close();

    var mydata = fileContents.Split("\n"[0]);
}

Is my code correct and am I heading in the right direction?
: Re: Javascript to read from a text file and save to variable - code not working
: kenjoe41 May 17, 2014, 11:56:44 PM
I don't do javascript but the programmer in me thinks it might not be wise to close that text file before all you need to do with the file is done. I mean, what if the txt file is pretty huge and not all of it can be copied into your var at once, since you don't have a loop, you end up loosing some data.
I might be wrong if javascipt implements its things differently.