wttech / bobcat

Bobcat is an automated testing framework for functional testing of web applications.
https://cognifide.github.io/bobcat/
Apache License 2.0
90 stars 40 forks source link

Page utility - new approach to page handling #24

Closed ghost closed 5 years ago

ghost commented 8 years ago

Introduce a new way of handling pages by Bobcat - a Page utility in favor of sub-classing PublishPage and AuthorPage.

Rationale:

Current approach

At the moment, in Bobcat we have abstract classes like AuthorPage or PublishPage that provide WebDriver instance for navigation properties and contain properties for domains. The current approach with managing different pages is to subclass these types of pages, inject or simply hardcode the path and add additional fields, like specific page objects. These last items are usually driven by tests itself, they are not necessarily related to the page structure, e.g.:

In the end we're having multiple, redundant page objects being nothing else than wrappers for properties in specific use cases (as can be seen e.g. here: https://github.com/Cognifide/bobcat/blob/cb894457e92d3d02dbf146f682f35f1e52dc332a/bb-aem-integration-tests/src/main/java/com/cognifide/bdd/demo/po/product/CirclePage.java). Having such implementations indicates that we are recommending/suggesting this solution - while different projects have shown it is not being the most effective way of handling pages.

Additional few things worth considering / areas not addressed with the above approach:

Based on the above, Bobcat does not provide a clear guidance on how to approach page handling.

Proposed approach

Page utility

In favor of abstract classes, we could provide an extendable utility that would handle navigation and obtaining content. Base assumptions:

// based on path
Page.on(PUBLISH).path("/content/test/node").open();

// based on config, e.g pages.yml:
// Test page:
//    - path: /content/test/page
Page.on(AUTHOR).named("Test page").open();

// with query string
Page.on(PUBLISH).path("tested page").query().open();

// custom env
Page.on("192.168.1.2:6103").path("/content/test/node").open();

// handling protocols
Page.protocol(HTTPS).on(PUBLISH).path("/content/test/node").open();

// setting defaults
Page.default().protocol(HTTPS);
Page.default().protocol(HTTP).on(PUBLISH); 

Opening pages in different AEM modes

// EDIT mode - default
Page.on(AUTHOR).path("/content/test/node").open();

// WCM Mode disabled
Page.on(AUTHOR).mode(WCM_MODE_DISABLED).path("/content/test/node").open();

Remembering the context, following redirects etc.

// Remembering the context
Page.on(AUTHOR).path("/content/test/node").open(); //saves as current page
// ... operations on page objects causing a redirect ...
Page.lastPage().open();

// Following redirect
WebElement a = driver.findElement(By.cssLocator("a.my-link"));
Page.navigateBy(a -> a.click()).expecting().path("/content/redirected/path"); // handles `page loading, change of URL etc.

// Verifying redirects
Page.wasRedirected().path("/path/to/potential/redirect");

Obtaining content

// Obtaining parsys/component in authoring

// assuming navigation to an author page happened
// e.g. Page.on(AUTHOR).named("Test page").open();
// based on config, e.g pages.yml:
// Test page:
//    - path: /content/test/page
//    - parsys: /par
Page.current().get().parsys().component(Title.class);

// based on data-path (Touch UI)
Page.current().get().parsys("/data-path").component(Title.class);

// get 1st, last, nTh component from parsys
Page.current().get().parsys().first().component(Title.class) ;
Page.current().get().parsys().last().component(Title.class, 2) ;
Page.current().get().parsys().nth().component(Title.class, 2) ;

// obtaining scoped page objects
Page.current().get().pageobject(Section.class); // default scoping or based on PageObject(locator)

By locator = By.cssLocator(".my-scoped-element");
Page.current().get().scoped(locator).pageobject(Some.class);

WebElement myScope = driver.findElement(locator);
Page.current().get().scoped(myScope).pageobject(Another.class);

To be considered / nice to have

nowszy94 commented 7 years ago

https://github.com/SeleniumHQ/fluent-selenium - worth to consider style used in that library

Shaihuludus commented 5 years ago

As new approach was created during new AEM Authoring this issue is no longer valid