[MGNLTEST-15] Allow to write custom page objects Created: 02/Mar/20  Updated: 14/Sep/20  Resolved: 26/Aug/20

Status: Closed
Project: Magnolia Test Framework
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0.1

Type: Task Priority: Major
Reporter: Maxime Michel Assignee: Rishab Dhar
Resolution: Fixed Votes: 0
Labels: QA&Testing, ui-test-fwk
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
dependency
depends upon MGNLTEST-1 Attempt to extract the integration te... Closed
depends upon MGNLTEST-28 Run selftests on extracted test frame... Closed
is depended upon by MGNLSSO-19 Integration tests with Docker Keycloa... Closed
Template:
Acceptance criteria:
Empty
Task DoR:
Empty
Release notes required:
Yes
Date of First Response:
Epic Link: core-TF-features-bugs-improvements
Sprint: TE 7, TE 8, TE 9
Story Points: 3

 Description   

I want to write IT/UI tests on a Magnolia setup with Keycloak authentication. I would like to describe the Keycloak login page with a Page object, therefore I would need to be able to register a custom a Page object and have the test framework inject the driver inside of it.



 Comments   
Comment by Rishab Dhar [ 26/Aug/20 ]
  • Added documentation for creating Custom Page Objects and exposing them.
  • Added @Library annotation for registering custom page-objects library
  • Added pageObject(Function<PO, Webdriver>) API to provision a custom page object on ad-hoc basis in a test
  • Added self test for Custom page objects
Comment by Mikaël Geljić [ 31/Aug/20 ]

See sample usage: https://git.magnolia-cms.com/projects/ENTERPRISE/repos/magnolia-sso/compare/diff?sourceBranch=refs%2Fheads%2Ftask%2FMGNLSSO-19&targetRepoId=4353#src/test/java/info/magnolia/functionaltests/SsoModuleITTests.java

SsoModuleITTests.java
@Test
public void userWithPublisherGroupDoesntSeeAdministrativeApps(CustomPageObjects expect) {
    ...
    expect.keycloakLoginPage(username, "marketer-password")
            .login();
    expect.findBar()
            .clickAppLauncherButton();

    assertTrue(expect.appLauncher().hasApp("Pages"));
    assertFalse(expect.appLauncher().hasApp("Security"));
}

@Library
public static class CustomPageObjects {
    private WebDriver driver;
    @Delegate
    private PageObjects pageObjects;

    public CustomPageObjects(WebDriver driver) {
        this.driver = driver;
        this.pageObjects = new PageObjects(driver);
    }

    public KeycloakLoginPage keycloakLoginPage(String username, String password) {
        return pageObjects.pageObject(driver -> new KeycloakLoginPage(driver, username, password));
    }
}

@AllArgsConstructor
public static class KeycloakLoginPage implements PageObject {
    ...
}
Generated at Mon Feb 12 07:44:43 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.