dongyue0263 2012-11-04 22:27
浏览 109
已采纳

自动化网页测试

I want to automate some tests on my webpage, mainly filling out forms with invalid data and see what happens. Is is possible with Javascript? If not, is it possible with PHP? The script should handle sessions and cookies.

Here is a very simple example that has 3 pages. In the first you should enter 'x' and click submit, in the second you should enter '3' and click submit. If that was successful the last page should show you "you got it!". Can that be automated so that I load a script and see the "you got it" right away? Please note: This has no cookies\sessions for simplicity, but I want an answer that dose support those.

  • I have tried making another page with iframe that includes the site above. But could not gain access to the elements inside the iframe
  • I have tried making an PHP script using cURL, that sends requests, but I could not forward cookies.
  • I have posted an comment on this answer but didn't get a reply.

For your convenience, here is the code: (you don't really need it, but just in case..)
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"... :)';
}
?>
  • 写回答

3条回答 默认 最新

  • dongyuhui0418 2012-11-04 22:30
    关注

    PHP-based solution: Won't test from the front-end, only the server-backend, hence won't emulate real input.

    JS: Will not persist across pages.

    Hence, you are either looking for a browser-extension or a standalone utility separate from the browser entirely.

    You could try:

    1. Sikuli which however is generic, not targeted at web-pages, but at GUIs in general.
    2. WatiN or Selenium
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