Automate a webpage testing
<p>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.</p>

<p><a href="http://www.cs.bgu.ac.il/~kahilm/myForms/" rel="nofollow">Here</a> 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? <strong>Please note</strong>: This has no cookies\sessions for simplicity, but I want an answer that dose support those.</p>

<ul>
<li>I have tried making another page with <code>iframe</code> that includes the site above. But could not gain access to the elements inside the <code>iframe</code></li>
<li>I have tried making an PHP script using <a href="http://php.net/manual/en/book.curl.php" rel="nofollow">cURL</a>, that sends requests, but I could not forward cookies.</li>
<li>I have posted an comment on <a href="http://stackoverflow.com/questions/189288/automate-getting-report-from-webpage/189358#comment17960209_189358">this answer</a> but didn't get a reply.</li>
</ul>

<p>For your convenience, here is the code: (you don't really need it, but just in case..)<br>
<strong>index.html</strong></p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
First page: please enter x
&lt;form method="post" action="next.php"&gt;
&lt;input type="text" id="id" name="id" /&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;
&lt;html&gt;
</code></pre>

<p><strong>next.php</strong></p>

<pre><code>&lt;?php
if(isset($_POST) &amp;&amp; isset($_POST['id']) &amp;&amp; $_POST['id']!='x'){
    echo '&lt;script&gt;window.location = "http://www.cs.bgu.ac.il/~kahilm/myNavigator/";&lt;/script&gt;';
}
?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
Second page: please enter 3
&lt;form method="POST" action="last.php"&gt;
&lt;input type="text" name="code" /&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;
&lt;/html&gt;
</code></pre>

<p><strong>last.php</strong></p>

<pre><code>&lt;?php
if(isset($_POST) &amp;&amp; isset($_POST['code']) &amp;&amp; $_POST['code']=='3'){
    echo 'you got it!';
}else{
    echo 'you sent something, please make it a "3"... :)';
}
?&gt;
</code></pre>
