Selenium testing

Automatic tests with Selenium – part #1

Testing is often the last thing that Developer thinks about. But with Selenium WebDriver it’s easy and even spectacular while running.

In short

With Selenium you automate the browser. So you can tell it to click wherever and do whatever you can do with your browser. But Selenium will do it for you. Moreover it’ll do it faster and every time in the the same exact way – repeatedly. We have a bunch of APIs to use c#, ruby, python, perl and even javascript. We also have a PHP API created by facebook group. Thanks guys.

Let’s test

I choose python, since it’s native in Ubuntu. First we need to install selenium driver:

pip install selenium

And we can check if it works. Let’s create a python file

sudo touch
sudo chmod +x
sudo vi

copy and paste this contetns

#!/usr/bin/env python

from selenium import webdriver

driver = webdriver.Chrome()
inputElement = driver.find_element_by_name("q")

then run your first test


As a result we should see the browser window open and Google page with selenium phrase searched.

What we just did

We created a driver for Chrome browser.

driver = webdriver.Chrome()

Next we tell the browser to open url


And then we get the search input by it’s name and enter “selenium” phrase.

inputElement = driver.find_element_by_name("q")

You can read some more about WebDriver.

Ok, let’s go to Automatic tests with Selenium – part #2.