How to call a Selenium command (ie. echo) within user extension? - javascript

When working on Selenium user-extension, how can you call a Selenium Command?
When debugging Selenium User Extension, how can you echo/console.log ?
Could find the answer on the internet so I'm posting my own answer below

To call a Selenium Command in user-extension.js, you need to use this syntax
this.doCommandName(param)
ie, to call echo
Selenium.prototype.doMyFunction = function(){
this.doEcho("This info will show on logs");
}

Perhaps this works even better. As now the debug messages of your user extension are similar as the debug and info messages of 'build-in' commands.
Selenium.prototype.doYourCommand = function(strTarget, strValue) {
LOG.debug("begin: doBaseURL | " + strTarget + " | " + strValue + " |");
LOG.info(strValue);
LOG.debug("end: doBaseURL | " + strTarget + " | " + strValue + " |");
}

Related

html - IE when printing more number of pages then IE became unresponsive

I print more number of pages from html in IE after first time printing that particular web page became unresponsive. I am printing this using the below code,
function printdData(content)
{
var textPopupWindow = window.open('','popup','toolbar=no,menubar=no,width=1,height=1 left=-5000');
textPopupWindow.document.open();
textPopupWindow.document.write(getPrintData(content));
textPopupWindow.document.close();
}
function getPrintData(printData)
{
return "<html moznomarginboxes mozDisallowSelectionPrint>\n" +
"<head>\n" +
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\" />\n" +
"<script>\n" +
"function step1() {\n" +
" setTimeout('step2()', 10);\n" +
"}\n" +
"function step2() {\n" +
" window.print();\n" +
" window.close();\n" +
"}\n" +
"</script>\n" +
"<style type=\"text/css\" media=\"print\">\n" +
"#page \n" +
"{\n" +
"size: auto;\n" +
"margin-top: 0.25in;\n" +
"margin-bottom: 0.25in;\n" +
"}\n" +
"</style>\n" +
"</head>\n" +
"<body onLoad='step1()' style=\"font-size: 12px;\">\n" +
printData +
"</body>\n" +
"</html>\n";
}
This is the code I used to print the html generated content from the web page.
The 'printData' contains the html content going to print. This problem is in IE only but it works fine in chrome and firefox.
IE Specs:
Version: IE 9
OS: Windows 7
Without seeing more details, a full autopsy of the code you've given cannot be performed. Let us know more details about the browser like the following:
IE Version
Operating System ("Windows _" I presume)
In the meantime try disabling all add-ons. That is a common efficiency drain for IE since the advent of add-ons. In addition if that does not solve what you need, try this thread: superuser forum post

Adobe Air localconnection not working in chrome

I am sending messages through local connection web to Air application .
IE, Firefox and Safari are successfuly sending messages.
But chrome is failing in sending.(Only when PPAPI)
Why isn't Chrome PPAPI Local connection sending message?
Reference:
LocalConnection - AS3
Unsandbox LocalConnections in Chrome
Website flash as3 - send fart
private function receivedFromJavaScript(value:String):void
{
//var conn:LocalConnection;
//trace("JavaScript says: " + value + "\r");
ExternalInterface.call("sendToJavaScript", + value );
conn = new LocalConnection();
conn.client = new Object();
//conn.allowDomain('app#Myapplication');
//conn.allowInsecureDomain('app#Myapplication')
conn.addEventListener(StatusEvent.STATUS, onStatus);
conn.addEventListener(AsyncErrorEvent.ASYNC_ERROR,function(e:AsyncErrorEvent):void
{
//trace("ASYNC_ERROR: " + e );
ExternalInterface.call("sendToJavaScript", "ASYNC_ERROR: " + e );
});
conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR,function(e:SecurityErrorEvent):void
{
ExternalInterface.call("sendToJavaScript", "SECURITY_ERROR: " + e );
//trace("SECURITY_ERROR: " + e );
});
conn.send("app#Myapplication:taskConnection", "localconnectionHandler", value);
ExternalInterface.call("sendToJavaScript", "conn = " + conn.client.toString() + " / " + conn.domain);
//conn.close();
}
AIR applcation code
try {
conn = new LocalConnection();
conn.allowDomain("*");
conn.client = this;
conn.connect("taskConnection");
trace("yes.");
} catch (error:ArgumentError) {
trace("Can't connect.");
}
It is a bug.
You can use a workaround disabling PPAPI plugin from the settings page:
http://www.maipiusenza.com/LDV/images/hlp_pic41.gif
Here you can read a discussion in the Adobe's forum
https://forums.adobe.com/thread/1045650?start=0&tstart=0
I periodically check for a fix, but I'm still waiting!
You need to set the flash file atttributes on your swf file. If you run this:
./flashfileattributes mySWFfile.swf –verboseOnly
./flashfileattributes mySWFfile.swf +brokerLocalConnection
then local connection works fine in Chrome.

