javascript - How to make a globally accessible variable? -
How do I create globally accessible variables in nightwatch.js? I'm using a variable to store an optimized URL (depending on which store is loaded in our online product), but I need it to be accessible in many JavaScript functions. Despite the declaration of the function at the top of the file, it reset after each function is exhausted.
ever since you asked your question and from whatever time you requested (originally From) could not be available. now it's.
Developer's Guide provides two ways to create global variables accessible from any trial based on your requirements. See for good reading. Method 1: In fact, for global globals, define the object in the "globals_path" section of your Nightwatch.json file, or pass a file for all trials and all environments, that is
"globals_path": "./lib/globals.js",
You have to export the variable, however, brushing on the node is a good The idea is. Here is a basic globals.js file example:
var userNames = {basicAuth: 'chicken', clientEmail: 'SaddenedSnail@domain.com', administrator email: 'admin@domain.com' ,}; Module.exports = {username: username}
This object / file will be used for all of your tests, no matter the environment, unless you Do not specify a different file / object below seen in method 2.
To access variables from your test suite, use the mandatory browser / client variables needed for every function (test), that is:
'account login ': Function accLogin (client) {var user = client.globals.userNames.clientEmail; Client Url (yourUrl) WaitForElementVisible ('yourUserNameField', 1000) .setValue ('yourUserNameField', user) .end (); }
Method 2: For environmental-based globals, which varies according to the environment you specify. Define an object, or pass a file, its nighttime. In the "Globals" section of the JSON file, nested under their required surroundings. "Local_ost": "http: // localhost", "selenium_port": 4444, "selenium_host": "localhost", "globals" Please note that at the time of writing, there is a bug in the night time and thus does not pass a file using method 2. {2} Work (at least in my environment) can be found for more information about bugs.
Comments
Post a Comment