Start with Python Selenium RC - Procedure to create first test script for the beginners

Prerequisite:
  1. Python should be installed and set up path in your machine. Download Python from http://www.python.org/getit/
  2. Download Selenium2 jar file from http://seleniumhq.org/download/.
  3. Install easy_install using code from link "http://peak.telecommunity.com/dist/ez_setup.py" . Just copy code from url and past in a new  created python file like “setup.py”
  4. Put “setup.py” file in where python installed and run “setup.py” file as below command  >python setup.py
  5. After successfully execution a Scripts folder created under Pyhon installed directory. setup “Script”    folder path in your machine.
  6. Install selenium 2 in your system using command: > easy_install selenium

How to create and Run scripts:

Now your system is ready to execute python selenium RC scripts. Copy and past below code in  python file like “PythonSelenium.py”

from selenium import selenium
import unittest, time, re

class PythonSelenium(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*chrome", "https://www.google.co.in/")
        self.selenium.start()
   
    def test_Google(self):
        sel = self.selenium
        sel.open("/")
        sel.type("id=gbqfq", "testing")
        sel.click("id=gbqfb")
   
    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()


Open command prompt goto “selenium-server-standalone-2.**.0.jar” and run below command
        Java –jar selenium-server-standalone-2.**.0.jar     

Below screen should be appear.


Open command prompt go to scripts directory and run command “python  PythonWebdriver.py” 
After successfully execution your screen should be look like below screen.



No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution