Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Grieve
Treehouse Moderator 91,253 PointsEnvironment Variable not working
This a trifle bit annoying :)
So I'm trying to set up the workspace URL as the URL set to the environment variable. I'm on Windows 10 so I do this as directed in the teachers notes :)
set URL=http://port-80-rp3wn6drlh.treehouse-app.com
Then all that's left to do is copy the shared code into my Git Bash to see if it'll pick up the URL.
It doesn't actually do this. It'll simply open a blank instance of Chrome.
const selenium = require("selenium-webdriver");
const By = selenium.By;
const driver = new selenium.Builder().forBrowser("chrome").build();
driver.get(process.env.URL);
So if I copy this in it won't actually run the commands in the same order so at least one variable returns as undeclared.
I've also tried typing in the commands separately but what this does is return the URL as undefined. It doesn't seem to recognise the environment variable as string.
This is the error returned when typing in the commands separately
> WebDriverError: unknown error: 'url' must be a string
I wonder if this is a common problem for Windows and if there#s any workarounds?
3 Answers
andren
28,558 PointsThe set
command defines a temporary environment variable in CMD and Powershell, if you are using Git Bash then you can use the export
command instead which is the bash equivalent of set
.
Like this:
export URL=http://port-80-rp3wn6drlh.treehouse-app.com
Craig Dennis
Treehouse TeacherWorst case scenario, just paste your URL in there ;)
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi Craig,
You mean paste the URL into driver.get? :)
I don't mind admitting I'm confused about the process. Ive not seen yet how the commands are saved after I move out of REPL Maybe not understanding what's supposed to be happening :)
Jonathan Grieve
Treehouse Moderator 91,253 PointsLet me ask the question another way.
I've just tried pasting in the shared code to my Git Bash and this time it seemed to work. On mine, I have to press enter one more time for the driver.get()
command but that's okay.
What happens now? Are the commands only saved for the duration of the session in REPL? That would appear to be the case. I've just come out and back into REPL and retried the driver.get(process.env.URL);
and all I got was
ReferenceError: driver is not defined
at repl:1:1
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:440:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
at REPLServer.Interface._onLine (readline.js:279:10)
at REPLServer.Interface._line (readline.js:626:8)
So I've lost the command I stored in the driver
constant. Help! :O)
Craig Dennis
Treehouse TeacherYeah... I mean in your driver.get(...)
you can just paste in your workspace URL where I put ...
. In a few more videos we're going to move to save this into a file. Yes, each REPL is a new session, so you need to add the setup each time.
Jonathan Grieve
Treehouse Moderator 91,253 PointsUnderstood. Thanks Craig :)
Brian Haucke
13,717 PointsI ran into similar trouble with the environment variable not working correctly. When I tried it, driver.get(process.env.URL) would not bring up the webpage and I would have to set the URL as a variable in Node, then do driver.get(URL)
When I checked my Node version (node -v), it was the most recent version - 8.5.0. I had installed this previously for a separate project I was working on.
Looking at the Node website, it recommends most users use v6.x.x
I decided to try installing an earlier version of Node: v6.11.3.
Once I installed the older version, everything ran perfectly.
If you are running into similar issues, check what version of Node you have installed.
If you need to install an older version (like I did) I recommend Googling how to install an older version of Node.
Downgrading Node on my Mac was relatively simple (a few terminal commands and I was done), but it may be different depending on your computer / OS.
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsHi Adren,
Thanks for this, I can confirm this command does work when typing in the shared code line by line.
I think there's an issue with Git Bash which is causing the
driver.get(process.env.URL);
to not be read by bash.Anyway, I have at least a partial workaround so thanks :)