Why Selenium is the Best Automation Tool - CNDRO.LLC
3248
post-template-default,single,single-post,postid-3248,single-format-standard,wp-custom-logo,theme-bridge,bridge-core-2.9.4,woocommerce-no-js,tribe-no-js,ehf-template-bridge,ehf-stylesheet-bridge-child,qode-page-transition-enabled,ajax_fade,page_not_loaded,,qode-title-hidden,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,columns-4,qode-child-theme-ver-1.0.0,qode-theme-ver-27.8,qode-theme-bridge,qode_header_in_grid,wpb-js-composer js-comp-ver-6.7.0,vc_responsive,elementor-default,elementor-kit-2634

Why Selenium is the Best Automation Tool

                                                         Photo by Joshua Sortino on Unsplash

This article will discuss why Selenium is the best automation tool. Selenium is an open-source automation testing tool used for automating tests to validate web applications on different web browsers. It supports different programming languages to create test scripts, such as Python, Java, C#, e.t.c. It also supports various browsers like Chrome, Mozilla, Firefox, Safari, e.t.c.

We can easily automate browser testing across these browsers using Selenium WebDriver. Selenium is well used by Developers because of the result derived from it. Now we will move further to discuss key reasons Developers use Selenium tool. After that, we’ll implement how we can use the tool.

Key Reasons to use Selenium Tool

  • Open Source Availability: One of the most exceptional reasons many Developers use this tool daily is that it’s publicly accessible and free. To use this tool, you don’t have to make any payment. The community keeps helping developers improve the web browser features and functionalities.
  • Language and Framework Support: We also have the aspect of language and framework support. For a Developer to utilize this tool, he can use any of his desired programming languages: Python, Java, C# e.t.c. As a Developer, you don’t have to worry about language support. You can use any major languages to carry out your test automation. Also, for every supported language in Selenium , there is an allocated framework designed to assist in writing test scripts. This was put in place to make the tool easier to use.
  • Ease of Implementation: Selenium has a friendly user interface making it very easy to implement test scripts effectively. With Selenium we can add different configurations on how we want our test to run. We can also reduce code duplication and improve code readability. In addition, new users who just started learning the tool find it easier to use and it doesn’t take much time to learn. Certainly, Developers who use Selenium sure do excellent feedbacks to give on this tool.
  • Support Across Various Operating Systems: It supports various Operating systems; it isn’t OS-dependent. This tool can work across this different OS; Windows, Linux, Mac OS, UNIX, etc. With Selenium WebDriver, we can create a test case on Windows and execute it on Mac and other OS.
  • Constant Update: Just like we mentioned earlier that a community supports Selenium. The selenium community releases regular updates and upgrades to make this tool more effective for Developers. Constant improvement on this tool drives more users daily.

Now that we’ve seen the different reasons this tool is very effective and why it’s one of the best automation tools. We’ll discuss how we can use this tool in Python.

Selenium With Python

Let’s implement how we to run a Selenium test script with Python programming language.

Follow the installation steps carefully.

Install Python on Windows

To demonstrate this, we will use a windows machine. If you don’t have Python on your machine, please visit this link to download, preferably Python 3.

After installing python, go to your command prompt to confirm by typing python, just as seen below.

You will have your python version, just as ours shows python 3.10.5.

Install Selenium

We can install Selenium using the command below. This will install the latest package of Selenium.

Python -m pip install -U Selenium

You can also confirm your installation using the same command we used below.

Download Selenium Web Driver

The next step is to download the Selenium Web driver for the browser we’ll be using. We’re using Google Chrome Browser, so we will download the chrome driver based on our chrome’s version. We can download the driver here. If you’re using other browsers, you can get FirefoxSafari, and Edge via each link. Here, we download the chrome driver for Windows as shown below.

Our Code

After downloading the zip file, we will extract the .exe file inside our working environment folder. To make things look cleaner, we can create a folder named Browser and put the .exe file inside. Like what we have below, our code will reside in the code.py file.

This is what we have in our code as shown below. In this code, we demonstrated a simple test case of how Selenium get driver was used to open Google and then we searched for our Name “Cndro”. Selenium performs the action of searching and clicking on search button automatically, after then, close the browser.

1 #we import our library
2 from selenium import webdriver
3 import time
4 from selenium.webdriver.common.keys import Keys
5
6 #here we paste link to our exe file in the webdriver.chrome method 7 driver = webdriver.Chrome(r'C:\Users\CNDRO\Documents\Selenium_project\Browser\chromedriver.exe')
8
9 #we maximize our window
10 driver.maximize_window()
11
12 #We will use the driver.get to open google
13 driver.get("https://www.google.com/")
14
15 #we use the driver to find name of the search bar name, so we can paste in our search item name
16 driver.find_element_by_name("q").send_keys("cndro")
17
18 #we use time.sleep to make selenium work at a balance by not being too fast
19 time.sleep(3)
20
21 #Now, we also get the name of the button where selenium will click automatically
22 #and then use send keys.enter to automatically click it
23 driver.find_element_by_name("btnK").send_keys(Keys.ENTER)
24
25 #we put it on sleep again
26 time.sleep(3)
27
28 #we then close the brower
29 driver.close()

 

So we run our code with the command python code.py as seen below;

Then it opens a new browser, just as seen below, to carry out our designated action.

Which automation tool do you consider the best? Drop your thoughts in the comments section below. Thanks for reading.

No Comments

Post A Comment