Start with Python WebDriver - 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 here “ClickHere
   2. Install easy_install using code from link "Click to download" .Just copy code from url and past in a new      created python file like “setup.py”
  3. Put “setup.py” file in where python installed and run “setup.py” file as below command
      >python setup.py
  4. After successfully execution a Scripts folder created under Pyhon installed directory. setup “Script”    folder path in your machine.
  5. 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 webdriver scripts. Copy and past below code in  python file like “PythonWebdriver.py”

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re

class GoogleTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.google.co.in/"
        self.verificationErrors = []        
    
    def test_untitled(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("gbqfq").clear()
        driver.find_element_by_id("gbqfq").send_keys("Testing")
        
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

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

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


2 comments:

  1. Hi

    I am using selenium Python wedriver and I need to read data from xls file and fill in the webpage, Can you please help me out with the exact connection code in python.

    ReplyDelete
  2. I am a novice automation tester
    I want to know how do we can generate a html report by using python and selenium test execution

    ReplyDelete

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