please help me with implementing FluentWait using nightwatch.js
how can I use it??
in my project I have global.js containing:
waitForConditionPollInterval : 300,
waitForConditionTimeout : 5000,
but this is not FluentWait??
And the second question is how to use variables from global.js in test scripts ??
for example, if I have code like this:
this.typeLoginAndSubmit = function() {
browser
.waitForElementVisible(loginPageSelectors.loginField, 5000)
.setValue(loginPageSelectors.loginField, 'login')
.waitForElementVisible(loginPageSelectors.loginSubmit, 5000)
.click(loginPageSelectors.loginSubmit)
return browser;
the nightwatch methods like "waitForElementVisible" has forced me to give ms value ?? so how and when I can use global.js configuration??
You have to assign a variable to the js.
var global=require('global.js');
browser
.waitForElementVisible(loginPageSelectors.loginField, global.timeout);
or
just assign var timeout=5000; before all actions as the script you run is javascript
then use it
browser.waitForElementVisible(loginPageSelectors.loginField,timeout);
Related
i'm currently working on an extends script which is the technology that we can use to create extension for adobe softwares, its a javascript similar script language
Im working on a script to automate some boring and repetitive tasks
Here is my problem i've to wait the creation of a bin before use a variable which call this bin but i can't, i tried
.then( Promise => { //Some Code }) ; setTimeout(Function(), time); nothing is working
Can someone help me please ?
Here is my code
root = app.project.rootItem
newFilesPath = "Path"
newFilesBin = root.children[0]
app.project.importFiles(newFilesPath, true, newFilesBin, false)
app.project.save()
for(i=0; i<newFilesBin.children.numItems; i++){ //here is the problem it tells me that
newFile = newFilesBin.children[i] //newFilesBin is null, i think he has not the
//time to create the file and then to put it
//in the variable
name = newFile.name
newTiktokBin = root.createBin(name)
root.children[i].children[0].moveBin(newTiktokBin)
}
You can simply send your program to sleep for any amount of milliseconds by using the $.sleep() method.
$.sleep(1000); // sends the program to sleep for a second
There is no such thing as .then() or promises in ExtendScript, as it is basically an ancient version of JavaScript.
I have been having issues with module.exports.
I have 2 Scripts that use Discord.js, and i need to have a SetTimeout() variable that is common to both scripts to be able to use ClearTimeout() from each of them.
I tried to use:
//first script
var foo = 20;
module.exports.foo = foo;
//Second Script
var exp = require('./firstscript');
console.log(exp.foo);
This was a test, to see if i was doing it the wrong way, with a simple variable instead of my SetTimeout().
The test worked fine when i ran new scripts with the node command but with npm start on my 2 original scripts it returned 'undefined' while having the same syntax.
In every script is already a module.exports for the Discord.js event class like 'Ready' for exemple.
I'm running this bit of code outside the main module.exports at the top where the const are declared.
I wonder if this is causing my issue.
example:
//the code i'm talking about is here.
module.exports = class ReadyEvent extends BaseEvent {
constructor() {
super('ready');
}
async run(client) {
Thanks for your help. Ask me for clarification if needed.
EDIT:
I looked up on the internet to see if it was an issue with the module.export that was already present on the script. And it was.
Apparently you cannot have several module.export in a script if each one of them doesn't specify a variable:
//this doesn't work
module.exports.value = value;
module.exports = value2;
//this works
module.exports.value = value;
module.exportd.value2 = value2;
My problem was that the one already present was used by the 'discord.js compiler' to register every command so i couldn't modify it without breaking the bot.
I decided to put my timer in a new script named GlobalVars and it worked Perfectly fine.
I'm Satisfied that it works now. For me the issue is fixed but i would love to know if it is possible to export a variable WITH the discord.js module.exports syntax included.
From your Second Script variable, its seems to be requiring a folder and not a file, and I don't think folders are allowed.
Assuming you are requiring a script and not a folder:
First Mistake: When requiring, inside the brackets you must have quotation marks ("") or ('').
If it is a folder, add a / next to ./firstscript and assign it to the file you want to refer to.
var exp = require('./firstscript/THE_INTENDED_FILE');
...If firstscript is a json file:
var exp = require('./firstscript.json');
Extracting Variables from file
// Option 1:
console.log(exp.foo);
// Option 2:
const extract = exp.foo
console.log(extract);
I'm writing Prestashop 1.7.2.1 module.
In that module when I want to register a javascript file I connect to the hook actionFrontControllerSetMedia and use registerJavascript like so:
$this->context->controller->registerJavascript('module-tuxinmodcartype-carsearch-js','modules/'.$this->name.'/js/displaytop.js');
this loads the javascript properly but I can't use smarty template engine in those javascript files.
is there a way to do that ? :)
if not... should I just add all my javascript files inline ?
update
so I added this to my hook function:
Media::addJsDef(['tuxinmodcartype'=>array(
'car_companies'=>$this->tuxDb->getCompanyNamesArray()
)]);
and this my js file:
$(function() {
var options = {
data: tuxinmodcartype.car_companies,
list: {
match: {
enabled: true
}
}
};
$('#company-name-input').easyAutocomplete(options);
});
and I get the error ReferenceError: tuxinmodcartype is not defined
For accessing variables in javascript you can assign them in your controllers with:
Media::addJsDef(array(
'mymodule' => array(
'var1' => 'yes',
'var2' => 'no'
)
));
Then you can use them in your javascript or through console:
let var1 = mymodule.var1;
let var2 = mymodule.var2;
Building javascript files with smarty... I guess it's better to split javascript into more files and load them through controller based on conditions. Or use the above definition for variables to control execution path in your javascript.
Safer way to declare your vars without mymodule array,
Media::addJsDef(array('var1' => $myphpvar));
Media::addJsDef(array('var2' => $myphpvartwo));
this way you DONT need
let var1 = mymodule.var1;
Why this better? Because 'let var1' cause error in iphone safari browser.
You can simply do this in the tpl file:
<script>var = '{$var}';</script>
and use your var in the javascript file.
Source: https://www.prestashop.com/forums/topic/589645-unknown-tag-addjsdef-error/?tab=comments#comment-2490210
I recently tried to import a file into my existing node.js project. I know this should be written with a module but i include my external javascript file like this:
eval(fs.readFileSync('public/templates/simple.js')+'')
The contents of simple.js looks like this:
if (typeof examples == 'undefined') { var examples = {}; }
if (typeof examples.simple == 'undefined') { examples.simple = {}; }
examples.simple.helloWorld = function(opt_data, opt_sb) {
var output = opt_sb || new soy.StringBuilder();
output.append('Hello world!');
return opt_sb ? '' : output.toString();
};
(Yes, google closure templates).
I can now call the template file using:
examples.simple.helloWorld();
Everything is working like expected. However I'm not able to figure out what the scope of these functions is and where I could possibly access the examples object.
Everything is running in a node.js 0.8 server and like I said its working...I just dont quite know why?
Thanks for clarification.
eval() puts variables into the local scope of the place where you called it.
It's as if the eval() was replaced by the code in the string argument.
I suggest to change the content of the files to:
(function() {
...
return examples;
})();
That way, you can say:
var result = eval(file);
and it will be obvious where everything is/ends up.
Note: eval() is a huge security risk; make sure you read only from trusted sources.
I'd like to write Javascript scripts for Google Apps Script using CoffeeScript, and I'm having trouble generating functions in the expected form.
Google Apps Script expects a script to contain top-level, named functions. (I may be using the wrong terminology, so I'll illustrate what I mean with examples...)
For example, this function is happily recognised by Google Apps Script:
function triggerableFunction() {
// ...
}
... while this function is not (it will parse, but won't you won't be able to trigger it):
var nonTriggerableFunction;
nonTriggerableFunction = function() {
// ...
};
I've found that with CoffeeScript, the closest I'm able to get is the nonTriggerableFunction form above. What's the best approach to generating a named function like triggerableFunction above?
I'm already using the 'bare' option (the -b switch), to compile
without the top-level function safety wrapper.
The one project I've found on the web which combines CoffeeScript and Google App Script is Gmail GTD Bot, which appears to do this using a combination of back-ticks, and by asking the user to manually remove some lines from the resulting code. (See the end of the script, and the 'Installation' section of the README). I'm hoping for a simpler and cleaner solution.
CoffeeScript does not allow you to create anything in the global namespace implicitly; but, you can do this by directly specifying the global namespace.
window.someFunc = (someParam) ->
alert(someParam)
Turns out this can be done using a single line of embedded Javascript for each function.
E.g. this CoffeeScript:
myNonTriggerableFunction = ->
Logger.log("Hello World!")
`function myTriggerableFunction() { myNonTriggerableFunction(); }`
... will produce this JavaScript, when invoking the coffee compiler with the 'bare' option (the -b switch):
var myNonTriggerableFunction;
myNonTriggerableFunction = function() {
return Logger.log("Hello World!");
};
function myTriggerableFunction() { myNonTriggerableFunction(); };
With the example above, Google Apps Script is able to trigger myTriggerableFunction directly.
This should give you a global named function (yes, it's a little hacky, but far less that using backticks):
# wrap in a self invoking function to capture global context
do ->
# use a class to create named function
class #triggerableFunction
# the constructor is invoked at instantiation, this should be the function body
constructor: (arg1, arg2) ->
# whatever
juste use # in script, exemple of my code :
#isArray = (o)->
Array.isArray(o)
it will be compiled in :
(function() {
this.isArray = function(o) {
return Array.isArray(o);
};
}).call(this);
this = window in this case, so it's global function