Failed: Cannot read property 'cartblock' of undefined - javascript

I'm new to protractor using javascript, I created a simple script that calls data from another js file.
I have a file called jsobjectdemo.js that contains
<pre>
this.productnames = element.all(by.tagName("app-card"));
this.cartblock = element(by.css("h4 a"));
this.addcartbutton = element(by.css("button[class='btn btn-info']"));
</pre>
And another file called jscalldemo.js
var cart = require('./jsobjectdemo.js');
function addCart(productname){
cart.productnames.each(function(item){
cart.cartblock.getText().then(function(text){
if (text==productname){
cart.addcartbutton.click();
}
})
})
}
When i ran the script, it returns an error
Message:
Failed: Cannot read property 'cartblock' of undefined
Stack:
TypeError: Cannot read property 'cartblock' of undefined
at D:\Trainings\Protractor\protractor-workspace\Protractor\jscalldemo.js:8:14

Const loc = {
productnames = element.all(by.tagName("app-card")), cartblock = element(by.css("h4 a")), addcartbutton = element(by.css("button[class='btn btn-info']"))
}
exports.cart = loc;
Change your jsobjectdemo.js to the above.
And in your jscalldemo.js
Const cart = require('./jsobjectdemo.js').cart;
Now you can use cart.cartblock in jscalldemo.js

Related

How to use value from Observable inside TypeScript component | Angular 4

I'm trying to get a JSON value I got from an API and set it inside a variable, for example:
TS
this.graphicService.getDatas().subscribe(datas => {
this.datas = datas;
console.log(datas);
});
test = this.datas[0].subdimensions[0].entry;
HTML
{{test}}
it returns an error on console:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'subdimensions' of undefined
TypeError: Cannot read property 'subdimensions' of undefined
at new GraphicsComponent (graphics.component.ts:33)...
However, It does work if I use directly on HTML like this:
{{datas[0]?.subdimensions[0].entry}}
The data is printed correctly then.
..
Try this:
let test;
this.graphicService.getDatas().subscribe(datas => {
this.datas = datas;
console.log(datas);
test = this.datas[0].subdimensions[0].entry;
});

Swagger-ui + oauth -> index.js:24 Uncaught TypeError: Cannot read property 'api' of undefined

