Skip to content

Suyog1608/Selenium_With_Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Selenium_With_Python

Test Automation using with Python-Selenium

Good to have basic knowledge of python and html

Why do we need to automate tests
  1. Decreased cost and time of testing
  2. Enable continuous delivery through round-the-clock testing
  3. Ensure regression testing
  4. Increased test coverage
  5. Cross-device testing made easy

Mike cohn's test automation pyramid

    [ User Interface tests <-- Service/API layer tests <-- Unit test ]

  • Unit tests which is the bottom most layer of pyramid which is most numerous and have maximum coverage,
    Used to test small line of code and hence can not be used for integration testing or system testing.
  • Service/APi layer tests functionality in terms of services,
    Service means an program where application takes input to produce the outputs,
    Main aim is to seperate UI testing from functionality testing, therby saving the cost and time of UI testing
  • UI layer is used to test only the functionality of UI elements

Python in Automated testing

  • provides diff tools for Unit testing and API testing like : unittest, pytest, nose
  • for UI level of testing mostly tools are used Selenium and Python

Selenium Autmation Framework

  • Selenium Automate browsers
  • Used for web UI automation -- the automatic execution of the actions performed in a web browser window
  • Used for robust, browser-based regression testing
  • Used to scale tests to multiple browsers and environment using Selenium
  • Selenium webdriver supports various browsers including Firefox, Chrome, Internet Explorer, Edge, and Safari
  • Ensure Cross-crowser compatibility
  • Selenium-Firefox Driver

  • Firefox binary needs to be installed seperately
  • Firefox Driver should be placed in the systems path such that webDriver can locate it automatically
  • An Instance of firefox Driver is Created
      driver = webdriver.Firefox()
  • For more info visit this website
  • Selenium-Chrome Driver

  • Chrome binary needs to installed seperately
  • Chrome Driver should be placed in the systems path such that webDriver can locate it automatically
  • An Instance of chrome Driver is Created
      driver = webdriver.Chrome()
  • For more info visit this website
  • Note : Before getting started with writing test cases all the installed webdrivers should be placed in Systems path so for getting locate automatically by webdriver

    HTML DOM STRUCTURTE

    1. The html DOM defines the logical structure of documents and the way a document is accessed and manipulated.
    2. The DOM presents an HTML Document as a tree structure (a node tree), with elements, attributes, and text
    3. With the DOM, programmers can create and build documents, navigate their structure, and add, modify, or delete elements and content

    Let's start with locating the elements by ID

    • The HTML id attribute specifies a unique id for a HTML element
    • Rules for the id attribute
      • At lease one character
      • No spaces characters
      • Case Sensitive
      • Unique in the document

    Let's start with practical now with locating the elements with the different ways

    • Locating elements by ID
    • Locating elements by Name
    • Locating elements by XPath
      • XPath stands for XML path language
      • XPath uses path expressions to identify and navigate nodes in an XML Document
      • XPath is used to locate elements when a specific ID or name is not available for the node.
        It can be used to select one or more nodes in the document - using absolute and relative paths.
      • In case of Absolute Path, the path of the name is specified right from the root node.
      • In case of Relative Path, the path of the node is specified relative to another node that has relative attribute.
      • Note: It is generally advised to not use and absolute XPath as even the slightest change in application structure could cause it to fail and become invalid.
    • Locating elements by class
      • The HTML class attribute specifies one or more class names for an HTML element
      • These class names are used to point a class in a stylesheet
      • It is Used to locate elements when the class attribute of one or more elements is known

    Let's get ahead with some new methods for testing

    PAGE INTERACION

    • Just landing on a page and locating elements is not enough
    • Interact with the elements on the page once they are selected
    • Interact with a page as actions performed by a user.
    • In this we will learn about how to put values in text inputs and text areas (like search boxes, etc.) and can test the results by importing the 'Keys' Module

    Filling Forms

    • Dealing with other form of elements
    • "Select" class that helps us tackle select elements - find a select element and then select values by index, visible text, and value
    • "Submit" method on every element in the form
    • In this we will use the SELECT class which helps you deal with select elements in the form & it also comes with a submit method that works on every element in the form

    Drag and Drop

    • Users drag and drop elements as part of a UI interaction
    • Drag and drop source element to a target element
    • Drag and drop a source element by a specific x-offset and y-offset
    • This can be implement by using ActionChains Class which will help in perfforming drag n drop and also setting in the values of xoffset and yoffset which can be perform by perform() function

    Let's go ahead with getting understand of what are Waits and why do we need them

      What are Waits?
    • Waits are very important when it comes to placing your automation script.
    • Because most websites used Asynchronous Techniques such as AJAX.
      • When a webpage is loaded by the browser the elements may be loaded at different time intervals due to AJAX calls.
      • Some elements may take much longer to load as compared to others. This could be something like a image, video or any other element that requires more time to load.
      • Which posses a problem while locating elements on a page
      • If an element is not found by a script at that time, an exception is raised and your script will run into a issue and stop
    • Waiting adds a time interval between actions performed by the Web driver
      i.e it adds a time wait between locating elements and performing operations on them.

    Selenium Webdriver provides two types of wait i.e Explicit Waits and Implicit Waits

    • An explicit waits stops execution until a certain condition is satisfied., and
    • An implicit waits Polls the DOM for a given amount of time while trying to locate an element.

    Explicit Wait

    • Explicit wait is one where you want your code to pause until a certain condition has been satisfied.
    • Like if you are testing an image and you want to wait for the presence of the image to be loaded, then you add explicit wait,
      otherwise the image will not load at right time in your script and element not found exception will be thrown.
    • Selenium webdriver uses a combination of the classes WebDriverWait and ExpectedConditions to add explicit waits.
    • These convinient methods could test conditions ranging from the title list to visibility of an element being located to an alert being present, to text being present, and much more.

    Implicit Wait

    • An implicit wait is where you want your code to pause for a certain amount of time beofre every action or every element to be loaded.
    • Pauses for a certain amount of time for every action.
    • Waiting time is specified in seconds.

    • Use Case
    • The typical use case for implicit waits is when you have a slow internet connection and you know that every element im the site will load much slowly than expected
    • So we can add implicit wait before every call, so once the element is loaded, If the element is loaded in the specified time then the script moves on
      If the element is not loaded within the specified amount of time, then an exception is thrown.

    About

    No description, website, or topics provided.

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published