All Projects → sudharsan-selvaraj → spydriver

sudharsan-selvaraj / spydriver

Licence: other
🕵️ Lightweight utility to intercept WebDriver and WebElement method calls.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to spydriver

Java.appium
Mobile test automation using Appium in Java
Stars: ✭ 59 (+145.83%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Csharp.webdriver
Browser test automation using Selenium WebDriver in C#
Stars: ✭ 115 (+379.17%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Cabbie
WebDriver for the masses
Stars: ✭ 70 (+191.67%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Php Webdriver
PHP client for Selenium/WebDriver protocol. Previously facebook/php-webdriver
Stars: ✭ 4,477 (+18554.17%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Thirtyfour
Selenium WebDriver client for Rust, for automated testing of websites
Stars: ✭ 191 (+695.83%)
Mutual labels:  webdriver, selenium, selenium-webdriver
E2e Experiment
A demo project with Spring Boot / Angular application and e2e tests
Stars: ✭ 9 (-62.5%)
Mutual labels:  webdriver, selenium, selenium-webdriver
google-meet-bot
Bot for scheduling and entering google meet sessions automatically
Stars: ✭ 33 (+37.5%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Htmlelements
Html Elements is a Java framework providing easy-to-use way of interaction with web-page elements in web-page tests.
Stars: ✭ 258 (+975%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Webium
Webium is a Page Object pattern implementation library for Python (http://martinfowler.com/bliki/PageObject.html). It allows you to extend WebElement class to your custom controls like Link, Button and group them as pages.
Stars: ✭ 144 (+500%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Java.webdriver
Browser test automation using Selenium WebDriver in Java
Stars: ✭ 135 (+462.5%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Golem
A complete test automation tool
Stars: ✭ 441 (+1737.5%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Steward
PHP libraries that makes Selenium WebDriver + PHPUnit functional testing easy and robust
Stars: ✭ 215 (+795.83%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Selenium Maven Template
A maven template for Selenium that will let you check out and go.
Stars: ✭ 403 (+1579.17%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Marionette client
Mozilla's Gecko Marionette client in golang
Stars: ✭ 21 (-12.5%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Atata
C#/.NET test automation framework for web
Stars: ✭ 362 (+1408.33%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Webdriverextensions
Make your WebDriver based Selenium tests more readable, reusability and maintainable by using WebDriver Extensions!
Stars: ✭ 89 (+270.83%)
Mutual labels:  webdriver, selenium, selenium-webdriver
page-modeller
⚙️ Browser DevTools extension for modelling web pages for automation.
Stars: ✭ 66 (+175%)
Mutual labels:  webdriver, selenium, selenium-webdriver
atata-kendoui
A set of Atata components for Kendo UI
Stars: ✭ 17 (-29.17%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Marionette
Selenium alternative for Crystal. Browser manipulation without the Java overhead.
Stars: ✭ 119 (+395.83%)
Mutual labels:  webdriver, selenium, selenium-webdriver
Panther
A browser testing and web crawling library for PHP and Symfony
Stars: ✭ 2,480 (+10233.33%)
Mutual labels:  webdriver, selenium, selenium-webdriver

Lightweight utility to intercept webdriver and webelement method calls. Supports both Selenium and Appium drivers

About | To Get Started | Installation


About

Spydriver is a utility library which helps in intercepting all webdriver and webelement method calls and enables us to perform any operation before and after the method is executed.

spydriver.gif

How?:

Creating the listener object:

 SpyDriverListener listener = new SpyDriverListener() {

        @Override
        public void beforeDriverCommandExecuted(DriverCommand command) {
            System.out.println("[webdriver] Before " + command.getMethod().getName() +" => id: "+ command.getId());
            //Perform any action
        }
        
        @Override
        public void afterDriverCommandExecuted(DriverCommandResult command) {
            System.out.println("[webdriver] After " + command.getMethod().getName() +" => id: "+ command.getId());
            //Perform any action
        }
        
        @Override
        public void onException(DriverCommandException command) {
             //Perform any action
        }
        
        @Override
        public void beforeElementCommandExecuted(ElementCommand command) {
            System.out.println("[webelement] Before " + command.getMethod().getName() +" => id: "+ command.getId());
            //Perform any action
        }
        
        @Override
        public void afterElementCommandExecuted(ElementCommandResult command) {
            System.out.println("[webelement] After " + command.getMethod().getName() +" => id: "+ command.getId());
            //Perform any action
        }
        
        @Override
        public void onException(ElementCommandException command) {
            //Perform any action
        }
    }

Creating the spy driver object:

SpyDriver spyDriver = new SpyDriver(new FirefoxDriver(), //Any webdriver object(supports both Selenium and Appium)
        SpyDriverOptions.builder().listener(listener).build());// Listener that we have created above
WebDriver driver = spyDriver.getSpyDriver();
//now the driver object can be used in the test to get the events via listeners

It's also possible to add any number of listeners later using

spyDriver.addListener(listener);

That's it. Now you can use the driver object in your test and it will log each and every method name that is invoked in the driver object.

Example:

driver.get("https://the-internet.herokuapp.com/");
driver.manage().window().setSize(new Dimension(1000, 400));
driver.findElement(By.partialLinkText("Inputs")).click();
driver.findElement(By.cssSelector("[type=\"number\"]")).sendKeys("1222");
driver.quit();

Output:

[webdriver] Before get => id: a1275da9-f10b-4ab6-a268-3b963b83dc4a
[webdriver] After get => id: a1275da9-f10b-4ab6-a268-3b963b83dc4a
[webdriver] Before setSize => id: 4aff25ac-8c30-496b-a299-76a4bd1b0dbe
[webdriver] After setSize => id: 4aff25ac-8c30-496b-a299-76a4bd1b0dbe
[webdriver] Before findElement => id: 9d7e9167-6f5b-4f13-9f29-66c2e0239889
[webdriver] After findElement => id: 9d7e9167-6f5b-4f13-9f29-66c2e0239889
[webelement] Before click => id: 57247a4e-5be9-4af3-b9fa-c9142bacce67
[webelement] After click => id: 57247a4e-5be9-4af3-b9fa-c9142bacce67
[webdriver] Before findElement => id: 8d57434c-6c02-4e41-934f-86771fce9226
[webdriver] After findElement => id: 8d57434c-6c02-4e41-934f-86771fce9226
[webelement] Before sendKeys => id: 0233e88f-6e89-47a0-aa60-a3f3b94319c9
[webelement] After sendKeys => id: 0233e88f-6e89-47a0-aa60-a3f3b94319c9
[webdriver] Before quit => id: aa31341e-c464-4789-98f2-bb0aaa5cec87
[webdriver] After quit => id: aa31341e-c464-4789-98f2-bb0aaa5cec87

Check SpyDriverExample.java for more usage.

Hooks:

beforeDriverCommandExecuted:

Invoked before the webdriver method is called. Parameter: DriverCommand

driver.get("https://www.google.com");

public void beforeDriverCommandExecuted(DriverCommand command) {
    System.out.println(command.getMethod().getName()); // prints "get"
    System.out.println(command.getArguments()[0]); // prints "https://www.google.com"
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
    
    Thread.sleep(2000); //Wait 2s before calling the get method
    //You can add any cutom logic here in blocking mode   
}

afterDriverCommandExecuted:

Invoked after the webdriver method is called. It also holds the return value from the original method call.

Parameter: DriverCommandResult

//sample driver method
driver.getTitle();

public void afterDriverCommandExecuted(DriverCommandResult command) {
    System.out.println(command.getMethod().getName()); // prints "getTitle"
    System.out.println(command.getArguments()); // prints "[]" (because there are no parameters)
    System.out.println(command.getResult()); // prints "Google"
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
}
//sample driver method
driver.findElement(By.cssSelector("body"));

public void afterDriverCommandExecuted(DriverCommandResult command) {
    System.out.println(command.getMethod().getName()); // prints "findElement"
    By locator = (By) command.getArguments()[0];
    WebElement locatedElement = (WebElement) command.getResult();
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
}
//sample driver method
driver.manage().window().getSize();

public void afterDriverCommandExecuted(DriverCommandResult command) {
    System.out.println(command.getMethod().getName()); // prints "getSize"
    System.out.println(command.getArguments()); // prints "[]" (because there are no parameters)
    Dimension size = (Dimension) command.getResult(); // returns the current window size
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
}

onException:

Invoked if any exception is thrown while calling the webdriver method.

Parameter: DriverCommandException

//sample driver method
driver.get("some-invalid-url");

public void onException(DriverCommandException command) {
    System.out.println(command.getMethod().get()); // prints "get"
    System.out.println(command.getArguments()[0]); // prints "some-invalid-url"
    System.out.println(command.getException().getMessage()); // Malformed URL: URL constructor: some-invalid-url is not a valid URL.
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
}

beforeElementCommandExecuted:

Invoked before any method is called in WebElement object.

Parameter: ElementCommand

//sample driver method
WebElement element = driver.findElement(By.cssSelector(".username"));
element.sendKeys("Test", " ", "Ninja");

public void beforeElementCommandExecuted(ElementCommand command) {
    System.out.println(command.getMethod().getName()); // prints "sendKeys"
    System.out.println(command.getArguments()[0]); // prints ["Test", " ", "Ninja"]
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
    Webdriver originalElement = command.getElement(); // return the original element object that is being spied.
    By locator = command.getLocator(); // returns the locator used to find the original element (By.cssSelector(".username")).
}
//sample driver method
WebElement element = driver.findElement(By.cssSelector(".username"));
element.click();

public void beforeElementCommandExecuted(ElementCommand command) {
    System.out.println(command.getMethod().getName()); // prints "click"
    System.out.println(command.getArguments()); // prints "[]"
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
    Webdriver originalElement = command.getElement(); // return the original element object that is being spied.
    By locator = command.getLocator(); // returns the locator used to find the original element (By.cssSelector(".username")).
}

afterElementCommandExecuted:

Invoked after any method is called in WebElement object.

Parameter: ElementCommandResult

//sample driver method
WebElement element = driver.findElement(By.cssSelector(".username"));
String username = element.getAttribute("value");

public void afterElementCommandExecuted(ElementCommandResult command) {
    System.out.println(command.getMethod().getName()); // prints "getAttribute"
    System.out.println(command.getArguments()[0]); // prints ["value"]
    System.out.println(command.getResult()); // prints "Test Ninaje"
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
    Webdriver originalElement = command.getElement(); // return the original element object that is being spied.
    By locator = command.getLocator(); // returns the locator used to find the original element (By.cssSelector(".username"))
}

onException:

Invoked if any exception is thrown while calling the webelement method.

Parameter: ElementCommandException

//sample driver method
WebElement element = driver.findElement(By.cssSelector(".hidden"));
element.click();

public void onException(ElementCommandException command) {
    System.out.println(command.getMethod().getName()); // prints "click"
    System.out.println(command.getException().getMessage()); // prints "element not visile"
    Webdriver originalDriver = command.getDriver(); // return the original driver object that is being spied.
    Webdriver originalElement = command.getElement(); // return the original element object that is being spied.
    By locator = command.getLocator(); // returns the locator used to find the original element (By.cssSelector(".hidden"))
}

Installation:

Maven:

<dependency>
  <groupId>io.github.sudharsan-selvaraj</groupId>
  <artifactId>spydriver</artifactId>
  <version>1.1.1</version>
</dependency> 

Gradle:

implementation group: 'io.github.sudharsan-selvaraj', name: 'spydriver', version: '1.1.1'
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].