Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Jonathan GrieveTreehouse Moderator 90,845 Points
Environment 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 :)
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?
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
Brian Haucke13,717 Points
I 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.