Friday, June 21, 2024

Selenium Introduction, Advantages and Disadvanatges

 

 

Automation Testing:

---------------------------

Def:

  Checking functionality of application with help of automation tool by writing some lines of code

 

ex:  login functionality

 

Steps :

·        open browser -->  code

·        enter url in browser --> code

·        enter user name in 'user name' text box --> code

·        enter pwd in 'password' text box --> code

·        click 'login' button  --> code

·        Verify home page is displayed successfully or not--> code

 

What is Selenium?

Selenium is an open-source automation tool that is freely available for anyone to download and use. You do not need to pay any money or purchase any tool to use Selenium.

 

Commercial Tools/Paid Tools:

·       QTP/UFT (by Microfocus): Requires purchasing a license. Offers a 20 or 30-day trial period.

·       Test Complete

·       Katalon Studio

·       IBM RFT

 

-Technically Selenium is distributed as a .jar file (Java Archive file, similar to a .zip file).

·       The .jar file contains packages that include classes and interfaces.

·       These classes and interfaces contain methods.

·       These methods can be used to automate browser actions.

 

 

- Selenium can only be used to automate web-based applications, not desktop applications.

 

Web Application:

A web application is any application that can be accessed via a web browser such as Chrome, Firefox, Edge, or Internet Explorer.

Examples:

  • amazon.com
  • facebook.com
  • redbus.com
  • Multi-User Access: Multiple users can access the web application simultaneously.
  • Internet Connection: Requires a Wi-Fi or network connection to function.

Desktop Application:

 A desktop application is any application that can be opened and run directly from a desktop, typically via an executable file (.exe).

Examples:

  • VLC Media Player
  • Zoom Desktop Client
  • Microsoft Teams (available as both desktop and web applications)

·        Single User Access: Typically, only one user can access the application at a time.

·        No Internet Requirement: It is not necessary to have a Wi-Fi or network connection to use the application, although some features may require internet access.

 

FAQ Difference between web application and Desktop application?

 

Feature

Web Application

Desktop Application

Accessibility

Through web browsers

Installed and run locally on a computer

Examples

amazon.com, facebook.com, redbus.com

VLC, Zoom Desktop, Microsoft Teams (Desktop)

User Access

Multiple users simultaneously

Typically single user

Internet Connection

Required for access

Not necessary, though some features may need internet

 

·        Supports multiple programming languages such as Java, C#, Python, JavaScript, Perl, Ruby, etc.

 

UFT (Unified Functional Testing):

  • Uses only VBScript for scripting.
  • Does not support languages like Java, C#, etc.

 

·        Selenium supports multiple operating systems, including Windows, Linux, and Mac (only on Apple laptops).   

 

UFT Supports only Windows operating system and does not support Linux or Mac OS.

·       Selenium supports multiple browsers:

  • Chrome
  • Firefox
  • Edge

·        Safari (only on Mac OS)- not available in windows o/s

  • Internet Explorer (no longer supported or enhanced)

 UFT :

·       Initially supported only Internet Explorer.

·       Later added support for Firefox and Chrome.

·        Does not support Safari.

 

UFT:

  • Known as Unified Functional Testing, it is a functional automation tool.
  • Evolved from Mercury Interactive’s QTP, which was acquired by HP, and then became UFT under MicroFocus.
  • Performs functional testing as well as web service testing/API testing  
  • ex:  3 laks 

Differences in Types of Licenses:

1.     Seat License:

    • Assigned per person.
    • Each individual user requires a separate license.

2.     Concurrent Licenses:

    • A fixed number of licenses (e.g., 4 or 5) that can be used by multiple users.
    • Any user can install and use the software, but only up to the licensed number of users can access it simultaneously.

Disadvantages of Selenium:

1.     Cannot Automate Desktop Applications:

    • Selenium is designed for web applications only and cannot automate desktop applications.
    • Note: Third-party tools like AutoIT can be used to automate desktop applications.

2.     No Default Test Results Generation:

    • Selenium does not generate test results by default.
    • Note: Third-party tools such as ExtentReports and TestNG can be used to generate detailed test reports.
    • UFT: Generates test results by default after test case execution.

3.     Cannot Automate Bar Code Scanning and ReCaptcha:

    • Selenium is not equipped to handle bar code scanning applications or ReCaptcha text testing.

4.     No Inbuilt Object Repository Mechanism:

    • Selenium does not have an inbuilt object repository to store object properties and values.
    • Object Repository: A place to store all object properties and values.
    • UFT: Includes an inbuilt object repository concept, making it easier to manage object properties.

FAQ: Disadvantages of Selenium?

1.     Can Selenium automate desktop applications?

·        No, Selenium cannot automate desktop applications. It is designed for web applications only.

2.     Does Selenium generate test results by default?

·        No, Selenium does not generate automation test results by default. You can use third-party tools like ExtentReports and TestNG to generate test reports.

3.     Can Selenium automate bar code scanning applications and ReCaptcha text testing?

·        No, Selenium cannot automate bar code scanning applications or ReCaptcha text testing.

4.     Does Selenium have an inbuilt object repository mechanism?

·        No, Selenium does not have an inbuilt object repository mechanism. You need to manage object properties and values manually or use additional tools.

Web Element Interface and it's Methods

WebElement Interface:

 WebElement is a predefined interface in Selenium.

The WebElement interface in Selenium represents any HTML element on a web page.

 Examples include text boxes, radio buttons, checkboxes, and visible text.

Each element on a web page is considered a web element (or)    whatever we see in the web page is a web element

Any item visible on the web page is a web element.

