Sunday, July 27, 2014

WebDriver with Python using Splinter and Nose

Till now I have been writing all my post in java, However after spending almost an year in python, Why not I write post in python. So here is my first post about how to use WebDriver in Python. If you are reading this please don't forget to put the comment.

I have used two frameworks for writing Webdriver tests in Python

Splinter is basically a wrapper around the Webdriver API, which ease you to write code as compared to webdriver.

For example if you have to fill a form with web driver, your code might look
elem = browser.find_element.by_name('username')

However, if you use splinter, it will look like this
browser.fill('username', 'janedoe')

Better, Aint't it ?

Nose is an unit testing framework extended from python unittest. As I told you it's extended from unittest which mean it provides all the features provided by unittest plus few more

Enough of theory, let's see the code.

from import assert_true

__author__ = 'Gaurang_Shah1'

import unittest
import splinter

class GoogleTest(unittest.TestCase):

    def setUp(self):
        self.browser = splinter.Browser()

    def tearDown(self):

    def test_google_search(self):
        google = GooglePage(self.browser)'splinter - python acceptance testing for web applications').verify_text_on_page(''')

class GooglePage(object):

    def __init__(self, browser):
        self.browser = browser

    def search(self, keyword):
        self.browser.fill('q', keyword)
        return self

    def verify_text_on_page(self, text):


Post a Comment