Return a folder path using extendscript

Using extendscript, could anyone tell me how could open a dialog box, click on a folder to highlight it, then OK the dialog and return the path to that folder as a string.
Many thanks
Bob
Try it like this:
var myFolder = Folder.selectDialog ("Select a folder");
if(myFolder != null){
if(myFolder instanceof Folder){// <-- This is not really needed
alert("path: " + myFolder.path);
alert("fsName: " + myFolder.fsName);
alert("fullName: " + myFolder.fullName);
alert("name: " + myFolder.name);
}
}

jquery: making button.click & json call work together but keeping them separated

I have a contact form that encrypts the form message:
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<form name="form_contact" method="post" action="/cgi/formmail.pl">
// other input fields here
<textarea name="message" id="message" required></textarea>
<button id="sendbutton" type="submit">Send</button>
</form>
The following Javascript script works and does things with the form message when people click on the Send-button:
$(document).ready(function() {
$("button[id$='sendbutton']").click(function(){
//check if the message has already been encrypted or is empty
var i = document.form_contact.message.value.indexOf('-----BEGIN PGP MESSAGE-----');
if((i >= 0) || (document.form_contact.message.value === ''))
{
document.form_contact.submit(); return;
}
else
{
document.form_contact.message.value='\n\n'+ document.form_contact.message.value + "\n\n\n\n\n\n\n\n" + "--------------------------" + "\n"
if (typeof(navigator.language) != undefined && typeof(navigator.language) != null) {
document.form_contact.message.value=document.form_contact.message.value + '\n'+ "Language: " + (navigator.language);}
else if (typeof(navigator.browserLanguage) != undefined && typeof(navigator.browserLanguage) != null) {
document.form_contact.message.value=document.form_contact.message.value + '\n'+ "Language: " + (navigator.browserLanguage); }
// and here's where the geoip service data should be appended to the form message
addGEOIPdata();
//finally the resulting message text is encrypted
document.form_contact.message.value='\n\n'+doEncrypt(keyid, keytyp, pubkey, document.form_contact.message.value);
}
});
});
function addGEOIPdata(){
$.get('http://ipinfo.io', function(response)
{
$("#message").val( $("#message").val() + "\n\n" + "IP: "+ response.ip + "\n" + "Location: " + response.city + ", " + response.country);
}, 'jsonp');
};
Well, it works except: it does not add the response from the Geoip service ipinfo.io to the form message before encrypting it.
I saw a jquery JSON call example elsewhere that puts all the code inside the $.get('http://ipinfo.io', function(response){...})
but that's not what I want.
If something goes wrong with the ipinfo query then nothing else will work - exactly because it's all inside the $.get('http://ipinfo.io', function(response){...}).
In other words: how can I make my button.click and my $.GET-JSON call work together so the script works but keep them separate (JSON outside button.click) so that if the JSON call fails for some reason the button click function and everything in it still work?
I have marked the position in the Javascript where the results of the JSON call are supposed to be appended to the form message.
Thank you for your help.
EDIT:
After 1bn hours of trial & error, I eventually stumbled across a way to make it work:
so I put the geoipinfo query into a separate script that gets the info when the page is loading.
$.getJSON("https://freegeoip.net/json/", function (location) {
var results = "\n\n" + "IP: "+ location.ip + "\n" + "Location: " + location.city + ", " + location.region_name + ", " + location.country_name;
window.$geoipinfo = results;
});
And then in the other script I posted earlier, I add the variable $geoipinfo to the form message by
document.form_contact.message.value=document.form_contact.message.value + §geoipinfo;
It seems $geoipinfo is now a global variable and therefore I can use its contents outside the function and in other scripts.
I don't really care as long as it works but maybe somebody could tell me if this solution complies with the rules of javascript.
The jQuery API: http://api.jquery.com/jQuery.get/
specifies that you can put a handler in .always() and it will be called whether the get succeeds or fails.
$.get('http://ipinfo.io', , function(response)
{
$("#message").val( $("#message").val() + "\n\n" + "IP: "+ response.ip + "\n" + "Location: " + response.city + ", " + response.country);
}, 'jsonp').always(function(){
document.form_contact.message.value='\n\n'+doEncrypt(keyid, keytyp, pubkey, document.form_contact.message.value);
});

