tags:

views:

89

answers:

5

I have to access some pages at work and then log into them to report any problems. I was thinking of writing a program to do this.

First, I have to be able to access the pages, then I have to locate the login form and send the info. Currently, I plan on printing true/false for each test (accessibility and login) and then filling the forms myself. I'm hoping to be able to write something to automate this later.

I was thinking of using Ruby, although I haven't coded in it yet, it seems like it'd make the whole thing easier. I've worked the most with Java, though I have some experience with C++ and a bit of experience with C.

Any advice?

A: 

Ruby, PHP and Python all have easy to use HTTP libraries which make this kind of an operation pretty easy. Any of these languages would work fine.

Cody Caughlan
+1  A: 

You can use Selenium IDE. It is a record and playback tool for simple web tests, which you can then save as test for Selenium RC in any language you want. I hope it helps

bbmud
+1  A: 

The Python urllib2 module easily permit you to interact with an HTTP server. You can use urrlib2 to read the page to verify the content. You can do a POST with the urlencoded form data and verify the content.

Further, Python has a simple unittest library that will help you structure your tests.

class TestForm( unittest.TestCase ):
    def testFillInForm( self ): 
        data= urllib.urlencode( { field1="value", field2="value" } )
        response= urllib2.urlopen( "http://localhost/path/to/form", data )
        # check the response

if __name__ == "__main__":
    unittest.main()
S.Lott
A: 

If you want to do this is ruby, The Mechanize gem would be perfect for this

` require 'mechanize'

agent = WWW::MECHANIZE.new page = agent.get('localhost/path/to/form')

login_form = page.forms.first #assuming the first form is the one we want

login_form.username = 'myusername'

login_form.password = 'mypassword'

page = agent.submit(login_form)

puts page.body # just to see the results `

bigjust
A: 

I have found CURL to be really useful and easy to use as well under PHP. Easy to learn.

Handles cookies, HTTPS, etc.

All good.