galenframework / galen

Layout and functional testing framework for websites
http://galenframework.com
1.41k stars 163 forks source link

Unable to generate spec using SpecGenerator java api #614

Closed winoth4 closed 5 years ago

winoth4 commented 5 years ago

I have created page dump and the json file for the page is generated, when i tried to generate spec file from json i got error below is the snippet i used

        InputStream inputstream = new FileInputStream(dumpPath + "/page.json");

        PageSpecGenerationResult pageSpecGenerationResult = gen.generate(inputstream, specOptions);
        String result = gen.generateSpecSections(pageSpecGenerationResult);

Please let me know what i am missing here.

winoth4 commented 5 years ago

Any updates on the above query??

ishubin commented 5 years ago

Hi! Could you please post the actual error?

winoth4 commented 5 years ago

Hi, Below is the steps i followed, 1) Created sample spec file with objects of login page 2) generated page dump with below snippet Galen.dumpPage(oDriver, "Login", specPath, dumpPath); 3)Once page dump is generated i tried to generate spec for that dump . i got below error msg :java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at com.galenframework.generator.model.GmPageSpec.create(GmPageSpec.java:42) at com.galenframework.generator.SpecGenerator.generateSpecSections(SpecGenerator.java:228)

Also can you please let me know on the clear doc for the java API calls for generate spec

winoth4 commented 5 years ago

page_json.zip

ishubin commented 5 years ago

I have seen this failure before and I released a fix for it. Probably this is something new. I will check it once I get some free time.

ishubin commented 5 years ago

I am trying to reproduce the error but I don't get any exception. Instead I get just an empty spec. But what I find weird is that in your page.json there is no screen element. Usually page dump is generated with screen element in it, which is the largest element. For spec generator it is important that it can build a structure of the page first. It does it by sorting elements by area and it tries to figure out a parent for each element. I guess in your case it was not able to do it. But if I add a large element (e.g. "base": {"area": [0, 0, 2000, 3000]}) - it does work. Here is what it has generated:

@lib galen-extras

= Skeleton =
    | input-3, input-4 are aligned horizontally next to each other with 10px margin

    label-1, label-2:
        height 18px

    label-2:
        above input-2 12px
        below input-1 22px
        width 56px

    label-1:
        above input-1 12px
        below header 32px
        width 44px

    input-3:
        width 62px

    input-4:
        width 68px

    input-1, input-2:
        height 39px

    header:
        height 27px
        inside base >= 38px top

    input-3, input-4:
        below input-2 22px
        height 25px

    signup:
        height 52px
        inside base 38px top
        width 64px

    label-1, input-1, label-2, input-2, input-3, input-4:
        inside base
winoth4 commented 5 years ago

Thanks for you inputs, I tried setting the galen extras as true, now i am able to get the spec file. Not sure what was the issue.

winoth4 commented 5 years ago

Earlier i generated the page dump using old version of Galen, Where screen was missing now i tried to generate page dump with 2.4 version its generating screen object. I think that was the issue