Examples: first name text box, last name text box, male radio button, female radio button, electronic checkbox

 Visible text à  is also web element

 Every element has some properties/ attributes  with specific "values"

 

Inspecting Elements:

To interact with web elements, you first need to inspect them to understand their attributes.

Steps:

·  Right-click on the desired/target element.

·  Select "Inspect" from the context menu.

·  The browser's Developer Tools will open, displaying the HTML code with the selected element highlighted.

 

Homework:

·  Inspect Last Name Text Box:

·  Inspect Male Radio Button:

·  Inspect Female Radio Button:

 

Moving Developer Tools (or) docker:

 

·  Move to Right: Click the three-dot menu on the Developer Tools panel, select "Dock side," and choose the right option.

·  Move to Bottom: Click the three-dot menu, select "Dock side," and choose the bottom option.

·  Move to Left Side: Click the three-dot menu, select "Dock side," and choose the left option.

Highlighting Elements:

  • Hover over different tags in the HTML code. The corresponding elements on the web page will be highlighted.

Actions on Web Elements:

For each web element, specific actions can be performed using methods provided by the WebElement interface.

 

ex:  send data to textbox ele,   ---- >   specific Method

     clear data from textbox ele   --> specific Method

     get val from text box ele --> specific  Method

     ele is displayed -->

ele is enabled à

ele is selected à

  

    Radio btn :   click    ---> click()

    Checkbox  :  clicking/ unclicking   --> click()

                Select/ Unselect checkbox

 

 

Important Methods in the WebElement Interface:

 We have to know what method we have to use.

  1. void sendKeys(String val):
    Sends or enters data into a text box.

sendkeys("Ramu");

Examples:

    • User name text box
    • Password text box

2.     void click():
Clicks an element like a button, radio button, or checkbox.

Examples:

·        Click login button

·        Select a radio button

·        Select a checkbox

3.     void clear():
Clears the value from a text box.

4.     boolean isDisplayed():

It can be used to check the element is displayed or not in webpage.

  • Returns true if the element is displayed.
  • Throws NoSuchElementException if the element is not found but not false

5.     boolean isEnabled():
Checks if the element is enabled.

  • Returns true if the element is enabled.
  • Throws an exception if the element is not found.

6.     boolean isSelected():
It can be used for checkbox , radio button  whether it is selected 

  • Returns true if the checkbox/radio button is selected.
  • Returns false if the checkbox/radio button is not selected.
  • Returns false if the checkbox/radio button is not selected.

7.      String getAttribute(String attrName):
Gets the value of the specified attribute of the element.

Example element:

html

 

<input type="text" value="default value Ram" name="firstname" id="idfirst" class="firstclass" width="55">

Usage:

  • getAttribute("type") returns "text"
  • getAttribute("name") returns "firstname"
  • getAttribute("id") returns "idfirst"

Who defines these properties (name, id) for HTML tags or elements in HTML?

  • The developer defines these properties, not the testers

8.       String getText():
Gets the visible text of the specified element. This method is generally used to get the text content of elements like
<a>, <option>, <div>, <span>, <ul>, and <li>.

 

      <a >  My gmail    </a>

      <option>  ECE   </option>

      <div>  Ramesh </div>

      <span>  Tendulkar            </span>

      <ul> Mobile </ul>

      <li>Samsung </li>

 

Note:

Don't use this method for text box elements. If you use it on a text box element, it will not return the value inside the text box. Instead, it will return an empty string or potentially throw an exception, depending on the state of the text box.

9.     void submit():
Submits a form. This method can be used on elements within a form, like an input of type "submit" or "button".

<input type="submit" value="Submit">

<button type="submit">Login</button>

<input type="button" value="Click me">

Note: You can also use the click() method for buttons.

10.  findElement(By by):

The findElement(By by) method in Selenium is used to find/locate/identify an element on a web page using the By class locators (or) By class mechanism. It returns the first matched element only

By is a predefined class in Selenium that provides methods like name(), id(), className(), xpath(), etc., to locate elements.

Refer to the Selenium API documentation for more details.

 

By Class Locators:

The By class in Selenium is used to locate elements. It contains both abstract and non-abstract methods.

  • Abstract Methods: These methods are declared without implementation. The implementation is provided by subclasses.
  • Non-Abstract Methods: These methods are fully implemented.

By.id("idValue");

By.name("nameValue");

By.className("classValue");

 

By.xpath("xpathExpression");

By.cssSelector("cssSelector");

 

By.linkText("fullLinkText");

By.partialLinkText("partialLinkText");

 

By.tagName("tagName");

 

 

 

 

Revision:

Webdriver : Interface  or class   -->  -> Interface

def:   ideally represents any type of browser.

       =     browser

 

Webelement :   Interface or class name ?  -> Interface

            def: 

ChromeDriver --> Interface or Class  ---> Class

A class that implements WebDriver to control the Chrome browser.

Inspecting/View Properties of Elements:

  • Steps: Right-click on the desired element and select "Inspect" to view its properties.

 

Questions on WebDriver Methods:

 

open url -->   get("url") or

navigate() to url  -->  navigate().to("url")

 

get title of page - >  getTitle()    return type string

 

get current url  -->   getCurrentUrl()              String

 

close browser  -->   close(); 

close all browsers -->   quit()

 

 

Questions on WebElement Methods:

sendkeys("ram") ;  -->  - textbox

click() ;  -->  click the given ele

clear() ;   -->  clear the val from text box

 

isDisplayed() -->  returns ?

isenabled -->  returns ?

isselected -->  returns ?

 

getattribute("name") ;   //  get val 

The getAttribute() method returns null if the specified attribute does not exist.

 

getText() ;   


git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...