Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add origin information to TemplateDerivedPageContent and Module #446

Closed
leonard84 opened this issue Sep 1, 2016 · 5 comments
Closed

Add origin information to TemplateDerivedPageContent and Module #446

leonard84 opened this issue Sep 1, 2016 · 5 comments
Assignees
Milestone

Comments

@leonard84
Copy link

leonard84 commented Sep 1, 2016

With the usage of groovy.lang.Interceptor to intercept all calls to "value", "click", "sendKeys", "at" on TemplateDerivedPageContent, NonEmptyNavigator, Browser we generate an action log which looks like this:

 [2016-08-31T22:59:43.780] 001 [Browser].at(org.foo.bar.pages.LoginPage)
 [2016-08-31T22:59:44.828] 002 [unknown].value(075921299)
 [2016-08-31T22:59:45.424] 003 [LoginPage.passwordTextfield].value(*****)
 [2016-08-31T22:59:45.992] 004 [LoginPage.loginButton].click()
 [2016-08-31T22:59:47.486] 005 [Browser].at(HomePage)
 [2016-08-31T22:59:48.736] 006 [unknown].value(Hans-Günther)
 [2016-08-31T22:59:49.264] 007 [Sidebar.searchButton].click()
 [2016-08-31T22:59:50.878] 008 [Browser].at(SimpleSearchPage)
 [2016-08-31T22:59:52.036] 009 [unknown].value()

Before the geb 13 release TemplateDerivedPageContent did have more information and we could generate the full structural path, e.g., [HomePage.sidebar.searchbutton].click(). And if you define a Module with $(...).module(..) it wil be reported as unknown, because the information is lost.

usernameTextfield { $('#login-username').module(TextInput) }
passwordTextfield { $('#login-password') }

So the feature request is to add this information to both TemplateDerivedPageContent and Module.
For example add a getParent() and getTemplatePath() to both classes and maybe getFullTemplatePath() as well which would return the full path up to the containing page.

We currently use this function to deduce the display name:

String optimizeName(Object object) {
    if (object instanceof TemplateDerivedPageContent) {
        PageContentTemplate template = (PageContentTemplate) ReflectionTestUtils.getField(object, "_template");
        if (template.getOwner() != null) {
            return optimizeName(template.getOwner()) + "." + template.getName();
        }
        return template.getName();
    } else if (object instanceof Page) {
        return (object).getClass().getSimpleName();
    } else if (object instanceof Module) {
        return (object).getClass().getSimpleName();
    } else if (object instanceof Class) {
        return ((Class)object).getSimpleName();
    } else if (object instanceof RemoteWebElement) {
        return object.toString();
    } else if (object instanceof Browser) {
        return "Browser";
    }

    return "unknown";
}
@erdi
Copy link
Member

erdi commented Jun 13, 2018

Sorry for taking so long @leonard84 but I finally got round to looking into this.

In the 0.13.0 release toString() on TemplateDerivedPageContent has been changed to be more meaningful. Would using it be enough to fulfil your needs?

If you find the current implementation too verbose with the arrows, types and argument values we could always make the conversion from owner, template name and arguments customisable using a strategy object which would be provided via the configuration mechanism.

If you still believe that adding the following methods:

  • List<String> PageContentContainer.getPath() (both Page and Module implement PageContentContainer)
  • List<String> TemplateDerivedPageContent.getPath()

which would return what you're proposing as getFullTemplatePath() and then you building up the string yourself to have full control is the way to go I'm happy to do it but I just wanted to double check with you first.

@erdi
Copy link
Member

erdi commented Jun 25, 2018

FYI, @leonard84, I ended up adding PageContentContainer getRootContainer() and List<String> getContentPath() to PageContentContainer and TemplateDerivedPageContent

@erdi erdi self-assigned this Jun 25, 2018
@erdi erdi added this to the 2.2 milestone Jun 25, 2018
@leonard84
Copy link
Author

Looks good, thanks.

@aptester
Copy link

@leonard84 that action log looks great. I'm trying to built exactly that for our project. Can you share the code/or a blog which talks about how you went about building it? Thanks.

@leonard84
Copy link
Author

@aptester I can try to extract it from our internal code base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants