paypal / SeLion

Enabling Test Automation in Java
http://selion.io
Apache License 2.0
281 stars 233 forks source link

SeLion-Code-Generator generates custom element incorrectly when defined in a Container #306

Closed nirsch closed 8 years ago

nirsch commented 8 years ago

I am experiencing weird behavior when a custom HTML element is defined within a Container of a PageYAML file. The resulting generated code incorrectly generates the getter for that element at the Page level instead of the Container level. The object mapping for the element exists within the Container mapping (as expected). Calling the getter at the Page level (as currently generated) results in a null locator being passed to the custom element, making that element unusable in the current implementation. What configuration is needed for it to generate within the Container?

mach6 commented 8 years ago

@nirsch Yes, that is weird. Will you please share the snippet of your PageYAML that reproduces this issue and the SeLion version you are using? FYI - here is an example source file with container markup - https://github.com/paypal/SeLion/blob/develop/client/src/test/resources/GUIData/paypal/TestPage.yml

@sebady fyi

nirsch commented 8 years ago

I'm experiencing the issue in 1.0.0 and 1.1.0-SNAPSHOT. I start from the archetype and base the information below on version 1.1.0-SNAPSHOT. The custom element (called TestCustom) is designed as documented in the code gen documentation.

The PageYAML:

baseClass: "com.paypal.selion.testcomponents.BasicPageImpl"
pageTitle:
    US: "about:blank"
elements:
    anotherLabel:
        locators:
            US: "//div[1]"
    testContainer:
        locators:
            US: "./html"
        containerElements:
                exampleTestCustom:
                    locators:
                        US: "./input"
                testLabel:
                    locators:
                        US: "./a"

Snippet of SeLion generated code:

private Label anotherLabel;
private TestContainer testContainer;
private TestCustom exampleTestCustom;

public TestCustom getExampleTestCustom() {
    TestCustom element = this.exampleTestCustom;
    if(element == null) {
        this.exampleTestCustom = new TestCustom(getObjectMap().get("exampleTestCustom"), "exampleTestCustom",
                this);
    }
    return this.exampleTestCustom;
}

public class TestContainer extends Container {

        private Label testLabel;

        public Label getTestLabel() {
            Label containerElement = getContainer().testLabel;
            if(containerElement == null) {
                getContainer().testLabel = new Label(this.containerElements.get("testLabel"),
                "testLabel", this);
                }
                return getContainer().testLabel;
            }
}

Test code:

 @Test
 public void myLocatorTest() {
     MyApp app = new MyApp();
     System.out.println(app.getAnotherLabel().getLocator());
     System.out.println(app.getExampleTestCustom().getLocator());

 }

Resulting output:

//div[1]
 null
sebady commented 8 years ago

@nirsch Thanks for the reproducible here. This does appear to be a bug.

mach6 commented 8 years ago

this is fixed with c1ca533