How can I automate website testing with Perl? [duplicate] - perl

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Integration Testing for a Web App
I've recently delved into Perl and I'd like to learn how to automate web site testing. To that end I'd appreciate answers to the following:
What modules from CPAN should I look into? Is there something similar to Watir (I know there's a Windows only port of it in Perl)?
I'm using a Windows system, so does it matter if I use ActivePerl or Strawberry Perl?
What books should I look into (aside from "Perl Testing: A Developer's Notebook")?
Edit:
The web application is written in Java
I want to test the application's web GUI, which makes use of javascript/ajax & some flex/flash

WWW::Mechanize, WWW::Selenium and LWP::Simple just to name a few.
ActivePerl is more user friendly than Strawberry when it comes to downloading CPAN modules, but at the end of the day they are both equally as good.
I haven't come across any books on the subject; perhaps a tutorial is what you need.

Are you interested testing the WEB GUI itself via http calls or individual Perl modules via calling Perl code directly?
For the former, Selenium - which AFAIK is not Perl specific at all - seems to be the accepted Best Practice (see Integration Testing for a Web App link helpfully provided by Ether ). It has a Perl CPAN module for integration, mentioned in the same SO question.
You can of course do your own testing frameworks, e.g. implement http calls via WWW::Mechanize. But that would not work with JavaScript-enabled web sites (are there any left that aren't?) since you need a JavaScript engine, either provided by the browser (Selenium's approach) or something embedded which AFAIK Perl doesn't actually have, though Java does.
However, there are non-http approaches to testing Perl side code of the web apps as well:
Have all non-presentation logic nicely modularized away, and test it as usual using Test::More or your other favorite test frameworks.
Test presentation (or presentation+logic) by using your web framework in command line mode, emulating running on web server. CGI.pm allows that, as well as EmbPerl. Not sure about Catalyst apps.

Related

Perl web crawling framework

I've been using Perl for years to crawl and scrape for various different purposes, one thing that's always bugged me is while there are tons of great CPAN modules for small-scale scraping and crawling, such as LWP, WWW::Mechanize, Web::Scraper, AnyEvent::HTTP, and now Mojo::UserAgent, there don't appear to be any crawling frameworks in the same way as there are for other languages.
For example Apache Nutch (/Droids) & Scrapy (Python).
Anybody know of any projects at all in Perl that are equivalent?
You probably need to take a look at modules such as HTML::Robot::Scraper or
HTTP::UserAgentString::Robot and I think there are a few more with robot in their name.

Building a professional application in Perl?

I've built a set of tools I use in my day-to-day work and I would like to make them look a bit more "professional" in order to sell them to financial institutions.
At the moment these tools are written in Perl and are executed from a DOS command line, it's extremely efficient but it doesn't look very attractive.
So, I would like to add a user interface to it but I don't really know what to use for language knowning that :
A Perl CGI interface hosted on the web is not an option since the information to be given as input is quite sensitive.
It would be ideal to sell it as a package/executable.
I don't really like the Perl/Tk interface.
I'm ok with rewritting the application in another language but I would prefere to reuse the main modules in Perl since it's very powerful with regular expressions and lists/arrays.
What would you advise me to do ?
Thanks,
Lory
If you want a non-web-based GUI, and don't like Tk, there's also Wx, which is a wrapper for the wxWidgets GUI toolkit.
However, web applications nowadays can be really easy to create (using a modern framework). Take a Mojolicious application, for example: Mojolicious carries no dependencies other than Perl 5.12.x, and provides its own web server (Hypnotoad). You can start by generating a "Lite::App", which is a simple self-contained single-file application, and then grow it to a bigger distribution later on as the need arises. It even comes with tools to convert your application to a conveniently packaged distribution that can be installed as easily as any CPAN module.
So that leaves the issue of security. User authentication, IP whitelisting, local network only... there are many ways to make a web application "for internal use only" if that's what you need.
You might just throw together a web-application prototype, and once you determine customer interest in your product, invest the substantial time in writing it as a Windows GUI application.
Continuing on from DavidO's answer, because the current web microframeworks for Perl (I prefer Dancer over his suggestion of Mojolicious, but both are good and largely equivalent) contain their own bundled web mini-servers, they also allow for the app to easily run entirely on the local machine.
Since these mini-servers default to a non-standard port (usually 3000 or 5000) by default and you can easily set them to a different port, they can be isolated by firewalls relatively easily, ensuring that nobody can connect to them remotely. You can also, of course, include and IP address check in the app and have it reject any requests that don't originate from localhost.
My guess is that the target system will be Windows. Use a RAD (Rapid Application Development) platform to develop a GUI. Examples for such a platform are Delphi or .NET with C# or VB. For bundling the Perl part, consider using a tool called perl2exe.
It doesn't sound like your scripts should require a web server. Also, consider the installation hassle. Only guessing as you're not giving much information about what your scripts are doing.
I am using the Cava packager to deploy my Perl-written tools. You can even generate an installer executable with just some mouse-clicks. It works pretty well with strawberry Perl and wxPerl on Windows.

Migrating to Visual Basic to perl - working with user interfaces

I've been around Visual Basic for years in high school, and I've grown up with the IDE supplied by Microsoft. It'd wonderful, but the educational and "working-model" editions of VB available to me through school don't allow me to redistribute software, as part of the EULA with Microsoft.
I instead find myself working in perl to design programs for friends and family, and it works fairly well, but I don't have a firm grasp on building user interfaces yet. I understand I could design user-interfaces with tcl/tk for perl, but the notion of coding all of that by hand is a bit daunting to me. That brings me to my question.
Do you have any suggestions for a tool I could use that would allow me to build GUIs for my perl programs?
Thanks in advance!
In addition to what tsee suggested, you can have a look at :
Perl/Qt (using Qtdesigner) and Perl::GladeXML (using Glade)
With Glade and Qtdesigner, you can generate a XML file that will describe your user interface and it will be a matter of hooking your perl code to widget's events.
I don't think you will find something as simple and well integrated for Perl as the Visual Basic GUI builder. A couple of pointers:
wxGlade can be used to design GUIs for the Wx GUI toolkit (for Perl, not only Python).
For Win32::GUI, you can use the GUI Loft to achieve something similar.
I think there's a bunch of other GUI builders including at least one for Tk, but I don't remember the name.
Either way, I believe you will have to accept that you have to do more coding vs. designing when compared to VB. The upside is that if you use Tk or Wx, your programs may well be portable to all major operating systems.
For a Perl-specific development environment, you might want to check out Padre, which is itself written in Perl using Wx. It's under active development, so eventually, somebody will probably integrate a GUI builder, too.
Frankly, having thought about GUIs for years and never getting round to them, I've found the best way to distribute GUI apps with perl is to use Catalyst, its built in server and for windows users, distributing it with Strawberry Perl (the professional edition comes with Catalyst included). For Linux or Mac users a local::lib installation to pull in the required cpan modules. Optionally bundle in a copy of portable firefox if you want not to have the usual web development pain caused by internet explorer.
tl;dr; Sidestep the whole issue by going for web development with a framework that comes with its own standalone server.

How do I create CGI scripts with Perl?

I am creating a website and done with some HTML stuff, but I am thinking to create site using CGI and Perl scripting. I don't have much idea on CGI scripting. Can anyone please suggest me how to create a CGI script and how to create web pages with that?
Try Ovid's CGI Course - it's a good start. "A Beginner's Introduction to Perl Web Programming" is also a good reading, but with less information.
Later you can try framework like CGI::Application - it should be easy even for a beginner.
Have a look at A Beginner's Introduction to Perl Web Programming on perl.com.
I would recommend you make use of tools like Template Toolkit or Markapl to make the process of producing and maintaining your HTML view much simpler.
And moving forward you might want to consider looking at using a web framework ranging from something very light like Squatting to a powerful beast like Catalyst.
CGI is a standard to interface a webserver and a content provider or external application (let's say a Perl script, a compiled program), I think you better study Perl to code some CGI.
This link is a beginner guide to get started with CGI coding in Perl.
Also if you are beginner in Perl you might look to some other scripting language more dedicated to web, the best example is PHP. But if you are already experienced Perl CGI, the CGI.pm is nice also.
As far as I understand your question, you say that you wrote your own web server and now want to implement CGI!?
These links should help you:
CGI Specification
How to implement CGI in a Web Server
Edit: Check the original question before downvoting me.

What languages can be used to make dynamic websites?

So, there are several languages which will allow you to create a website, as long as you configure the server(s) well enough.
To my knowledge, there is:
PHP
ASP.NET
Ruby(on rails, what is
that all about?)
And thusly, my knowledge is limited. Ruby and ASP, I've only heard of, never worked with. If there are other languages, I suppose they have some way to make files containing the needed html. It would then suffice to add a line to the Apache config to associate the file-extension.
And if other languages: are there any notable characteristics about the one(s) you mention?
ANY language can be use to make a dynamic website - you could do it in COBOL or FORTRAN if you were twisted enough. Back in the olden days (about 10 years ago) most dynamic websites were done with CGI scripts - all you needed was a program that could read data from standard input and write data (usually HTML) to standard output.
Most modern languages have libraries and frameworks to make it easier. As well as the languages you have already mentioned, Java, C# and Python are probably the most common in use today.
Typically a web framework will have:
a way of mapping URLs to a class or function to handle the request
a mechanism for extracting data from a request and converting it into an easy to use form
a template system to easily create HTML by filling in the blanks
an easy way to access a database, such as an ORM
mechanisms to handle caching, redirections, errors etc
You can find a comparison of popular web frameworks on wikipedia.
How can you forget Java ? :)
Python
It runs on Windows, Linux/Unix, Mac OS X, and has been ported to the Java and .NET virtual machines.
Python is a perfect scripting language for web applications, e.g. via mod_python for the Apache web server. With Web Server Gateway Interface a standard API has been developed to facilitate these applications. Web application frameworks or application servers like Django, Pylons, TurboGears, web2py and Zope support developers in the design and maintenance of complex applications. Around libraries like NumPy, Scipy and Matplotlib, Python is a standard in scientific computing.
Among the users of Python are YouTube and the original BitTorrent client. Large organizations that make use of Python include Google, Yahoo!, CERN, NASA,and ITA.
This could be for your interest.
Virtually thru CGI all programming languages that produce output may use for web page generation.
Basically, you can use any language (if you are hosting your own server)
Very closely related and very interesting is this article where LISP has been used to build a very succesfull website.
Python has a 3rd party module CherryPy which can be used with or without a http server.
Amongst others: Erlang (YAWS, Mochiweb), Python
JSP has the advantage that it automatically wraps your code in a servlet, compiles that to bytecodes, then uses the just-in-time Java compiler to recompile critical sections into native object code. Not aware of any alternative which allows optimizes your work automatically in this way.
Also allows you to develop and deploy on any combination of Windows, Mac OS X, or Linux.
If you'd like to choose one for the beginning, you should check out PHP first. It gives you the basic clues about how dynamic sites work in general.
After you've become familiar with the basics, I recommend ASP.NET.
Fist off, you should know that ASP.NET is a technology and not a language. (It actually supports any language that can be used on the .NET platform.) Also it is not to be confused with classic ASP. (The old ASP was much more like PHP.)
ASP.NET is very easy to begin with, and after you have some clues about its concepts, you can always dig deeper and customize everything in it. The http://asp.net site is a very good starting point, if you are to learn it. I think it is really worth the effort, because even if you choose not to stick to it, it will give you some interesting ideas and concepts.
I tell you its most important advantages:
The code is compiled (and NOT interpreted like PHP), and it has a very good performance. (In a performace comparsion, it is 10-15 times faster. http://www.misfitgeek.com/pages/Perf_Stat_0809.htm)
It can be run on Windows without effort, and on Linux / Mac / etc using the Mono project.
It implements the Separation of Concerns principle very well.
It has most of the general functionality you'll need built-in. (Such as membership, roles, database management, and so on.)