Coder Social home page Coder Social logo

sethijatin / creative-element Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 5.0 66 KB

The project aims to provide a simple light weight object (Creative Element) to compare the layout of one Web Element with respect to the Other.

License: Apache License 2.0

Java 100.00%
creative layout page-layout testing quality-assistance quality-assurance selenium automation

creative-element's Introduction

Project For Facilitating Page Layout Testing For Websites

The project aims to provide a simple light weight object (Creative Element) to compare the layout of one Web Element with respect to the Other.

The relation between web elements (two web elements) is expressed in the following terms:

  • On
  • Near
  • Inside
  • Aligned

The project is inspired by Galen Framework and has been produced so that relevant functions can be utilized by other frameworks.

Usage

Including It In Your Project POM:

<repositories>
     <repository>
	<id>jitpack.io</id>
	<url>https://jitpack.io</url>
     </repository>
</repositories>

<dependency>
    <groupId>com.github.sethijatin</groupId>
    <artifactId>creative-element</artifactId>
    <version>1.1</version>
    <scope>test</scope>
</dependency>

Creating a Creative Element:

Creative Element is created using a WebElement.

CreativeElment element = new creative.layout.CreativeElement(driver.findElement(By.cssSelector(...)));

Creative Element also returns back the Selenium WebElement so as the tester can continue with their regular selenium operations

WebElement element = creativeElement.getElement();

Relation between one Creative Element with respect to other can be asserted in the following way:

CreativeElment elementOne = new CreativeElement(driver.findElement(By.cssSelector(...)));
CreativeElment elementTwo = new CreativeElement(driver.findElement(By.cssSelector(...)));
Assert.assertTrue(elementOne.isInside().isInside(elementTwo));

Near

Near is used to evaluate that a WebElement is not on, or inside another WebElement. Relevant functions for near are:

  • On Top Of => isNear().onTopOf(...)
  • On Bottom Of => isNear().onBottomOf(...)
  • Is Near => isNear().isNear(...)
  • On Right Of => isNear().onRightOf(...)
  • On Left Of => isNear().onLeftOf(...)
//Is creative.layout.Near
//Returns true in case the WebElement is neither inside other WebElement, nor on the other WebElement
elementOne.isNear().isNear(elementTwo);

//creative.layout.On Top Of
//Returns true in case the WebElement is near and on right of other WebElement
elementOne.isNear().onRightOf(elementTwo);

//creative.layout.On Top Of
//Returns true in case the WebElement is near other WebElement, and the distance between the Top Edge of Element 1, and Top Edge of
//Element 2 is exactly 16 pixels (calculated using integers)
elementOne.isInside().isInside(elementTwo, creative.layout.Direction.Top, 16);

//creative.layout.On Top Of
//Returns true in case the WebElement is near other WebElement, and the distance between the Top Edge of Element 1, and Top Edge of
//Element 2 is between 16 - 20 pixels (calculated using integers)
elementOne.isInside().isInside(elementTwo, creative.layout.Direction.Top, 16, 20);

On:

On is used to evaluate if a WebElement overlaps the other WebElement. If the respective edges or even points of 2 WebElements will overlap each other they are considered overlapping.

//Overlaps
//Returns true in case the WebElement overlaps the other WebElement
elementOne.on().overlaps(elementTwo);

//Get Distance
//Returns the distance (integer) between Top edge of ElementOne and Top Edge of ElementTwo
elementOne.on().getDistance(elementTwo, creative.layout.Direction.TOP);

Inside

Inside is used to evaluate if a WebElement is inside other WebElement. Completely inside no edges or points overlap.

//Is Inside

//Returns true in case the WebElement is inside other WebElement
elementOne.isInside().isInside(elementTwo); //Simple check

//Returns true in case the WebElement is inside other WebElement, and the distance between the Top Edge of Element 1, and Top Edge of
//Element 2 is exactly 16 pixels (calculated using integers)
elementOne.isInside().isInside(elementTwo, creative.layout.Direction.Top, 16);

//Returns true in case the WebElement is inside other WebElement, and the distance between the Top Edge of Element 1, and Top Edge of
//Element 2 is between 16 - 20 pixels (calculated using integers)
elementOne.isInside().isInside(elementTwo, creative.layout.Direction.Top, 16, 20);

Aligned

Aligned evaluates if the two WebElemnts are aligned. creative.layout.Aligned is validated on the edges, or inside another Web Element. Functions:

  • Top => isAligned().top(...);
  • Bottom => isAligned().bottom(...);
  • Left => isAligned().left(...);
  • Right => isAligned().right(...);
//creative.layout.Inside Top
//Returns true in case the WebElement 1 is top aligned with WebElement 2
elementOne.isAligned().top(elementTwo);

Aligned & Inside

It is possible for the WebElements to be inside another webaligned and still be aligned. The following functions can be used to validate the same:

  • Inside Centrally => isAligned().insideCentrally(...);
  • Inside Horizontally => isAligned().insideHorizontally(...);
  • Inside Vertically => isAligned().insideVertically(...);
//Returns true if element one is inside element two and are aligned right in the center (vertically & horizontally).
elementOne.isAligned().insideCentrally(elementTwo);

Describe

While most functions in the API were meant to be used directly into assertions, this specific function describes the relation between the two web elements.

elementOne.describe().describeRelationTo(elementTwo);

Sample Output For Inside:

 Element is 'inside' the other element to which it is compared to.

 Space Between Element Edges In Pixels
 Top    : 17
 Bottom : 17
 Left   : 194
 Right  : 195

 Alignment Between Elements
 Top Aligned : false
 Bottom Aligned : false
 Left Aligned : false
 Right Aligned : false
 Aligned Inside Horizontally : false
 Aligned Inside Vertically : true
 Aligned Inside Centrally : false

Sample Output For Near:

 Element is 'near' (on top right of) the other element to which it is compared to.

 Space Between Element Edges In Pixels
 My Top & Other's Bottom : 1908
 My Bottom & Other's Top : 1598
 My Left & Other's Right : 373
 My Right & Other's Left : 722

 Alignment Between Elements
 Top Aligned : false
 Bottom Aligned : false
 Left Aligned : false
 Right Aligned : false
 Aligned Inside Horizontally : false
 Aligned Inside Vertically : false
 Aligned Inside Centrally : false

BrowserStack is helping us getting better:

BrowserStack

BrowserStack is helping me extend the API by providing their state of the art infrastructure to test this API across platforms! Together we shall make the layout testing easy!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.