This forum is in archive mode. You will not be able to post new content.

Author Topic: Javascript to read from a text file and save to variable - code not working  (Read 570 times)

0 Members and 1 Guest are viewing this topic.

Offline sc13nt1st

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 0
    • View Profile
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?

Code: [Select]
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?

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
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.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.