Perl 是否有与 Java 的 Robot 类 (java.awt.Robot) 等效的东西?
5 回答
Alternatively, you can surely use the WWW::Mechanize module to create an agent as we do here at work. We have a tool called AppMon that is really just a dramatized wrapper around Mechanize.
The Mechanize module allows you to use scripts that look a lot like this:
use WWW::Mechanize;
my $Agent = WWW::Mechanize->new(cookie_jar => {});
$Agent->get("http://www.google.com/search?q=stack+overflow+mechanize");
print "Found Mechanize" $Agent->content =~ /WWW::Mechanize/;
and will result in "Found Mechanize" being output. This is a very simple script, but rest assured you can interact with forms quite well.
You can also move to Ruby and use Watir, or Selenium as another alternative, albeit not as interesting (in terms of coding) or automate-able. Selenium has a firefox extension that is quite useful for creating the selenium scripts and can change them between the various languages that it supports, which is pretty extensive in terms of automation.
Update - Nov 2016
Although I haven't had much of an opportunity to play with it, there are also webdriver packages for most languages, and Perl is no different.
如果您正在寻找一种方法来控制浏览器以进行功能测试,Selenium 具有 Perl 绑定:http ://selenium.openqa.org/
对于 X (Linux/Unix),有X11::GUITest。
对于 Windows,有Win32::CtrlGUI,尽管安装它的先决条件可能有点棘手。
在 Windows 上,我一直使用Win32::GuiTest。