Browsing Category

Automation

Selenium Webdrive in Python Tutorial

Tutorial: Getting Started with Selenium in Python

The best things in life are free, and for Software Testers this is particular true thanks to Selenium. Being a portable testing framework for web applications, Selenium allows us to interact with web elements either without coding skills at all (Recording Tool) or with an easy to learn test domain-specific language (Webdriver). It is perfect for automating the boring stuff!

I’ll show how easy is to get started in Automation Testing using basically only Selenium and Python.

This tutorial assumes that the user is running a similar working environment with the following software:

  • Debian based Linux distribution, like Ubuntu
  • Python 2.7.x
  • Python Pip
  • Firefox 54

Don’t get discouraged if you have an operative system different than Linux. Python and other tools can be installed in other Operative Systems. One of the greatest advantages of these type of software is that they are multi-platform!

Creating an isolated Python environment with Virtualenv

Virtualenv is a tool that allows to create an environment that has it’s own isolated installation of Python and libraries. This is useful if we want to avoid having compatibility issues between projects that require different version of a particular library or simply because we don’t want to mess our global installation.

To install Virtualenv, open a new terminal and type the following command:

pip install virtualenv

Then we create a new folder for your Virtual Environment:

virtualenv selenium

To start using your new virtual environment enter (within your project folder):

source bin/activate

To exit from the your virtual environment, simply type:

deactivate

Installing Selenium with pip

Once our Virtual Environment is up and running, we can proceed to install Selenium via pip:

pip install selenium

Grabbing Geckodriver

In order to run our tests in Firefox, first we must install the Geckodriver. To check the latest version available visit:

https://github.com/mozilla/geckodriver/releases

Download the version corresponding to your Operative System and Architecture using wget, example:

wget https://github.com/mozilla/geckodriver/releases/download/v0.17.0/geckodriver-v0.17.0-linux64.tar.gz

Then we uncompress the file:

tar -xvzf geckodriver*

Also we make the file executable:

chmod +x geckodriver

Finally we move the Geckodriver to /usr/local/bin/ so it is accesible for Selenium to use:

sudo mv geckodriver /usr/local/bin/

Running a quick test

Now we are ready to test our environment, let’s write a small script that opens a new browser and navigates to Google:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://google.com')

Feel free to use your favorite code editor, since is a simple script you can even use nano. Once you’re done writing your script, save your changes and go back to Terminal and run your script:

python demo.py

If all went well a new firefox window should open and the browser should display google’s homepage. Congratulations! You wrote your first Selenium Script! Stay tune for more tutorials.

Transitioning from Manual to Automation Tester

Transitioning from Manual to Automation Tester

Start coding may seem like a daunting task, perhaps an intimidating experience, specially for those who look to transition from Manual to Automation Tester. Those who decide to make the journey may ask themselves “Where do I start?”. We start by choosing our tools.

Choose your poison

For those who had never write code before, picking your first programming language is very important. From the wide array of options out there, Python fills the bill perfectly. Python uttermost characteristic is its high readability, meaning you don’t have to waste a lot of time and effort trying to memorize complex syntaxes.

Code less, do more with Python

Not only Python is easy to read but also requires less code to get things done. Please, observe the following code examples:

Java

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}

Python

print("Hello, World!")

Both code examples return the traditional first program phrase “Hello, World!”. However, notice how Python just needs a single line of code to get things working, not to mention the syntax is much more easier to read than its Java counterpart.

Stop doing the boring stuff as an Automation Tester

As described in my previous blog post “The importance of automation to avoid doing the boring stuff“, automating mind-numbing tasks can save your sanity as well as your company’s money. This is quite true in the Software Testing area, if you had been working for a while as a Tester, probably you had the chance to test a considerable amount of test cases where only changing factor are parameters like Browser, User Type, etc. This can get boring fast, doesn’t it?

I picked up a programming language, now what?

After “choosing your poison” and spending some time with it, figure out what would like to automate, is it the login progress or a lengthy form? As we choose our target, also we need to pickup some additional tools. If we are going to automate the process of filling up a form, we need a tool that can handle a web application. Tools like Selenium comes to mind.

Selenium is a framework for testing web applications, which provides support to write tests in the most popular programming languages out there, like Python or Java. The tests run against a web browser and deploys on Windows, Mac and Linux.

Where to go from here?

“Practice makes the master” – Patrick Rothfuss, The Name of the Wind

Practice! Pick up a web application you would like to automate, figure out how to automate each and every component. Be a sign up form or login screen, learn how to interact with the elements shown in the web application. Don´t be afraid to make mistakes, constant practice will get you to a proficient level.

The importance of automation to avoid doing the boring stuff

The importance of automation to avoid doing the boring stuff

Repetition eventually leads to errors, especially if it involves mind-numbing tasks. People have a great displeasure of having to perform these types of tasks, that’s where automation comes into play. Imagine having to execute several test cases that involve verifying that all mandatory fields are in fact, mandatory, or that all drop-downs contain all expected options. These type of scenarios are not uncommon in a typical application that deals with a lot of forms. Financial or Insurance related applications come to mind.

Nowadays we have access to a wide range of automation tools that allow us to compare current and expected behavior. Tools like Selenium, enable us to quickly build a set of automated test cases that we can run whenever we need, again and again. Although Selenium itself is not a programming language but a framework, we can implement a quick set of automated test cases using virtually any major language that’s out there in the market.

But.. automation? I can’t code!

Python can ease the anxiety of not having strong coding skills. Being a highly readable language, meaning no need to learn complex syntaxes, Python can be the best choice for people with no programming background at all. Not only is easier to read but also requires less code to get things done.

Automation doesn’t have to be a complicated effort, at least not with the right tools. Implementing Automation can be highly beneficial, not only saves the sanity of engineers but also saves money. Having engineers spend their time on more meaningful tasks can bring big rewards in the long run.