first of all i am using a bit modified version of the standard html/js code offered from swagger-ui.
Changes are rather simple, instead of using only a single SwaggerUI element like:
window.swaggerUi = new SwaggerUi({
....
window.swaggerUi.load();
we iterate over them and create lots of swaggerUI elements:
function addSwaggerUI(url, dom_id, host){
window[dom_id] = new SwaggerUi({
....
window[domId].load();
this is our iteration:
var services = [{SERVICE_SPECS}];
var doc_container = document.getElementById('service-doc-container');
var index = 0;
services.forEach(function(serviceSpec) {
var swaggerNode = document.createElement('div');
swaggerNode.id = "swagger-ui-container-" + index;
swaggerNode.className = "swagger-ui-wrap";
var messageNode = document.createElement('div');
messageNode.id = "message-bar-" + index;
messageNode.className = "swagger-ui-wrap";
doc_container.appendChild(swaggerNode);
doc_container.appendChild(messageNode);
log("adding service documentation for " + serviceSpec);
addServiceDocumentation(serviceSpec, swaggerNode.id, "{SERVICE_HOST}");
index++;
});
This worked quiet well until we started using securityDefinitions oAuth:
"securityDefinitions": {
"OauthSecurity": {
"type": "oauth2",
"authorizationUrl": "http://localhost/oauth/dialog",
"flow": "implicit",
"scopes":{
"write:sessions":"kill sessions",
"read:sessions":"get sessions"
}
}
Now i get on each swaggerUI this error:
index.js:24 Uncaught TypeError: Cannot read property 'api' of undefined
Original swaggercode:https://github.com/swagger-api/swagger-ui/tree/master/dist see index.html
Can someone help to fix this?
(Alternative solution: Anyone know of another way to add multiple web apis from different json files on one html page? )
UPDATE:
So i looked at the generated page from swagger.petstore.io and found something called 'authorzie-wrapper'it is possible that this element is missing at my code.

Error Start workflow via JavaScript

I can't get start a Workflow via Web Script.
I created the file workflow.get.js:
var nodeId = args.nodeid; //fdadc86f-d996-472d-8267-850a63573b02
var workflowName = args.w; //jbpm$wf:adhoc
var document = search.findNode("workspace://SpacesStore/" + nodeId);
var workflowAction = actions.create("start-workflow");
workflowAction.parameters.workflowName = workflowName;
workflowAction.parameters["bpm:workflowDescription"] = "Please edit: " + document.name;
workflowAction.parameters["bpm:assignees"] = [people.getPerson("admin"), people.getPerson("admin")];
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 7);
workflowAction.parameters["bpm:workflowDueDate"] = futureDate;
workflowAction.execute(document);
workflow.get.desc.xml
<webscript>
<shortname>Start Workflow</shortname>
<description>Testando Start Workflow</description>
<url>/workflow?nodeid={idfile}&&w={namewf}</url>
<format default="html">argument</format>
<authentication>admin</authentication>
<transaction>required</transaction>
</webscript>
and workflow.get.html.ftl
The ${args.w} started!
when I click http://localhost:8080/alfresco/service/workflow?nodeId=fdadc86f-d996-472d-8267-850a63573b02&w=jbpm$wf:adhoc return the error
06190076 Wrapped Exception (with status template): 06190474 Failed to execute script '/triggerworkflow.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts)': 06190473 Can't find method org.alfresco.repo.jscript.ScriptAction.execute(org.mozilla.javascript.Undefined). (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts)#11)
Exception: org.alfresco.error.AlfrescoRuntimeException - 08200041 TypeError: Cannot read property "name" from null
(workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/Workflow/workflow.get.js#7)
org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:469)
Exception: org.alfresco.scripts.ScriptException - 08200042 Failed to execute script '/Workflow/workflow.get.js
(in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': 08200041 TypeError: Cannot read
property "name" from null (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/Workflow/workflow.get.js#7)
org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:183)
Exception: org.springframework.extensions.webscripts.WebScriptException - 08200035 Wrapped Exception (with status template):
08200042 Failed to execute script '/Workflow/workflow.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)'
: 08200041 TypeError: Cannot read property "name" from null (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/Workflow/
workflow.get.js#7)
org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:742)
Anybody help me?
Your problem is you're calling arguments one thing in one place, and a different thing in another:
var nodeId = args.nodeid; //fdadc86f-d996-472d-8267-850a63573b02
var workflowName = args.w; //jbpm$wf:adhoc
vs
<url>/workflow?nodeid={idfile}&&w={namewf}</url>
You need to get those to agree! I'd suggest, given the URL you seem to already be using from the client, changing your webscript descriptor URL to match what you use, to:
<url>/workflow?nodeid={nodeid}&w={w}</url>
You should also add logic to check that the node given really exists - search.findNode can return null so you should check that before continuing (eg and give a 404 if not found)
Also, you could use utils.getNodeFromString(String) if you'd rather
Please try to start your workflow using this code,
replace your code of workflow.get.js with this code and change all the properties according to your requirement.
function startWorkflow()
{
var workflowAction = workflow.getDefinitionByName("activiti$test_wf");
var package= workflow.createPackage();
var wfparams = new Array();
wfparams["model_prefix:req_props_name"] = value2;
wfparams["bpm:assignee"] = people.getPerson("ADMIN");
workflowAction.startWorkflow(package, wfparams);
}
}
startWorkflow();

Why is my jsondata object undefined?

var jsondata = $.parseJSON('{"bwpaperback":{"creme":{"5x8":[".95",".016"],"5_25x8":[".95",".016"],"5_5x8_5":[".95",".016"],"6x9":[".95",".016"],"pages":["18","1050"]},"white":{"5x8":[".95",".016"],"5_25x8":[".95",".016"],"5_5x8_5":[".95",".016"],"6x9":[".95",".016"],"8x8":[".95",".016"],"8_5x8_5":[".95",".016"],"7x10":["1.35",".021"],"8x10":["1.35",".021"],"8_25x11":["1.35",".021"],"8_5x11":["1.35",".021"],"pages":["18","1200"]}},"bwhardcover":{"case":{"creme":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1050"]},"white":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"8x8":["6.05",".016"],"8_5x8_5":["6.05",".016"],"7x10":["6.05",".021"],"8x10":["6.05",".021"],"8_5x11":["6.05",".021"],"pages":["18","1200"]}},"cloth":{"creme":{"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1050"]},"white":{"5x8":["6.05",".016"],"5_5x8_5":["6.05",".016"],"6x9":["6.05",".016"],"pages":["18","1200"]}}},"scpaperback":{"5x7":[".95",".026"],"5x8":[".95",".026"],"5_25x8":[".95",".026"],"5_5x8_5":[".95",".026"],"6x9":[".95",".026"],"8_5x8)5":[".95",".026"],"7x10":["1.30",".031"],"8x10":["1.30",".031"],"8_25x11":["1.30",".031"],"8_5x11":["1.30",".031"],"pages":["18","1200"]},"schardcover":{"case":{"5x8":["6.05",".026"],"5_5x8_5":["6.05",".026"],"6x9":["6.05",".026"],"8x8":["6.05",".026"],"8_5x8_5":["6.05",".026"],"7x10":["6.05",".031"],"8x10":["6.05",".031"],"8.5x11":["6.05",".031"],"pages":["18","1200"]},"cloth":{"5x8":["6.05",".026"],"5_5x8_5":["6.05",".026"],"6x9":["6.05",".026"],"pages":["18","1200"]}},"pcpaperback":{"5_5x8_5":["1.05",".06"],"6x9":["1.05",".09"],"8x8":["1.05",".09"],"8_5x8_5":["1.05",".09"],"7x10":["1.55",".10"],"8x10":["1.55",".10"],"8_5x11":["1.55",".10"],"pages":["4,900"]},"pchardcover":{"case":{"5x8":["6.05",".06"],"5_5x8_5":["6.05",".06"],"6x9":["6.05",".091"],"8x8":["6.05",".091"],"8_5x8_5":["6.05",".091"],"7x10":["6.05",".011"],"8x10":["6.05",".011"],"8_5x11":["6.05",".011"],"pages":["24,840"]},"cloth":{"5x8":["6.05",".06"],"5_5x8_5":["6.05",".06"],"6x9":["6.05",".091"],"pages":["24,840"]}}}');
if(main.hasClass('bw') && main.hasClass('paperback')){
baseprice = jsondata[calctype][color][size][0];
perpage = jsondata[calctype][color][size][1];
minpages = jsondata[calctype][color].pages[0];
maxpages = jsondata[calctype][color].pages[1];
}
I'm not sure if I need to provde more code. but it says "Uncaught TypeError: Cannot read property '#' of undefined"
This worked when I was using $.getJSON from an external json file. How can I use this as a object instead of .json?
thanks!

TypeError: Error #1009: Cannot access a property or method of a null object reference. at Slide1_fla::MainTimeline/frame1() AS3

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Slide1_fla::MainTimeline/frame1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Slide2_fla::MainTimeline/frame1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Side3_fla::MainTimeline/frame1()
I have tried all of the sources and still couldn't find any answer to fix this problem.
I am running Adobe Flash CS6 AS3
Whenever I run the script, I get this output and the file doesn't run properly. In the published file, the swf file isn't show completely, meaning the external .swf files are not fitted in the contentContainer.
My code is this:
var _swfLoader:Loader;
var _swfRequest:URLRequest;
var _swfPathArr:Array = new Array("Slide1.swf", "Slide2.swf", "Slide3.swf");
var _swfClipsArr:Array = new Array();
var _swfTempClip:MovieClip;
var _loadedSWFs:int;
var contact_btn:SimpleButton;
var news_btn:SimpleButton;
var portfolio_btn:SimpleButton;
startLoading(_swfPathArr);
function startLoading(pathArr:Array):void {
_swfLoader = new Loader();
_swfRequest = new URLRequest();
loadSWF(pathArr[0]);
}
function loadSWF(path:String):void {
setupListeners(_swfLoader.contentLoaderInfo);
_swfRequest.url = path;
_swfLoader.load(_swfRequest);
}
function setupListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, onSwfComplete);
dispatcher.addEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
}
function currentSwfProgress(event:ProgressEvent):void {
var _perc:int = (event.bytesLoaded / event.bytesTotal) * 5;
// swfPreloader.percentTF.text = _perc + "10%";
}
function onSwfComplete(event:Event):void {
event.target.removeEventListener(Event.COMPLETE, onSwfComplete);
event.target.removeEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
_swfTempClip = event.target.content;
_swfTempClip.customID = _loadedSWFs;
_swfClipsArr.push(_swfTempClip);
if(_loadedSWFs <_swfPathArr.length - 1) {
_loadedSWFs++;
loadSWF(_swfPathArr[_loadedSWFs]);
} else {
_swfLoader.unloadAndStop();
_swfLoader = null;
onCompletePreloading();
}
}
function onCompletePreloading():void {
contentContainer.addChild(_swfClipsArr[0]);
news_btn.enabled = true;
contact_btn.enabled = true;
portfolio_btn.enabled = true;
news_btn.addEventListener(MouseEvent.CLICK, setContent);
portfolio_btn.addEventListener(MouseEvent.CLICK, setContent);
contact_btn.addEventListener(MouseEvent.CLICK, setContent);
}
function setContent(event:MouseEvent):void {
var _swfToAdd:MovieClip;
switch(event.target.name) {
case "news_btn":
_swfToAdd = _swfClipsArr[0];
break;
case "portfolio_btn":
_swfToAdd = _swfClipsArr[1];
break;
case "contact_btn":
_swfToAdd = _swfClipsArr[2];
break;
}
contentContainer.removeChildAt(contentContainer.numChildren-1);
contentContainer.addChild(_swfToAdd);
trace(_swfToAdd.customID);
}
I used to face this problem when the loaded SWF contain "TLF Text".
So the fix? Make "ALL" your textfield in the loaded SWF "Classic Text" and hopefully your problem would be solved.
PS. An easy way to clean all TLF text from a FLA file is to change document script from ActionScript 3.0 to 2.0. Since TLF Text is only support in 3.0, they will immediately change back to Classic Text, and then change your script back to 3.0 again. :)

Categories