Usability tests with Selenium – Install

Usability tests are very important to single page applications (SPA), so I am gonna write some tutorials about Selenium, which is a test application suite for web apps.

First things first. Let’s see how to install Selenium in Ubuntu Linux environment. Most steps will be the same for Mac and Windows, since I will make use of PIP/python. If you use Windows, you will need to install python first. Check python.org for that.

1- Installing Pip:

Open your Terminal, and download get-pip script with curl.

curl -O https://bootstrap.pypa.io/get-pip.py

Then run the script. Obs: If you run the script with the –user flag, pip will be installed only for your current user, in .local/bin folder.

python get-pip.py --user

The output will look like this:

Collecting pip
	Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)
Collecting setuptools
	Downloading setuptools-26.1.1-py2.py3-none-any.whl (464kB)
Collecting wheel
	Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
Installing collected packages: pip, setuptools, wheel Successfully installed pip setuptools wheel

After this installation, we need to add the .local/bin folder to the PATH environment variable. You can use the .profile or .bashrc files. I like nano, so in Terminal (Obs: in Mac I would to use .profile):

nano ~/.bashrc

At the very last line of the file I add:

export PATH=~/.local/bin:$PATH

In case you don’t know, this command will add your local folder .local/bin to the existing PATH variable. From now on, every time you type a command in the Terminal, the system will look into the binaries located in .local/bin to see if the executable file is in there to run it. And that is the case with PIP, the pip command is in this folder. Save the file. Now reload the PATH typing:

source ~/.bashrc

If everything is right type:

pip -v

If the help appears you did everything right! 🙂

2- Now we Install Selenium.

I like the –user to keep the installation files only in the user folder. The -U flag, will also update the pip directory:

pip install -U selenium --user

After installing Selenium you need to install the WebDrivers interface for your desired Browser. I use mostly Chrome for development, so my example will be to download and install Chrome driver, but the steps are the same for all other browser. At the end of the post, you will find helpful links to download the other drivers.

2.1- Get your driver interface.

For Chrome we can go to the https://sites.google.com/a/chromium.org/chromedriver/downloads and download the most recent release. It will be a zip package. You can unzip it, and place that executable file where ever you want in your system, as far as the destination is listed in the PATH. I added my at the same .local/bin folder where pip is also located. As the name suggests that folder is meant to hold executable files anyway.

Once you place this executable files in a right place, you are good to go!

3- Let’s test.

Run the first test in the python console! In Terminal just call:

python

And there try the following:

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://google.com')

When you set the browser variable, a Chrome window will pop up. Don’t worry! It is exactly what we want! The command get() will make the Chrome window to access Google’s page!

Perfect! We did the first step. Now we can control a browser page through script, and now we can automate our usability tests.

Next posts more about how to do it.

REFERENCES:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-linux.html

https://www.rosehosting.com/blog/how-to-install-pip-on-ubuntu-16-04/

https://pypi.python.org/pypi/selenium

https://docs.python.org/3/library/unittest.html

unittest introduction

http://docs.python-guide.org/en/latest/writing/tests/

https://jeffknupp.com/blog/2013/12/09/improve-your-python-understanding-unit-testing/

http://www.seleniumhq.org/docs/03_webdriver.jsp

 

WEBDRIVERS INTERFACES:

Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads

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

Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/

Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

 

Youtube:

Browser elements & Operations: https://youtu.be/ph3NJm4Z7m4?t=21m31s

Selenium Methods and Functions: https://youtu.be/ph3NJm4Z7m4?t=32m1s