/Generic-functions-Selenium-java

This repository contains generic functions used in selenium java

Primary LanguageJava

Selenium webdriver with Java
This repository contains generic functions used in selenium java
πŸ‘ Click this link to view JavaScriptExecutor methods
πŸ‘ Click this link to view Excel Operation using Apache POI
πŸ‘ Click this link to view Extent Reports in Selenium WebDriver
πŸ‘ Click this link to view Access data from Properties File
πŸ‘ Click this link to view Common methods used in selenium webdriver
πŸ‘ Click this link to view Sample selenium programs
πŸ‘ Click this link to view Sample TestNG programs
πŸ‘ Click this link to view Advance selenium concepts
πŸ‘ Click this link to view Jenkins concepts
πŸ‘ Click this link to view Java TitBits
πŸ‘ Click this link to view Java Programs
πŸ‘ Click this link to view Debugging
πŸ‘ Click this link to view Accessibility Testing
πŸ‘ Click this link to view Linux Commands

Why Do We Need Waits In Selenium?

Most of the web applications are developed using Ajax and Javascript. When a page is loaded by the browser the elements which we want to interact with may load at different time intervals.
Selenium Wait
Wait commands
Handle Ajax call Using JavaScriptExecutor

Action Class in Selenium

Action Class in Selenium is a built-in feature provided by the selenium for handling keyboard and mouse events. It includes various operations such as multiple events clicking by control key, drag and drop events and many more. These operations from the action class are performed using the advanced user interaction API in Selenium Webdriver.
How to use Action Class

Need for Robot class

Selenium scripts use Robot class for automating the browser and desktop pop-ups, but the exciting thing is this class is not part of org.openqa.selenium package of Web Driver API.
Then from where does this class come?
It doesn’t reside in Web Driver API; it is part of the Java API awt package
How to use Robot Class

Test Automation for Windows Desktop Applications

Winium

Winium is a Selenium-based tool for testing and automating desktop applications on a Windows desktop. It uses selenium-based libraries however the community has made only two releases and there is no active work or maintenance since then
Winium sample code snippet

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;

import java.net.MalformedURLException;
import java.net.URL;

public class sampleTest {
    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        WiniumDriver driver = null;
        String appPath = "C:/windows/system32/calc.exe";
        DesktopOptions option = new DesktopOptions();
        option.setApplicationPath(appPath);
        option.setDebugConnectToRunningApp(false);
        option.setLaunchDelay(2);
        driver = new WiniumDriver(new URL("http://localhost:9999"),option);
        Thread.sleep(1000);
        WebElement window =  driver.findElementByClassName("CalcFrame");
        WebElement menuItem = window.findElement(By.id("MenuBar")).findElement(By.name("View"));
        menuItem.click();
        driver.findElementByName("Scientific").click();

        window.findElement(By.id("MenuBar")).findElement(By.name("View")).click();
        driver.findElementByName("History").click();

        window.findElement(By.id("MenuBar")).findElement(By.name("View")).click();
        driver.findElementByName("History").click();

        window.findElement(By.id("MenuBar")).findElement(By.name("View")).click();
        driver.findElementByName("Standard").click();

        driver.findElementByName("4").click();
        driver.findElementByName("Add").click();
        driver.findElementByName("5").click();
        driver.findElementByName("Equals").click();
        driver.close();
    }
}

WinAppDriver Test Automation Framework

WinAppDriver uses selenium-like libraries and is actively supported by the community and is developed by the makers of Windows OS – Microsoft. Windows Application Driver supports Selenium-like UI test automation for Windows applications. The service supports automated testing of Universal Windows Platform (UWP), Windows Forms (WinForms), Windows Presentation Foundation (WPF), and Classic Windows (Win32) apps on the Windows 10 operating system. Winappdriver complies with the JSON Wire Protocol and some application management functionalities defined by Appium. This service provides better support for using Appium to test Windows Applications.
WinAppDriver with Java
WinAppDriver with C#
HTML unit driver

What is the sequence in which Maven searches for dependency libraries?

Maven build life cycles are listed below as the followings:

  • Step 1 βˆ’ Search dependency in local repository(.m2), if not found, move to step 2.
  • Step 2 βˆ’ Search dependency in central repository(https://mvnrepository.com), if not found and remote repository/repositories is/are mentioned then move to step 4. Else it is downloaded to local repository for future reference.
  • Step 3 βˆ’ If a remote repository has not been mentioned, Maven simply stops the processing and throws error (Unable to find dependency).
  • Step 4 βˆ’ Search dependency in remote repository or repositories, if found then it is downloaded to local repository for future reference. Otherwise, Maven stops processing and throws error (Unable to find dependency).

Execute script in Remote cloud

PerfectoSampleProject

Selenium Hierarchy

Selenium Webdriver Interface & Classes Hierarchy
Hierarchy Of Classes & Interfaces Of WebDriver Interface In Selenium WebDriver
Upcasting & downcasting Classes
Why Should We Upcast Browser Driver Class Object To WebDriver?

        // Running javascript command
		// Need to downcast to JavascriptExecutor
        WebDriverManager.chromedriver().setup();
		WebDriver driver = new ChromeDriver();
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("window.scrollBy(0,250)");
        
        or
        
		ChromeDriver driver = new ChromeDriver();
		driver.executeScript("window.scrollBy(0,250)");

Selenium architecture

Architecture Of Selenium
selenium < 3.8 -Json wire protocol
selenium > 3.8 -W3C Protocol
http://makeseleniumeasy.com/home/seleniumbytopic/