Testing page login

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

First, I need to be able to access the pages, then I need to find the login form and submit the information. I am currently planning to print true / false for each test (accessibility and login) and then fill out the forms myself. I hope I can write something to automate this later.

I thought about using Ruby, although I haven't coded it yet, it looks like it would make things easier. I've worked the most with Java, although I have experience with C ++ and a bit of experience with C.

Any advice?

+1


a source to share


5 answers


You can use Selenium IDE . It is a recording and playback tool for simple web tests that you can save as a Selenium RC test in any language you want. I hope this helps



+1


a source


The urllib2 python module allows you to interact with an HTTP server. You can use urrlib2 to read the page to check the content. You can POST the urlencoded data and check the content.

Also, Python has a simple unittest library to 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()

      

+1


a source


Ruby, PHP, and Python have easy-to-use HTTP libraries that make this operation pretty straightforward. Any of these languages ​​will work fine.

0


a source


If you want to do it this is Ruby, Mechanize Gem is perfect for this

require "mechanization"

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 `

0


a source


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

Handles cookies, HTTPS, etc.

Things are good.

0


a source







All Articles