我应该如何对非JavaScript应用进行自动化测试?

4

我正在编写与JavaScript良好配合的控件,但它们甚至必须在没有JavaScript的情况下工作。现在,使用Selenium进行测试对我来说效果很好。但是,所有在浏览器中禁用JavaScript的测试都无法在Selenium中运行。是否有一种方法可以进行此目的的自动化测试?

5个回答

2

我不了解Selenium,但是通过NoScript Firefox扩展程序,您可以按域名禁用脚本。因此,您是否可以使用它来允许Selenium但禁用您页面的脚本?


1
Selenium 通过使用 Javascript 与网页进行交互来工作。这意味着如果您关闭 Javascript,Selenium 将无法运行。 - Alana Storm

1

1

WWW::MechanizeTest::WWW::Mechanize是两个Perl模块,可以实现这一点。

use Test::More tests => 5;
use Test::WWW::Mechanize;

my $mech = Test::WWW::Mechanize->new;

# Test you can get http://petdance.com
$mech->get_ok( "http://petdance.com" );

# Test the <BASE> tag
$mech->base_is( 'http://petdance.com/', 'Proper <BASE HREF>' );

# Test the <TITLE>
$mech->title_is( "Invoice Status", "Make sure we're on the invoice page" );

# Test the text of the page contains "Andy Lester"
$mech->content_contains( "Andy Lester", "My name somewhere" );

# Test that all links on the page succeed.
$mech->page_links_ok('Check all links');

0
如果只是普通的HTML而没有JavaScript,您可以使用常规的屏幕抓取技术来比较从服务器下载的HTML和您期望的内容,无需在浏览器中进行测试。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接