You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Is it possible to pass any other arguments than window to 'executeJS(function(window))' ?
I would like to inject Redux state, but don't know if it is possible with Gemini (and I would like to avoid pasting it directly inside the function, because it contains ~3000 LOC).
I just hit the same problem. Currently I've solved it using the piece of code below. It's a bit hacky though and it's quite possible that the code can be improved upon.
getOptions=function(options){vardefaultOptions={"env": 'prod',};returnObject.assign(defaultOptions,options||{});}loadTest=function(window){window.loadJSFunction(/* REPLACEME */);}/* ** Copied from https://github.com/gemini-testing/gemini/blob/master/lib/tests-api/actions-builder.js and modified to accept dynamic options */functionserializeFunc(func,options){return'('+func.toString().replace('/* REPLACEME */',JSON.stringify(options))+'(window));';}/* ** Copied from https://github.com/gemini-testing/gemini/blob/master/lib/tests-api/actions-builder.js and modified to accept dynamic options */myExecuteJS=function(callback,options){if(typeofcallback!=='function'){thrownewTypeError('executeJS argument should be function');}this._pushAction(this.executeJS,functionexecuteJS(browser){returnbrowser.execute(serializeFunc(callback,options));});returnthis;};gemini.suite('firsttest',function(suite){suite.setUrl('/test.html').setCaptureElements(['#testContainer']);gemini.suite('fullpage',function(suite){suite.before(function(actions,find){actions.executeJS=myExecuteJS;actions.executeJS(loadTest,getOptions({"env": "test"}));actions.wait(1000);}).capture('test');})})
As @sipayRT has said there is no a straight way to pass any other arguments to method executeJS, but we are using the next hack to make closure work in this method:
varformat=require('util').format;/** * Helper which supports closure in callback of method '.executeJS' * * @param {Function} fn – callback of method '.executeJS' * @param {Object} vars – variables to be injected */exports.executeJsInjector=function(fn,vars){varvarsToExport=Object.keys(vars).map(function(v){returnformat('var %s = "%s";',v,vars[v]);}).join('\n');returnnewFunction([varsToExport,format('(%s)(window)',fn.toString())].join('\n'));};
where controlSelector is the variable which will be injected to function moveCaretToTheEnd. And function moveCaretToTheEnd will be passed as a callback to method executeJS.
Activity
sipayRT commentedon May 30, 2016
hi. no, you can't do it throw API. But there is another variant. @eGavr can you show your variant here?
rhoog commentedon Jun 23, 2016
I just hit the same problem. Currently I've solved it using the piece of code below. It's a bit hacky though and it's quite possible that the code can be improved upon.
eGavr commentedon Jun 23, 2016
@Pszek @rhoog
As @sipayRT has said there is no a straight way to pass any other arguments to method
executeJS, but we are using the next hack to make closure work in this method:This hack can be used like this:
where
controlSelectoris the variable which will be injected to functionmoveCaretToTheEnd. And functionmoveCaretToTheEndwill be passed as a callback to methodexecuteJS.ThaneshR commentedon Mar 21, 2017
Both approaches look real hacky. Will the
actions.executeJSbe updated to allow external functions to be passed in?