Getting started with Web Automation using Selenium
Conventional yet powerful tool
Putting the system to the test in the face of adversity is a challenging task, and you'll need a tool to assist yourself. It is one of the most widely used automation testing tools. You've come to the right place if you're new to this tool and want to learn how it works from the ground up. In this blog, I'll give you a quick overview of the Selenium WebDriver Architecture and how to set it up in Ubuntu.
What is Selenium?
All the updates are easily available and do not require any specific training. Thus, this makes WebDriver a budget-friendly tool.
What is Selenium WebDriver Architecture?
The architecture consists of four layers:
- Selenium WebDriver Client Libraries - When we choose a tool, the first thing that comes to mind is: Does this tool support the language that I am familiar with? Yes, Selenium Web driver supports a wide range of languages, including Java, C#, Python, Ruby, PHP, and others, and allows testers to automate in their comfort zone.
- Browser Drivers - We have a browser driver for each of the browsers that Selenium supports. As a result, these browser drivers communicate with their respective browsers and carry out commands by decoding Json sent by the browser, and then the response is given back in the form of the HTTP response.
- Browsers - Selenium can only run tests on browsers that are installed locally, either on the client or server machines. As a result, you'll need to install a browser on your system and it supports a variety of browsers, such as Chrome, Firefox, Internet Explorer, and others.
Setting up Selenium-WebDriver for Python on Ubuntu is simple; we'll go through everything you need to know step by step.
- Python (version 2.X or 3.X should be okay. I am using Python 3)
- Check whether python is already installed on your system by typing python3 –V command into your terminal.
- If you get Python 3..on your terminal, that means the Python is already installed and if it is not installed, you have to run sudo apt-get install python3.9 –y or apt install python3-pip.
Install Selenium package
- Run pip3 install selenium
Steps for installing Firefox driver
- Since the default browser on Ubuntu is Firefox, I would like to use Firefox in my case. Download the driver based on the Firefox version installed on your system. You can check the version by entering ALT >> Help>>About Firefox
- Go to the https://github.com/mozilla/geckodriver/releases and in this guide, we will use wget to download the file. To download, make a right-click on get and copy the link.
- Now open the terminal and copy-paste the below command and replace it with the right Firefox link wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriv er-v0.30.0-linux64.tar.gz.
- Extract the tar file by running tar -xvzf geckodriver-v0.30.0-linux64.tar.gz
- Make it executable using chmod +x geckodriver
- Move geckodriver binary to your system PATH by running mv geckodriver /usr/bin/local
Run the Python Script
- Here is an example of a script I have written in Python, which will launch the browser automatically and open the Glide Invest site, and will print the title on the console
- I'm using the pycharm editor here, but you may use whichever editor you like.
Screenshot of selenium script
On the Ubuntu operating system, we covered the fundamentals of getting started with selenium and python. In the next blog, we will see how to set up a project and write a script in detail for automating web-based applications.