New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment: custom variables #85
Comments
you can have different environment settings in your nightwatch.json. Does is not fit your needs ? regards |
I think @vinogradoff is referring to having properties defined in your test_settings available inside the test. What you need is the In your test refer to is as |
That almost surely does fit but I need a hint how to use it :-). "test_settings" : { How can I reference it from my test script main_page.js? starting ./nightwatch -e <staging | default> |
@beatfactor cool! it is working fine, I think the docs were not so obvious at this place, that you might just get client.launch_url resp. browser.launch_url as string :-) |
tested. looks like only launch_url is explicitly wired. Perhaps a Bag with custom variables as improvement? |
I'm not programming seriously since a few years, but could it be that
And config like:
And call like:
Not? |
@beatfactor I talk about it in https://github.com/beatfactor/nightwatch/issues/86, but there used to be support for custom environment variables before v0.4.1 by calling the You could specify custom, environment specific variables in The |
thanks @dmarquezz, I must admit, I am cowardly using 0.3, as it worked so fine for me :-) @beatfactor have I already told you, that nightwatchJS is just brilliant? Thank you! |
@vinogradoff thanks a lot! |
@vinogradoff you're right, Nightwatch is pretty awesome. @beatfactor thanks a lot. that will be really useful. |
@vinogradoff that's close enough (i.e. your code example). |
I've added support for a "globals" property. It can be defined either inside the test_settings environment or on the top level as an external module, as seen in the sample nightwatch.json: "saucelabs" : {
...
"globals" : {
"myGlobal" : "some_sauce_global"
}
}, or ...
"globals" : "./examples/globals.json" |
can i close this? |
Looks good. How do you include the globalModules.js instead of the globals.json? |
the same way. |
Got it working. super wonderful awesomeness. |
Hi guys, |
what about sharing the setup that doesn't work for you? |
I try added and use client.options.custom_vars.myuser but TypeError: Cannot read property "custom_vars" or undefined |
@apanashchenko Did you read this.. ? |
Hey sorry to boot up an old thread, but I am having trouble. I have read and re-read the docs - not sure what is going on. In my nightwatch.json I have this:
However, when calling this at the start of a test:
I always get an empty object. Going any deeper (i,e. client.globals.userName), unsurprisingly, returns undefined. Why wouldn't this work? Any help is really appreciated. Thanks to all. |
Of course, the moment I post this, I get it to work. If listing it under the "globals" section (under "test_settings") it will silently fail to properly find the globals.js file. No error is thrown (i.e. nothing about not being able to locate the globals.js file appears in the debug output) and Hopefully this helps future nightwatch users... if specifying a file, and not an object, to use globally throughout your tests ensure it is listed under "globals_path" and not "globals". |
Hi, I have more then 1 user and respective password. e.g. user1 / tester, user2 / tester, user3/tester etc. and I am expecting my script should run against all user. I will go for this? |
Is it possible to load |
+1 |
Since I'm not the only one who found this issue by googling "nightwatch environment variables", I will share how I managed to get dotenv secrets loaded in my nightwatch configuration.
...
"globals_path" : "globals.js"
...
module.exports = {
before: function(done){
require('dotenv').config();
done();
}
}
Add node-dotenv to the project with Now the secret code is available within my test suite with |
What if you have different variables for different environments?
…On Tue, Apr 4, 2017 at 4:01 PM, Bob Bolender ***@***.***> wrote:
Since I'm not the only one who found this issue by googling "nightwatch
environment variables", I will share how I managed to get dotenv secrets
loaded in my nightwatch configuration.
nightwatch.json
..."globals_path" : "globals.js"...
globals.js
module.exports = {
before: function(done){
require('dotenv').config();
done();
}
}
.env
SECRET_CODE=1234
Add node-dotenv to the project with npm install dotenv.
Now the secret code is available within my test suite with
process.env.SECRET_CODE
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#85 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEaHvItjFKlJjQwj_k5XpFE1gmrzqc19ks5rsq-jgaJpZM4BqUqZ>
.
--
Thanks!
*Manjunath Dharamadas (MG)* | Sr. Quality Engineer
c: 309.530.1825
301 Congress Avenue, Suite 700, Austin, Texas 78701
Austin | Hoboken | Phoenix | London | Paris | Vannes
*RetailMeNot is the first shopping app to earn the Good Housekeeping Seal!*
--
This e-mail, including attachments, contains confidential and/or
proprietary information, and may be used only by the person or entity to
which it is addressed. The reader is hereby notified that any
dissemination, distribution or copying of this e-mail is prohibited. If you
have received this e-mail in error, please notify the sender by replying to
this message and delete this e-mail immediately.
|
I am using nearly the same setup as @awesomebob, with one slight difference - I added the following:
To my
As for loading different variables for different environments, you will need to load all of your conditions under one |
`var self = module.exports = {
}` And then using adminPassword in a test: gives me undefined testEnvironment |
Is there a way to put (and read) some custom variables in environment part of settings.json?
For example, you would like to have different test-site urls for production and staging.
The text was updated successfully, but these errors were encountered: