Perl for Windows GUI - windows

I searched the internet before coming here. I guess everyone's needs are different. I want a Windows GUI program that will get information from database and show it in grid and have a delete button next to each record. I also want it to have a link, for example if the id number of the record is clicked, it opens new browser and navigates to a page associated with it, and completes forms then submits by itself.
The question is: Since there are many modules out there, which one is the best for this?
(Perl Nubie)

Nobody can truly say what is BEST, but the option of the Tk module with a backend of, in your case, DBD::MySQL, is maybe the most "standard" for things like this in Perl. Examples for both can be found all around online.
Here are some for SQL with mySQL and DBD :
http://sql-info.de/mysql/examples/Perl-DBI-examples.html
Here is a good document of examples for perl TK:
http://www.ibm.com/developerworks/aix/library/au-perltkmodule/index.html
As far as opening a browser - a simple system command will do:
my #command = ('start', $url);
system(#command);
^That is for Windows. It looks like you have a decently large application you want to build - opening a browser is just a small part of it - you will want to execute the above when a button is pressed, no doubt.
The last part...submitting data to forms on the web, is a topic called "web crawling"... WWW::Mechanize is a library to look into - Google "perl web crawler" and you are bound to get more good examples.
I found this with a little searching - it looks to be of use to you:
http://www.stratos.me/2009/05/writing-a-simple-web-crawler-in-perl/

Give one (nasty) precondition, ca. 25 lines of HTML
<html>
<head>
<hta:application id="demo" scroll="No"></hta>
<title>Demo</title>
<script language = "PerlScript"
src = "demo.pl"
type = "text/perlscript"
></script>
</head>
<body onload="DoOnLoad()" onunload="DoOnUnLoad()">
<object classid = "clsid:67397AA3-7FB1-11D0-B148-00A0C922E820"
id = "id_oDC"
style = "position:relative;width:1px;height:1px"
></object>
<object classid = "clsid:CDE57A43-8B86-11D0-B3C6-00A0C90AEA82"
id = "id_oDG"
style = "position:relative;width:100%;height:95%"
></object>
</body>
</html>
and ca. 40 lines of Perl:
use strict;
use warnings;
use Win32::OLE qw( in );
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
use vars qw( $window );
my $oAdoDC;
my $oAdoDG;
sub DoOnLoad {
my $owda = $window->document->all;
$oAdoDC = $owda->id_oDC;
$oAdoDC->{ConnectionString} = 'DSN=SakilaGent';
$oAdoDG = $owda->id_oDG;
$oAdoDC->{CursorType} = adOpenKeyset;
$oAdoDG->Font->{Name} = "Arial";
$oAdoDG->Font->{Size} = "8";
$oAdoDG->HeadFont->{Name} = "Arial";
$oAdoDG->HeadFont->{Size} = "8";
$oAdoDC->{RecordSource} = "select * from customer";
$oAdoDG->{Caption} = $oAdoDC->{RecordSource};
$oAdoDC->Refresh();
$oAdoDG->{DataSource} = $oAdoDC;
}
sub DoOnUnLoad {
$oAdoDG->{ DataSource }->Close();
$oAdoDC->{ Recordset }->Close();
$oAdoDG = undef;
$oAdoDC = undef;
}
will give you a flexible 'display/edit every recordset from every database accessible by ADO' type of data grid:
at no costs. A person familiar with HTML (but not Tk or Wx) and ADO/Access/Excel (but not DBI) could build a nice Database GUI easily/effiently. The precondition (i.e. drawback) is: Even the deployment computers need to have the "Microsoft DataGrid Control 6.0 (OLEDB)" (there are a plain tabular, a hierarchical, and a flexible hierarchical grid control too; maybe more modern controls can be used also) installed in a development/design-time enabled mode.

I would suggest using:
Wx for the user interface (provides a more modern/native look than Tk; see also the main site wxWidgets)
DBD::SQLite for local database storage
WWW::Mechanize - submitting forms
Since you're using Windows, your best bet would be to install Strawberry Perl which includes SQLite and Mechanize. Installing Wx or Tk is an extra step, but you should be able to find tutorials on the web from others who have done so. You may also want to look at Padre, the Perl IDE which is a Perl editor / development environment (it also happens to use Wx).

Related

Is there a way to automate IE Mode in Microsoft Edge browser for project in Ruby?

Refers to this thread : Is there a way to activate IE mode in Edge Options?
It may sound like a duplicate, but my question is not if automating IE Mode in Edge is possible or not, but if it is possible for Ruby. So far, I only saw the code that can run Edge in IE mode in C#, VB.NET, etc but not in Ruby.
Here is the code I refer to :
static void Main(string[] args)
{
var dir = "{FULL_PATH_TO_IEDRIVERSERVER}";
var driver = "IEDriverServer.exe";
if (!Directory.Exists(dir) || !File.Exists(Path.Combine(dir, driver)))
{
Console.WriteLine("Failed to find {0} in {1} folder.", dir, driver);
return;
}
var ieService = InternetExplorerDriverService.CreateDefaultService(dir, driver);
var ieOptions = new InternetExplorerOptions{};
ieOptions.AddAdditionalCapability("ie.edgechromium", true);
ieOptions.AddAdditionalCapability("ie.edgepath", #"\\msedge.exe");
var webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(30));
webdriver.Url = "http://www.example.com";
}
If Ruby supports these features, please let me know or share where I can go to look for the solution.
I didn't find related information about using Ruby to automate Edge IE mode. AFAIK, it only works with C#, VB.NET and Python now.
You can have a try to set the same IE capabilities in Ruby, if it doesn't work, then I think Ruby doesn't support the capabilities either. In this situation, you can raise a new issue about adding these features in IE WebDriver on Selenium GitHub as IE WebDriver is maintained by Selenium.
If you're using selenium 3, add those 2 new capabilities into the desired capabilities payload
If you're using selenium 4, add those 2 new capabilities to the first part of the capabilities array.
The names look W3C-like, so in theory they "should" just work. But I've never heard of anyone even wanting to automate this (i.e. what is the real world use case)

Find Hidden Miners in Go (Hidden windows + commandlines)

I found this C# and I want to improve on it in Go: https://github.com/roachadam/MinerKiller/blob/master/MinerKiller/MinerKiller.cs
My first question, is how do I detect if a process window is hidden. ie this code:
if (p.MainWindowHandle == IntPtr.Zero )
My Second question is how to get the command line of a process. ie this C# code
private string GetCommandLine(Process process)
{
string cmdLine = null;
using (var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
{
var matchEnum = searcher.Get().GetEnumerator();
if (matchEnum.MoveNext())
{
cmdLine = matchEnum.Current["CommandLine"]?.ToString();
}
}
return cmdLine;
}
While the go standard library's os package provides a lot of nice utilities for interfacing with operating system functionality, they are much "lower level" then what you are referencing from the .NET System.Management classes. You will most likely have to implement the behavior of these classes yourself to achieve the desired outcome (using the tool from Go's os package as your primary "building blocks")
That said, there is a psutil port in Go (gopsutil - https://github.com/shirou/gopsutil/) that provides utilities for retrieving info on running processes as well as system utilization. This will most likely provide the higher level abstraction you can use to implement your program.
If gopsutil is too opinionated or high level for you needs, I would also check out the operating system specific packages in the golang subrepositories.
Documented here: https://godoc.org/golang.org/x/sys
Source here: https://github.com/golang/sys/

Calling checkCurrentDictionary() from addon crashes FF - why?

I'm tyring to call the method checkCurrentDictionary() of nsIEditorSpellCheck from within an add-on. The relevant code I use is:
var editorSpellCheck = Cc["#mozilla.org/editor/editorspellchecker;1"].createInstance(Ci.nsIEditorSpellCheck);
editorSpellCheck.checkCurrentDictionary();
This immediately crashes the Fx. What is going wrong here?
So this probably has something to do with the fact that nsIEditorSpellCheck is not a scriptable interface.
Basically, a scriptable interface is one that can be used from JavaScript.
If you want to access the spell check service you can do something like:
let editor = editableElement.editor;
if (!editor) {
let win = editableElement.ownerDocument.defaultView;
editor = win.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIWebNavigation).
QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIEditingSession).
getEditorForWindow(win);
}
if (!editor)
throw new Error("Unable to find editor for element " + editableElement);
(The above is from http://dxr.mozilla.org/mozilla-central/source/editor/AsyncSpellCheckTestHelper.jsm which is MPL).
Then you can use the InlineSpellCheck.jsm to do some crazy stuff.
I'm not sure what you want to do though, so perhaps you should ask that more specific question as a new question.

Coded UI error: The following element is not longer availabe

I recorded some test cases with CUIT in VS2010. Everything worked fine the day before. So, today I run again, all the test failed, with the warning: The following element is no longer available ... and I got the exception : Can't perform "Click" on the hidden control, which is not true because all the controls are not hidden. I tried on the other machine, and they failed as well.
Does anyone know why it happens? Is it because of the web application for something else? Please help, thanks.
PS: So I tried to record a new test with the same controls that said "hidden controls", and the new test worked!? I don't understand why.
EDIT
The warning "The following element blah blah ..." appears when I tried to capture an element or a control while recording. The source code of the button is said 'hidden'
public HtmlImage UIAbmeldenImage
{
get
{
if ((this.mUIAbmeldenImage == null))
{
this.mUIAbmeldenImage = new HtmlImage(this);
#region Search Criteria
this.mUIAbmeldenImage.SearchProperties[HtmlImage.PropertyNames.Id] = null;
this.mUIAbmeldenImage.SearchProperties[HtmlImage.PropertyNames.Name] = null;
this.mUIAbmeldenImage.SearchProperties[HtmlImage.PropertyNames.Alt] = "abmelden";
this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.AbsolutePath] = "/webakte-vnext/content/apps/Ordner/images/logOut.png";
this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.Src] = "http://localhost/webakte-vnext/content/apps/Ordner/images/logOut.png";
this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.LinkAbsolutePath] = "/webakte-vnext/e.consult.9999/webakte/logout/index";
this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.Href] = "http://localhost/webakte-vnext/e.consult.9999/webakte/logout/index";
this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.Class] = null;
this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.ControlDefinition] = "alt=\"abmelden\" src=\"http://localhost/web";
this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.TagInstance] = "1";
this.mUIAbmeldenImage.WindowTitles.Add("Akte - Test Akte Coded UI VS2010");
#endregion
}
return this.mUIAbmeldenImage;
}
}
Although I am running Visual Studio 2012, I find it odd that we started experiencing the same problem on the same day, I can not see any difference in the DOM for the Coded UI Tests I have for my web page, but for some reason VS is saying the control is hidden and specifies the correct ID of the element it is looking for (I verified that the ID is still the same one). I even tried to re-record the action, because I assumed that something must have changed, but I get the same error.
Since this sounds like the same problem, occurring at the same time I am thinking this might be related to some automatic update? That's my best guess at the moment, I am going to look into it, I will update my post if I figure anything out.
EDIT
I removed update KB2870699, which removes some voulnerability in IE, this fixed the problems I was having with my tests. This update was added on the 12. september, so it fits. Hope this helps you. :)
https://connect.microsoft.com/VisualStudio/feedback/details/800953/security-update-kb2870699-for-ie-breaks-existing-coded-ui-tests#tabs
Official link to get around the problem :
http://blogs.msdn.com/b/visualstudioalm/archive/2013/09/17/coded-ui-mtm-issues-on-internet-explorer-with-kb2870699.aspx
The problem is more serious than that! In my case I can't even record new Coded UI Tests. After I click in any Hyper Link of any web page of my application the coded UI test builder cannot record that click "The following element is no longer available....".
Apparently removing the updates, as said by AdrianHHH do the trick!
Shut down VS2010, launch it again "Run as administrator".
There may be a field in the SearchProperties (or possible the FilterProperties) that has a value set by the web site, or that represents some kind of window ID on your desktop. Another possibility is that the web page title changes from day to day or visit to visit. Different executions of the browser or different visits to the web page(s) create different values. Removing these values from the SearchProperties (or FilterProperties) or changing the check for the title from an equals to a contains for a constant part of the title should fix the problem. Coded UI often searches for more values than the minimum set needed.
Compare the search properties etc for the same control in the two recorded tests.
Update based extra detail given in the comments:
I solved a similar problem as follows. I copied property code similar to that shown in your question into a method that called FindMatchingControls. I checked how many controls were returned, in my case up to 3. I examined various properties of the controls found, by writing lots of text to a debug file. In my case I found that the Left and Top properties were negative for the unwanted, ie hidden, controls.
For your code rather than just using the UIAbmeldenImage property, you might call the method below. Change an expression such as
HtmlImage im = UIMap.abc.def.UIAbmeldenImage;
to be
HtmlImage im = FindHtmlHyperLink(UIMap.abc.def);
Where the method is:
public HtmlImage FindHtmlHyperLink(HtmlDocument doc)
{
HtmlImage myImage = new HtmlImage(doc);
myImage.SearchProperties[HtmlImage.PropertyNames.Id] = null;
myImage.SearchProperties[HtmlImage.PropertyNames.Name] = null;
myImage.SearchProperties[HtmlImage.PropertyNames.Alt] = "abmelden";
myImage.FilterProperties[HtmlImage.PropertyNames.AbsolutePath] = "/webakte-vnext/content/apps/Ordner/images/logOut.png";
myImage.FilterProperties[HtmlImage.PropertyNames.Src] = "http://localhost/webakte-vnext/content/apps/Ordner/images/logOut.png";
myImage.FilterProperties[HtmlImage.PropertyNames.LinkAbsolutePath] = "/webakte-vnext/e.consult.9999/webakte/logout/index";
myImage.FilterProperties[HtmlImage.PropertyNames.Href] = "http://localhost/webakte-vnext/e.consult.9999/webakte/logout/index";
myImage.FilterProperties[HtmlImage.PropertyNames.Class] = null;
myImage.FilterProperties[HtmlImage.PropertyNames.ControlDefinition] = "alt=\"abmelden\" src=\"http://localhost/web";
myImage.FilterProperties[HtmlImage.PropertyNames.TagInstance] = "1";
myImage.WindowTitles.Add("Akte - Test Akte Coded UI VS2010");
UITestControlCollection controls = myImage.FindMatchingControls();
if (controls.Count > 1)
{
foreach (UITestControl con in controls)
{
if ( con.Left < 0 || con.Top < 0 )
{
// Not on display, ignore it.
}
else
{
// Select this one and break out of the loop.
myImage = con as HtmlImage;
break;
}
}
}
return myImage;
}
Note that the above code has not been compiled or tested, it should be taken as ideas not as the final code.
I had the same problem on VS 2012. As a workaround, you can remove that step, and re-record it again. That usually works.
One of the biggest problem while analyzing the Coded UI test failures is that the error stack trace indicates the line of code which might be completely unrelated to the actual cause of failure.
I would suggest you to enable HTML logging in your tests - this will display step by step details of how Coded UI tried to execute the tests - with screenshots of your application. It will also highlight the control in red which Coded UI is trying to search/operate upon.This is very beneficial in troubleshooting the actual cause of test failures.
To enable tracing you can just add the below code to your app.config file --

Convert a Visual Studio resource file to a text file?

I know there are tools to get text files to resource files for Visual Studio. But I want to get the text from my resource files to a text file so they can be translated. Or is there a better way to do this?
You could use Resx Editor, a small translation-oriented file editor.
Target audience: translators.
Supported file format: Microsoft RESX 2.0
Here is a link to Joannès Vermoel's (the author of the free tool) weblog entry about it.
In the end I just used a quick hack:
public class Export
{
public string Run()
{
var resources = new StringBuilder();
var assembly = Assembly.GetExecutingAssembly();
var types = from t in assembly.GetTypes()
where t != typeof(Export)
select t;
foreach (Type t in types)
{
resources.AppendLine(t.Name);
resources.AppendLine("Key, Value");
var props = from p in t.GetProperties()
where !p.CanWrite && p.Name != "ResourceManager"
select p;
foreach (PropertyInfo p in props)
{
resources.AppendFormat("\"{0}\",\"{1}\"\n", p.Name, p.GetValue(null));
}
resources.AppendLine();
}
return resources.ToString();
}
}
Add this code to the project which contains your.resx files (mine are in a separate "Languages" project) then use the following code to save the result into a .csv so that it can be loaded with a spreadsheet editor.
var hack = new Languages.Export();
var resourcesSummary = hack.Run();
var cultureName = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
using (TextWriter file = File.CreateText(#"C:\resources." + cultureName + ".csv"))
{
file.Write(resourcesSummary);
}
This does not allow you to import files from the .csv back to your .resx files so that they can be compiled. It would be nice to have a utility that would do that.
You can use Simple Resx Editor, it has some interesting features that will help you into the translation process.
Even though it is counter intuitive, it's a better idea to translate the exe rather than the resource file. Read why here:
http://www.apptranslator.com/misconceptions.html
You may want to have a look at Excel Resource Transfer. It is
an Add-In for Microsoft Excel to import and export texts from resource files.
There is a trial version. The full version costs 25,- Euro.
If you're doing this for a web project, a better way to do internationalization (including translation) is to use the i18n nuget package. Not only does work better with templates but it has other nice-to-haves like localized URLs.
Here's an example from the github repo:
<div id="content">
<h2>[[[Welcome to my web app!]]]</h2>
<h3><span>[[[Amazing slogan here]]]</span></h3>
<p>[[[Ad copy that would make Hiten Shah fall off his chair!]]]</p>
<span class="button" title="[[[Click to see plans and pricing]]]">
<a href="#Url.Action("Plans", "Home", new { area = "" })">
<strong>[[[SEE PLANS & PRICING]]]</strong>
<span>[[[Free unicorn with all plans!]]]</span>
</a>
</span>
</div>
Running a post-build task generates a PO database that can be provided to translators that use PO editing tools (like POEdit) to provide locale-specific text.
You could use winres.exe from Microsoft, it lets you localize windows forms without having to use Visual Studio. It doesn't save the resources to a text file, but the idea is that the localization expert for each culture could use the tool to generate a localized versions of the application.
Here's a better explanation:
http://msdn.microsoft.com/en-us/library/8bxdx003(VS.80).aspx

Resources