Selenium: Setup Chrome Driver

Here is how to setup chrome driver for selenium functional testing. If you are using firefox, leave this post because selenium by default provide the driver. 😀

Download the driver from https://sites.google.com/a/chromium.org/chromedriver/home
adjust with your OS. After that, extract to your project, for example following my project dir structure.

- myproject
    - myproject
        - apps
            - member
                - tests.py
    - chromedriver

then write followed below.

import os

from django.test import LiveServerTestCase
from selenium import webdriver


class MyTestCase(LiveServerTestCase):

    def setUp(self):
        # Get your chrome driver path location.
        current = os.path.dirname(__file__)
        driver_path = os.path.abspath(
            os.path.join(current, '..', '..', '..', 'chromedriver')
        )

        self.selenium = webdriver.Chrome(driver_path)
        self.selenium.maximize_window()
        super(MyTestCase, self).setUp()

    def tearDown(self):
        self.selenium.quit()
        super(MyTestCase, self).tearDown()

    def test_open_the_app(self):
        self.selenium.get(self.live_server_url)

NB: Don’t forget to install the selenium. 😀

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s