我想在我的网页上自动执行一些测试,主要是填写无效数据的表单,看看会发生什么。是可以使用Javascript?如果没有,是否可以使用PHP?脚本应该处理会话和cookie。自动化网页测试
Here是一个非常简单的例子,有3页。首先输入'x'并点击提交,在第二个输入'3'并点击提交。如果这是成功的最后一页应该告诉你“你懂了!”。这可以自动化,以便我加载脚本并立即看到“你明白了吗?” 请注意:为简单起见,这没有cookies \ sessions,但我想要一个支持这些的答案。
- 我已经尝试制作另一页
iframe
,其中包括上述网站。但无法访问iframe
- 里面的元素我尝试了使用cURL来发送PHP脚本,它发送请求,但我无法转发cookie。
- 我对this answer发表了评论,但未收到回复。
为方便起见,这里是代码:(你并不真的需要它,但以防万一..)
的index.html
<!DOCTYPE html>
<html>
First page: please enter x
<form method="post" action="next.php">
<input type="text" id="id" name="id" />
<input type="submit" />
</form>
<html>
next.php
<?php
if(isset($_POST) && isset($_POST['id']) && $_POST['id']!='x'){
echo '<script>window.location = "http://www.cs.bgu.ac.il/~kahilm/myNavigator/";</script>';
}
?>
<!DOCTYPE html>
<html>
Second page: please enter 3
<form method="POST" action="last.php">
<input type="text" name="code" />
<input type="submit" />
</form>
</html>
last.php
<?php
if(isset($_POST) && isset($_POST['code']) && $_POST['code']=='3'){
echo 'you got it!';
}else{
echo 'you sent something, please make it a "3"... :)';
}
?>