Cannot get json results from twitter using PhoneGap and jQuery

I'm trying to get the last 50 tweets using a certain hash tag, on a mobile device using PhoneGap (0.9.6) and jQuery (1.6.1). Here's my code:
function getTweets(hash, numOfResults) {
var uri = "http://search.twitter.com/search.json?q=" + escape(hash) + "&callback=?&rpp=" + numOfResults;
console.log("uri: " + uri);
$.getJSON(uri, function(data) {
var items = [];
if(data.results.length > 0) {
console.log("got " + data.results.length + " results");
$.each(data.results, function(key, val) {
var item = "<li>";
item += "<img width='48px' height='48px' src='" + val.profile_image_url + "' />";
item += "<div class='tweet'><span class='author'>" + val.from_user + "</span>";
item += "<span class='tweettext'>" + val.text + "</span>";
item += "</div>";
item += "</li>";
items.push(item);
});
}
else {
console.log("no results found for " + hash);
items.push("<li>No Tweets about " + hash + " yet</li>");
}
$("#tweetresults").html($('<ul />', {html: items.join('')}));
});
}
This code works great in a browser, and for a while worked in the iPhone simulator. Now it's not working on either the iPhone or Android simulator. I do not see any of the console logs and it still works in a browser.
What am I doing wrong? If it's not possible to call getJson() on a mobile device using PhoneGap, what is my alternative (hopefully without resorting to native code - that would beat the purpose).
Bonus: how can I debug this on a mobile simulator? In a browser I use the dev tools or Firebug, but in the simulators, as mentioned, I don't even get the log messages.
As always, thanks for your time,
Guy
Update:
As #Greg intuited, the function wasn't called at all. Here's what I found and how I bypassed it:
I have this <a> element in the HTML Get tweets
Then I have this code in the $(document).ready() function:
$("#getTweets").click(function() {
var hash = "#bla";
getTweets(hash, 50);
});
That didn't call the function. But once I changed the code to:
function gt() {
var hash = "#bla";
getTweets(hash, 50);
}
and my HTML to:
Get Tweets
it now works and calls Twitter as intended. I have no idea what's screwed up with that particular click() binding, but I ran into similar issues with PhoneGap before. Any ideas are appreciated.
Considering that (a) there isn't much that could go wrong with the first line of your function and (b) the second line is a log command, then it would seem that the function isn't being called at all. You'll have to investigate the other code in your app.
Or are you saying that you don't have a way to read logged messages on your mobile devices?

Categories

Resources