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.

Quality Assurance Introduction to Selenium Test Drive Selenium More Locator Strategies

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse 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 :)

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
andren
28,526 Points

The 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
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 90,845 Points

Hi 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 :)

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Worst case scenario, just paste your URL in there ;)

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 90,845 Points

Hi 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
Jonathan Grieve
Treehouse Moderator 90,845 Points

Let 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
Craig Dennis
Treehouse Teacher

Yeah... 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.

Brian Haucke
Brian Haucke
13,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.