There is a software product called AnyChart which is great for embedding Flashed based charts in web pages. AnyCharts can also export to PNG file format. Here is an example:
<script type="text/javascript" language="javascript">
//<![CDATA[
var chart = new AnyChart('http://www.mysite.com/swf/AnyChart.swf');
chart.width = 600;
chart.height = 300;
chart.setXMLFile('http://www.mysite.com/anychart.xml');
chart.addEventListener("draw", function() { saveChartAsImage(chart); });
chart.write("content-box");
//]]>
</script>
My ultimate goal is to make a automated service to export the AnyChart charts to PNG format. So I made a service with Indy which calls pages containing the AnyChart javascript. But the problem seems to be that Indy cannot execute the javascript.
Is there a way to enable Indy to execute javascript?
No, Indy does not execute Javascript. You may have also noticed that it doesn't parse or display HTML, and it doesn't run Flash, either. Indy does network protocols.
You could import the Microsoft Script Control ActiveX object and have that run your Javascript. If you need details on that, post a new question.
You don't have to use Indy for this. If you want you can use TWebBrowser.
IHTMLWindow2 interface has execScript function. So may be you can :
var
Doc : IHTMLDocument2;
Win : IHTMLWindow2;
aBrowser : TWebBrowser;
//...
begin
//...
Doc := aBrowser.Document as IHTMLDocument2;
Win := Doc.parentWindow;
Win.execScript('alert(SomeMessage);', 'JavaScript');
end;
Did you try vcl FOR THE web (aka Intraweb atozed) ?
There is a teechart version wich is quite useful, you can also execute "external" javascript code within any of the TiwForms of your web app (the exact same code you are using now).
Post a new question if you need to and I'll be glad to help.
Related
I want to identify few properties during my run and form a json object which I would like to write to a ".json"file and save it on the disk.
var target = UIATarget.localTarget();
var properties = new Object();
var jsonObjectToRecord = {"properties":properties}
jsonObjectToRecord.properties.name = "My App"
UIALogger.logMessage("Pretty Print TEST Log"+jsonObjectToRecord.properties.name);
var str = JSON.stringify(jsonObjectToRecord)
UIALogger.logMessage(str);
// -- CODE TO WRITE THIS JSON TO A FILE AND SAVE ON THE DISK --
I tried :
// Sample code to see if it is possible to write data
// onto some file from my automation script
function WriteToFile()
{
set fso = CreateObject("Scripting.FileSystemObject");
set s = fso.CreateTextFile("/Volumes/DEV/test.txt", True);
s.writeline("HI");
s.writeline("Bye");
s.writeline("-----------------------------");
s.Close();
}
AND
function WriteFile()
{
// Create an instance of StreamWriter to write text to a file.
sw = new StreamWriter("TestFile.txt");
// Add some text to the file.
sw.Write("This is the ");
sw.WriteLine("header for the file.");
sw.WriteLine("-------------------");
// Arbitrary objects can also be written to the file.
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
sw.Close();
}
But still unable to read and write data to file from ui automation instruments
Possible Workaround ??
To redirect to the stdout if we can execute a terminal command from my ui automation script. So can we execute a terminal command from the script ?
Haven't Tried :
1. Assuming we can include the library that have those methods and give it a try .
Your assumptions are good, But the XCode UI Automation script is not a full JavaScript.
I don't think you can simply program a normal browser based JavaScript in the XCode UI Automation script.
set fso = CreateObject("Scripting.FileSystemObject");
Is not a JavaScript, it is VBScript which will only work in Microsoft Platforms and testing tools like QTP.
Scripting.FileSystemObject
Is an ActiveX object which only exists in Microsoft Windows
Only few JavaScript functions like basic Math, Array,...etc..Are provided by the Apple JavaScript library, so you are limited to use only the classes provided here https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef/
If you want to do more scripting then Try Selenium IOS Driver http://ios-driver.github.io/ios-driver/
Hey so this is something that I was looking into for a project but never fully got around to implementing so this answer will be more of a guide of what to do than step by step copy and paste.
First you're going to need to create a bash script that writes to a file. This can be as simple as
!/bin/bash
echo $1 >> ${filename.json}
Then you call this from inside your Xcode Instruments UIAutomation tool with
var target = UIATarget.localTarget();
var host = target.host();
var result = host.performTaskWithPathArgumentsTimeout("your/script/path", ["Object description in JSON format"], 5);
Then after your automation ends you can load up the file path on your computer to look at the results.
EDIT: This will enable to write to a file line by line but the actual JSON formatting will be up to you. Looking at some examples I don't think it would be difficult to implement but obviously you'll need to give it some thought at first.
I am currently writing a JavaScript script for the Microsoft JScript Runtime Environment. It's not in a browser, but rather going to be run more like a SysAdmin would use VBScript. I've written a lot of code, and while some of it is specific for what needs to be accomplished, a majority of it is supporting framework for the script to do what it needs to do. I'd like to use this sum of code in other future scripting adventures, but as to my current knowledge, I would have to copy and paste these mini-libraries over and over again, and well, that's just an update nightmare for one and two, it's inefficient. I know it's possible to dynamically load JS when I have a window or document, I know it's possible to require() JS files in Node.js, but is this possible in the raw JScript Runtime for MS?
Look into the Windows Script File (*.wsf) format. One of its features is to allow for includes like you're describing. An example taken from the linked documentation:
<job id="IncludeExample">
<script language="JScript" src="FSO.JS"/>
<script language="VBScript">
' Get the free space for drive C.
s = GetFreeSpace("c:")
WScript.Echo s
</script>
</job>
where "FSO.JS" contains the JScript library.
Assuming your talking about the WSH, you can load a file and eval the contents, which is much the same as including it.
var incfso=new ActiveXObject("Scripting.FileSystemObject");
include = function(x) {
eval(incfso.OpenTextFile(x,1).ReadAll());
}
source: http://www.mailsend-online.com/blog/wsh-javascript-includes.html
I couldn't find a global object like "window" for jscript, but you can sort of create one.
var host = this;
var test = "hello-world";
var messagebox = new ActiveXObject("wscript.shell");
if (host.test) {
messagebox.Popup("host.test exists, value = " + host.test);
} else {
messagebox.Popup("host.test does not exist.");
}
I think "host" should now effectively be the global object. (the example works for me anyway)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
calling a Flash ExternalInterface with JavaScript
I have a flash file with AS code. I want to run Javascript that will run a function the AS. For example: In the AS I have a function called "loadXML". The object that holds the SWF file called "pawel" (The ID of the object). How can I run a Javascript code that will run on "pawel" the function "loadXML"? I'm using Flash 6 with AS 3.
You should use ExternalInterface.addCallback() method. See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#addCallback() for details.
I suggest you check this http://www.redcodelabs.com/2012/04/calling-actionscript-method-from-javascript/ it has running sample and as3/js code.
I believe the goal here is to send the swf (which has compiled an external .as file) the location of an xml file somewhere on the server so the swf can compile, parse, and create something.
I've done this many times, using flash variables, which may be useful to you as well. When embedding the .swf in your webpage you can send it flash variables via js or html, or dynamically with php. Once i have my fla working perfectly with hardcoded variables (like the xml) i then add the flash variable code to the head and make a few minor adjustments to the fla – which usually breaks the fla from running "properly" within flash (because it's now dependent upon these external variables)
anyways, here's how i do my flash vars (there's other ways, worth a good google search)
import flash.net.*;
var flashVars:Object = new Object();
flashVars = this.loaderInfo.parameters;
var xmlVal;
for (var item:String in flashVars)
{
switch (item)
{
case "xmlLocation" :
xmlVal = String(flashVars[item]);
break;
}
}
Here's the javascript which sends the values:
<script type="text/javascript">
//flashObj
var flashvars = {};
flashvars.xmlLocation = "http://google.com/myXML.xml";
var params = {wmode:"transparent"};
var attributes = {};
swfobject.embedSWF("images/banner.swf", "yourSliderId", "175", "300", "9.0.0", false, flashvars, params, attributes);
</script>
this is using SWFObject (an open API flash embedding js library) to handle the swf embed. I prefer it because if you look at the code above you can read it and understand it, the default way is really hard to read, edit and understand.
If you simply need XML and then you're done, this will work for you. If you still need to say hit the 'next' or 'previous' button using javascript, refer to this web site article, i believe this may help you out further:
http://arrixlive.wordpress.com/2005/03/25/javascript-in-love-with-flash-control-swf-from-javascript/
So similar to ALt-Shift-F in Netbeans, is there a to do this right in the ide in TestComplete? Not sure if this is possible or if anyone can think of a workaround to autoFormat without leaving the TestComplete window.
I'm trying to get the below solution to work with http://jsbeautifier.org/ for javascript / Jscript code in TestComplete.
Thanks
Great question!
There is no built-in function for that. So, we should not expect any solution to be 100% convenient - it is just not a simple task to modify the current script editor contents (if at all possible). So, whatever you do, it will still be some kind of compromise.
In general, the task is three-fold:
Get the current unit code.
Format the code.
Put the code back to the unit.
According to my understanding, items 1 and 3 can be accomplished only by creating a TestComplete plug-in - accessing editors for project nodes is not an easy thing.
UPDATE: silly me! There is a way to access the script editor code - I've updated the below part.
What will help us avoid switching to a different app, are the Script Extensions:
We create a custom Checkpoint in the form of a Script Extension, and install it to TestComplete. As a result, we get a button on the toolbar that we can click to invoke our code.
In the design time action, we call some code that reads the editor contents, then uses external code formatting functionality, and replaces the editor contents with the formatted code.
It would extremely interesting to see the implementations other TestComplete users can suggest! As a start, I am posting a solution that includes using an external web site to format VBScript code (http://www.vbindent.com/). I know that the starter of the post is probably using JScript, but I have not found a JScript formatter yet.
My solution is a simple Script Extension. I can't post a file here, so I will post the code of the two Script Extension files:
Description file:
<!-- Description.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<ScriptExtensionGroup>
<Category Name="Checkpoints">
<ScriptExtension Name="VBScript Code Indent" Author="SmartBear Software" Version="0.1" HomePage="smartbear.com">
<Script Name="VBIndent.js">
<DesignTimeAction Name="Indent Current VBScript Unit" Routine="DesignTimeExecute"/>
</Script>
<Description>
Indents VBScript code in the currently active unit.
</Description>
</ScriptExtension>
</Category>
</ScriptExtensionGroup>
Code file:
// VBIndent.js
function DesignTimeExecute()
{
if (CodeEditor.IsEditorActive)
{
var newCode = IndentVBSCode_Through_VBIndent(CodeEditor.Text);
if (null == newCode)
return;
CodeEditor.Text = newCode;
}
}
function IndentVBSCode_Through_VBIndent(codeToIndent)
{
var URL_VBIndent = "http://www.vbindent.com/?indent";
var httpObj = Sys.OleObject("MSXML2.XMLHTTP");
httpObj.open("POST", URL_VBIndent, false);
httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpObj.send("thecode=" + escape(codeToIndent));
var responseText = httpObj.responseText;
// Extract the indented code from the response
var rx = /<textarea name=\"thecode\".*?>((.*\n)*?)<\/textarea>/;
matches = rx.exec(responseText);
if (null == matches)
{
return null;
}
codeIndented = matches[1];
return codeIndented;
}
After you create these files, and put them to something like "\Bin\Extensions\ScriptExtensions\VBIndent", and click "File | Install Script Extensions | Reload", you will see a new "Indent Current VBScript Unit" item in the custom checkpoints drop-down button on the Tools toolbar. Clicking the element will format the VBScript code in the currently active editor.
So, this is to give a clear idea of what a solution can look like. Better suggestions are welcome! Share your thoughts!
FYI
I've done. Based on your posts.
JSFormat.tcx
https://drive.google.com/uc?export=download&id=0B1x_73bHRc2Jcm8wbTJ2dUpZQTQ
To install the extension copy attached file JSFormat.tcx to C:\Program Files (x86)\SmartBear\TestComplete 10\Bin\Extensions\ScriptExtensions
To use view next image:
https://drive.google.com/uc?export=download&id=0B1x_73bHRc2Jc3RuLXFpTnlCSnc
Regards
How to tag images in the image itself in a web page?
I know Taggify, but... is there other options?
Orkut also does it to tag people faces... How is it done?
Anyone knows any public framework that is able to do it?
See a sample bellow from Taggify:
I know this isn't javascript but C# 3.0 has an API for doing this. The System.Windows.Media.Imaging namespace has a class called BitmapMetadata which can be used to read and write image metadata (which is stored in the image itself). Here is a method for retrieving the metadata for an image given a file path:
public static BitmapMetadata GetMetaData(string path)
{
using (Stream s = new System.IO.FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
var decoder = BitmapDecoder.Create(s, BitmapCreateOptions.None, BitmapCacheOption.OnDemand);
var frame = decoder.Frames.FirstOrDefault();
if (frame != null)
{
return frame.Metadata as BitmapMetadata;
}
return null;
}
}
The BitmapMetadata class has a property for tags as well as other common image metadata. To save metadata back to the image, you can use the InPlaceBitmapMetadataWriter Class.
There's a map tag in HTML that could be used in conjunction with Javascript to 'tag' different parts of an image.
You can see the details here.
I will re-activate this question and help a bit. Currently the only thing i have found about is http://www.sanisoft.com/downloads/imgnotes-0.2/example.html . A jQuery tagging implementation. If anyone knows about another way please tell us.
;)
You can check out Image.InfoCards (IIC) at http://www.imageinfocards.com . With the IIC meta-data utilities you can add meta-data in very user-friendly groups called "cards".
The supplied utilities (including a Java applet) allow you to tag GIF's, JPEG's and PNG's without changing them visually.
IIC is presently proprietary but there are plans to make it an open protocol in Q1 2009.
The difference between IIC and others like IPTC/DIG35/DublinCore/etc is that it is much more consumer-centric and doesn't require a CS degree to understand and use it...